Improve test coverage in MDNodaRepository
This commit is contained in:
@@ -96,7 +96,8 @@ final class MDNodaRepositoryTest extends TestCase {
|
||||
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" => [false, "fkld;s102423008"];
|
||||
yield "Broken ID; fkld;s102423008" => [false, "fkld;s102423008"];
|
||||
yield "Broken ID; s102423008-x" => [false, "s102423008-x"];
|
||||
|
||||
}
|
||||
|
||||
@@ -139,6 +140,7 @@ final class MDNodaRepositoryTest extends TestCase {
|
||||
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"];
|
||||
|
||||
}
|
||||
@@ -228,6 +230,7 @@ final class MDNodaRepositoryTest extends TestCase {
|
||||
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"];
|
||||
|
||||
}
|
||||
|
||||
@@ -291,6 +294,8 @@ final class MDNodaRepositoryTest extends TestCase {
|
||||
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"];
|
||||
|
||||
}
|
||||
|
||||
@@ -365,4 +370,83 @@ final class MDNodaRepositoryTest extends TestCase {
|
||||
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"', json_encode($entry));
|
||||
|
||||
self::assertNotEmpty(MDNodaRepository::caseNames());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user