453 lines
17 KiB
PHP
453 lines
17 KiB
PHP
<?PHP
|
|
/**
|
|
* This script contains tests for the home page.
|
|
*
|
|
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
|
|
*/
|
|
declare(strict_types = 1);
|
|
use PHPUnit\Framework\TestCase;
|
|
use PHPUnit\Framework\Attributes\Small;
|
|
use PHPUnit\Framework\Attributes\CoversClass;
|
|
use PHPUnit\Framework\Attributes\DataProvider;
|
|
|
|
require_once __DIR__ . '/../src/enums/MDValueEnumInterface.php';
|
|
require_once __DIR__ . '/../src/enums/MDNodaRepository.php';
|
|
|
|
/**
|
|
* Tests for home page.
|
|
*/
|
|
#[small]
|
|
#[CoversClass(\MDNodaRepository::class)]
|
|
final class MDNodaRepositoryTest extends TestCase {
|
|
/**
|
|
* Data provider for validating Wikidata IDs.
|
|
*
|
|
* @return Generator<string, array{0: string, 1: string}>
|
|
*/
|
|
public static function wikidataIdForValidationProvider():Generator {
|
|
|
|
yield "Full URL, http / Q834961" => ["Q834961", "http://www.wikidata.org/w/index.php?title=Q834961&oldid=2256125706"];
|
|
yield "Full URL, https / Q834961" => ["Q834961", "https://www.wikidata.org/w/index.php?title=Q834961&oldid=2256125706"];
|
|
yield "Q-ID / Q834961" => ["Q834961", "Q834961"];
|
|
yield "Q-ID / Q834961 (trailing space)" => ["Q834961", "Q834961 "];
|
|
|
|
}
|
|
|
|
/**
|
|
* Ensure validating references to Wikidata works.
|
|
*
|
|
* @param string $expected Expected output.
|
|
* @param string $inputString Input string.
|
|
*
|
|
* @return void
|
|
*/
|
|
#[DataProvider('wikidataIdForValidationProvider')]
|
|
public function testWikidataIdValidation(string $expected, string $inputString):void {
|
|
|
|
self::assertEquals($expected, MDNodaRepository::wikidata->validateId($inputString));
|
|
|
|
}
|
|
|
|
/**
|
|
* Data provider for validating BNE IDs.
|
|
*
|
|
* @return Generator<string, array{0: string|false, 1: string}>
|
|
*/
|
|
public static function bneIdForValidationProvider():Generator {
|
|
|
|
yield "Full URL, http / XX5034943" => ["XX5034943", "http://datos.bne.es/persona/XX5034943"];
|
|
yield "Full URL, https / XX5034943" => ["XX5034943", "https://datos.bne.es/persona/XX5034943"];
|
|
yield "ID / XX5034943" => ["XX5034943", "XX5034943"];
|
|
yield "Broken input / XX503494safdsaf;3" => [false, "XX503494safdsaf;3"];
|
|
|
|
}
|
|
|
|
/**
|
|
* Ensure validating references to the BNE works.
|
|
*
|
|
* @param string|false $expected Expected output.
|
|
* @param string $inputString Input string.
|
|
*
|
|
* @return void
|
|
*/
|
|
#[DataProvider('bneIdForValidationProvider')]
|
|
public function testBneIdValidation(string|false $expected, string $inputString):void {
|
|
|
|
self::assertEquals($expected, MDNodaRepository::bne->validateId($inputString));
|
|
|
|
}
|
|
|
|
/**
|
|
* Data provider for validating GND IDs.
|
|
*
|
|
* @return Generator<string, array{0: string|false, 1: string}>
|
|
*/
|
|
public static function gndIdForValidationProvider():Generator {
|
|
|
|
yield "Full URL, http / 102423008" => ["102423008", "http://d-nb.info/gnd/102423008"];
|
|
yield "Full URL, https / 102423008" => ["102423008", "https://d-nb.info/gnd/102423008"];
|
|
yield "Full URL, http, superfluous spaces / 102423008" => ["102423008", "http://d-nb.info/gnd/ 102423008"];
|
|
|
|
yield "Full URL, http / 1037602218" => ["1037602218", "http://d-nb.info/gnd/1037602218"];
|
|
yield "Full URL, GND Explorer / 1037602218" => ["1037602218", "https://explore.gnd.network/gnd/1037602218"];
|
|
yield "ID / 1037602218" => ["102423008", "102423008"];
|
|
yield "ID, trailing comma / 102423008" => ["102423008", "102423008,"];
|
|
yield "4114170-2" => ["4114170-2", "4114170-2"];
|
|
yield "4114170-2, trailing content in brackets" => ["4114170-2", "4114170-2 (Fenster (Motiv)"];
|
|
yield "4114170-2, trailing content in brackets, with newline" => ["4114170-2", "4114170-2" . PHP_EOL . " (Fenster (Motiv)"];
|
|
yield "4113617-2, with newline" => ["4113617-2", "4113617-2" . PHP_EOL . "Zauberin (Motiv)"];
|
|
yield "Broken ID; fkld;s102423008" => [false, "fkld;s102423008"];
|
|
yield "Broken ID; s102423008-x" => [false, "s102423008-x"];
|
|
|
|
}
|
|
|
|
/**
|
|
* Ensure validating references to the GND / Gemeinsame Normdatei works.
|
|
*
|
|
* @param string|false $expected Expected output.
|
|
* @param string $inputString Input string.
|
|
*
|
|
* @return void
|
|
*/
|
|
#[DataProvider('gndIdForValidationProvider')]
|
|
public function testGndIdValidation(string|false $expected, string $inputString):void {
|
|
|
|
self::assertEquals($expected, MDNodaRepository::gnd->validateId($inputString));
|
|
|
|
}
|
|
|
|
/**
|
|
* Data provider for validating NDL IDs.
|
|
*
|
|
* @return Generator<string, array{0: string|false, 1: string}>
|
|
*/
|
|
public static function ndlIdForValidationProvider():Generator {
|
|
|
|
yield "Full URL, http / 00967046" => ["00967046", "http://id.ndl.go.jp/auth/ndlna/00967046"];
|
|
yield "Full URL, https / 00967046" => ["00967046", "https://id.ndl.go.jp/auth/ndlna/00967046"];
|
|
yield "ID / 00967046" => ["00967046", "00967046"];
|
|
yield "Broken input / XX503494safdsaf;3" => [false, "http://id.ndl.go.jp/auth/ndlna/0096704;43s6"];
|
|
|
|
}
|
|
|
|
/**
|
|
* Data provider for validating NPG IDs (National Portrait Gallery).
|
|
*
|
|
* @return Generator<string, array{0: string|false, 1: string}>
|
|
*/
|
|
public static function npgIdForValidationProvider():Generator {
|
|
|
|
yield "Full URL, http / mp01751" => ["mp01751", "http://www.npg.org.uk/collections/search/person/mp01751"];
|
|
yield "Full URL, https / mp01751" => ["mp01751", "https://www.npg.org.uk/collections/search/person/mp01751"];
|
|
yield "ID / mp01751" => ["mp01751", "mp01751"];
|
|
yield "incomplete ID without prefix / 01751 > mp01751" => ["mp01751", "01751"];
|
|
yield "Broken input / https://www.npg.org.uk/collections/search/person/mp017;51" => [false, "https://www.npg.org.uk/collections/search/person/mp017;51"];
|
|
|
|
}
|
|
|
|
/**
|
|
* Ensure validating NPG entries works (National Portrait Gallery).
|
|
*
|
|
* @param string|false $expected Expected output.
|
|
* @param string $inputString Input string.
|
|
*
|
|
* @return void
|
|
*/
|
|
#[DataProvider('npgIdForValidationProvider')]
|
|
public function testNpgIdValidation(string|false $expected, string $inputString):void {
|
|
|
|
self::assertEquals($expected, MDNodaRepository::npg->validateId($inputString));
|
|
|
|
}
|
|
|
|
/**
|
|
* Data provider for validating references to the Library of Congress works.
|
|
*
|
|
* @return Generator<string, array{0: string|false, 1: string}>
|
|
*/
|
|
public static function locIdForValidationProvider():Generator {
|
|
|
|
yield "Full URL, http / n2022014604" => ["n2022014604", "http://id.loc.gov/authorities/names/n2022014604"];
|
|
yield "Full URL, https / n2022014604" => ["n2022014604", "https://id.loc.gov/authorities/names/n2022014604"];
|
|
yield "ID / n2022014604" => ["n2022014604", "n2022014604"];
|
|
yield "Broken input / n20220146;04" => [false, "n20220146;04"];
|
|
|
|
}
|
|
|
|
/**
|
|
* Ensure validating LOC entries works (Library of Congress).
|
|
*
|
|
* @param string|false $expected Expected output.
|
|
* @param string $inputString Input string.
|
|
*
|
|
* @return void
|
|
*/
|
|
#[DataProvider('locIdForValidationProvider')]
|
|
public function testLocIdValidation(string|false $expected, string $inputString):void {
|
|
|
|
self::assertEquals($expected, MDNodaRepository::loc->validateId($inputString));
|
|
|
|
}
|
|
|
|
/**
|
|
* Data provider for validating references to the Library of Congress Subject Headings works.
|
|
*
|
|
* @return Generator<string, array{0: string|false, 1: string}>
|
|
*/
|
|
public static function lcshIdForValidationProvider():Generator {
|
|
|
|
yield "Full URL, http / names/sh2022014604" => ["sh2022014604", "http://id.loc.gov/authorities/names/sh2022014604"];
|
|
yield "Full URL, https / names/sh2022014604" => ["sh2022014604", "https://id.loc.gov/authorities/names/sh2022014604"];
|
|
yield "Full URL, http / subjects/sh85081569.html" => ["sh85081569", "http://id.loc.gov/authorities/subjects/sh85081569.html"];
|
|
yield "ID / sh85081569" => ["sh85081569", "sh85081569"];
|
|
yield "Broken input / sh20220146;;04" => [false, "sh20220146;;04"];
|
|
|
|
}
|
|
|
|
/**
|
|
* Ensure validating LCSH entries works (Library of Congress Subject Headings).
|
|
*
|
|
* @param string|false $expected Expected output.
|
|
* @param string $inputString Input string.
|
|
*
|
|
* @return void
|
|
*/
|
|
#[DataProvider('lcshIdForValidationProvider')]
|
|
public function testLcshIdValidation(string|false $expected, string $inputString):void {
|
|
|
|
self::assertEquals($expected, MDNodaRepository::lcsh->validateId($inputString));
|
|
|
|
}
|
|
|
|
/**
|
|
* Data provider for validating references to the PIM / Petőfi Irodalmi Múzeum.
|
|
*
|
|
* @return Generator<string, array{0: string|false, 1: string}>
|
|
*/
|
|
public static function pimIdForValidationProvider():Generator {
|
|
|
|
yield "Full URL, https / opac > en/record/-/record/PIM71684" => ["PIM71684", "https://opac-nevter.pim.hu/en/record/-/record/PIM71684"];
|
|
yield "Full URL, https / record > auth/PIM71684" => ["PIM71684", "https://resolver.pim.hu/auth/PIM71684"];
|
|
yield "ID / PIM71684" => ["PIM71684", "PIM71684"];
|
|
yield "Broken input / PIM7168;;4" => [false, "PIM7168;;4"];
|
|
yield "Broken input / 7168a" => [false, "7168a"];
|
|
|
|
}
|
|
|
|
/**
|
|
* Ensure validating PIM / Petőfi Irodalmi Múzeum entries works.
|
|
*
|
|
* @param string|false $expected Expected output.
|
|
* @param string $inputString Input string.
|
|
*
|
|
* @return void
|
|
*/
|
|
#[DataProvider('pimIdForValidationProvider')]
|
|
public function testPimIdValidation(string|false $expected, string $inputString):void {
|
|
|
|
self::assertEquals($expected, MDNodaRepository::pim->validateId($inputString));
|
|
|
|
}
|
|
|
|
/**
|
|
* Data provider for validating references to the VIAF.
|
|
*
|
|
* @return Generator<string, array{0: string|false, 1: string}>
|
|
*/
|
|
public static function viafIdForValidationProvider():Generator {
|
|
|
|
yield "Full URL, http / 248941990" => ["248941990", "http://viaf.org/viaf/248941990"];
|
|
yield "Full URL, https / 248941990" => ["248941990", "https://viaf.org/viaf/248941990"];
|
|
yield "Full URL, https / 42893419" => ["42893419", "https://viaf.org/viaf/42893419"];
|
|
yield "Full URL, https / 86145857811423020454" => ["86145857811423020454", "https://viaf.org/viaf/86145857811423020454"];
|
|
yield "ID / 86145857811423020454" => ["86145857811423020454", "86145857811423020454"];
|
|
yield "Full URL, https / 2869150688328112660005" => ["2869150688328112660005", "https://viaf.org/viaf/2869150688328112660005"];
|
|
yield "ID / 2869150688328112660005" => ["2869150688328112660005", "2869150688328112660005"];
|
|
yield "Broken input / 2869150688328112;;660005" => [false, "2869150688328112;;660005"];
|
|
|
|
}
|
|
|
|
/**
|
|
* Ensure validating VIAF works.
|
|
*
|
|
* @param string|false $expected Expected output.
|
|
* @param string $inputString Input string.
|
|
*
|
|
* @return void
|
|
*/
|
|
#[DataProvider('viafIdForValidationProvider')]
|
|
public function testViafIdValidation(string|false $expected, string $inputString):void {
|
|
|
|
self::assertEquals($expected, MDNodaRepository::viaf->validateId($inputString));
|
|
|
|
}
|
|
|
|
/**
|
|
* Data provider for validating references to the NDP-IKMK.
|
|
*
|
|
* @return Generator<string, array{0: string|false, 1: string}>
|
|
*/
|
|
public static function ndpIkmkIdForValidationProvider():Generator {
|
|
|
|
yield "ort/2847 ; url" => ["ort/2847", "https://ikmk.smb.museum/ndp/ort/2847"];
|
|
yield "land/123 ; url" => ["land/123", "https://ikmk.smb.museum/ndp/land/123"];
|
|
yield "region/123 ; url" => ["region/123", "https://ikmk.smb.museum/ndp/region/123"];
|
|
yield "land/123 ; ID" => ["land/123", "land/123"];
|
|
yield "Broken input / 123123" => [false, "123123"];
|
|
yield "Broken input / a/123123" => [false, "a/123123"];
|
|
yield "Broken input / land/123123-a" => [false, "land/123123-a"];
|
|
|
|
}
|
|
|
|
/**
|
|
* Ensure validating NDP/IKMK works.
|
|
*
|
|
* @param string|false $expected Expected output.
|
|
* @param string $inputString Input string.
|
|
*
|
|
* @return void
|
|
*/
|
|
#[DataProvider('ndpIkmkIdForValidationProvider')]
|
|
public function testNdpIkmkIdValidation(string|false $expected, string $inputString):void {
|
|
|
|
self::assertEquals($expected, MDNodaRepository::ndp_ikmk->validateId($inputString));
|
|
|
|
}
|
|
|
|
/**
|
|
* Data provider for validating references to the Catalogue of Life.
|
|
*
|
|
* @return Generator<string, array{0: string|false, 1: string}>
|
|
*/
|
|
public static function colIdForValidationProvider():Generator {
|
|
|
|
yield "C46V ; url" => ["C46V", "https://www.catalogueoflife.org/data/taxon/C46V"];
|
|
yield "CRLT8 ; url" => ["CRLT8", "https://www.catalogueoflife.org/data/taxon/CRLT8"];
|
|
yield "CRLT8 ; url, http" => ["CRLT8", "http://www.catalogueoflife.org/data/taxon/CRLT8"];
|
|
yield "Broken input / 123123" => [false, "123123"];
|
|
|
|
}
|
|
|
|
/**
|
|
* Ensure validating Catalogue of Life works.
|
|
*
|
|
* @param string|false $expected Expected output.
|
|
* @param string $inputString Input string.
|
|
*
|
|
* @return void
|
|
*/
|
|
#[DataProvider('colIdForValidationProvider')]
|
|
public function testColIdValidation(string|false $expected, string $inputString):void {
|
|
|
|
self::assertEquals($expected, MDNodaRepository::col->validateId($inputString));
|
|
|
|
}
|
|
|
|
/**
|
|
* Data provider for validating references to the Mindat.
|
|
*
|
|
* @return Generator<string, array{0: string|false, 1: string}>
|
|
*/
|
|
public static function mindatIdForValidationProvider():Generator {
|
|
|
|
yield "2047 ; url, http" => ["2047", "http://www.mindat.org/min-2047.html"];
|
|
yield "2047 ; url, https" => ["2047", "https://www.mindat.org/min-2047.html"];
|
|
yield "Broken input / adfdasjfklasjl" => [false, "adfdasjfklasjl"];
|
|
|
|
}
|
|
|
|
/**
|
|
* Ensure validating Mindat references.
|
|
*
|
|
* @param string|false $expected Expected output.
|
|
* @param string $inputString Input string.
|
|
*
|
|
* @return void
|
|
*/
|
|
#[DataProvider('mindatIdForValidationProvider')]
|
|
public function testMindatIdValidation(string|false $expected, string $inputString):void {
|
|
|
|
self::assertEquals($expected, MDNodaRepository::mindatorg->validateId($inputString));
|
|
|
|
}
|
|
|
|
/**
|
|
* Data provider for validating references to orcid.
|
|
*
|
|
* @return Generator<string, array{0: string|false, 1: string}>
|
|
*/
|
|
public static function orcidIdForValidationProvider():Generator {
|
|
|
|
yield "0000-0000-0000-0000 ; url, http" => ["0000-0000-0000-0000", "http://orcid.org/0000-0000-0000-0000"];
|
|
yield "0000-0000-0000-0000 ; url, https" => ["0000-0000-0000-0000", "https://orcid.org/0000-0000-0000-0000"];
|
|
yield "0000-0000-0000-0000 ; ID" => ["0000-0000-0000-0000", "0000-0000-0000-0000"];
|
|
yield "Broken input / adfdasjfklasjl" => [false, "adfdasjfklasjl"];
|
|
|
|
}
|
|
|
|
/**
|
|
* Ensure validating orcid references.
|
|
*
|
|
* @param string|false $expected Expected output.
|
|
* @param string $inputString Input string.
|
|
*
|
|
* @return void
|
|
*/
|
|
#[DataProvider('orcidIdForValidationProvider')]
|
|
public function testOrcidIdValidation(string|false $expected, string $inputString):void {
|
|
|
|
self::assertEquals($expected, MDNodaRepository::orcid->validateId($inputString));
|
|
|
|
}
|
|
|
|
/**
|
|
* Data provider for validating references to iconclass.
|
|
*
|
|
* @return Generator<string, array{0: string|false, 1: string}>
|
|
*/
|
|
public static function iconclassIdForValidationProvider():Generator {
|
|
|
|
yield "45C221 ; url, http" => ["45C221", "http://iconclass.org/rkd/45C221"];
|
|
yield "45C221 ; url, https" => ["45C221", "http://iconclass.org/rkd//45C221"];
|
|
yield "45C221 ; ID" => ["45C221", "45C221"];
|
|
yield "Broken input / adfdasjfklasäj%l" => [false, "adfdasjfklasäj%l"];
|
|
|
|
}
|
|
|
|
/**
|
|
* Ensure validating iconclass references.
|
|
*
|
|
* @param string|false $expected Expected output.
|
|
* @param string $inputString Input string.
|
|
*
|
|
* @return void
|
|
*/
|
|
#[DataProvider('iconclassIdForValidationProvider')]
|
|
public function testIconclassIdValidation(string|false $expected, string $inputString):void {
|
|
|
|
self::assertEquals($expected, MDNodaRepository::iconclass->validateId($inputString));
|
|
|
|
}
|
|
|
|
/**
|
|
* Tests conversion of already validated and set up entries to strings.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function testConversionWorks():void {
|
|
|
|
$entry = MDNodaRepository::fromUrl("http://www.wikidata.org/w/index.php?title=Q834961&oldid=2256125706");
|
|
|
|
self::assertEquals("wikidata", $entry->toDbName());
|
|
self::assertEquals("Wikidata", $entry->toFullName());
|
|
self::assertEquals("https://www.wikidata.org/entity/", $entry->getUrlPrefix());
|
|
self::assertEquals("https://www.wikidata.org/entity/a", $entry->getEntityLink("a"));
|
|
self::assertEquals("https://www.wikidata.org/w/index.php?search=&search=a&ns0=1&ns120=1", $entry->getSearchLink("a"));
|
|
|
|
self::assertEquals('"wikidata"', MD_STD::json_encode_object($entry));
|
|
|
|
self::assertNotEmpty(MDNodaRepository::caseNames());
|
|
|
|
}
|
|
}
|