Use generators for tests for MDNodaRepository validation
This commit is contained in:
@@ -442,6 +442,9 @@ enum MDNodaRepository implements MDValueEnumInterface, JsonSerializable {
|
|||||||
if (str_contains($id, '(')) {
|
if (str_contains($id, '(')) {
|
||||||
$id = trim(explode('(', $id)[0]);
|
$id = trim(explode('(', $id)[0]);
|
||||||
}
|
}
|
||||||
|
if (str_contains($id, PHP_EOL)) {
|
||||||
|
$id = trim(explode(PHP_EOL, $id)[0]);
|
||||||
|
}
|
||||||
|
|
||||||
// There is an issue with this regex
|
// There is an issue with this regex
|
||||||
if (preg_match("/^[0-9-X]*$/", $id) === false) {
|
if (preg_match("/^[0-9-X]*$/", $id) === false) {
|
||||||
@@ -630,7 +633,10 @@ enum MDNodaRepository implements MDValueEnumInterface, JsonSerializable {
|
|||||||
private static function validateNpgId(string $id):string|false {
|
private static function validateNpgId(string $id):string|false {
|
||||||
|
|
||||||
if (filter_var($id, FILTER_VALIDATE_URL) !== false) {
|
if (filter_var($id, FILTER_VALIDATE_URL) !== false) {
|
||||||
$id = strtr($id, ['https://www.npg.org.uk/collections/search/person/' => '']);
|
$id = strtr($id, [
|
||||||
|
'http://www.npg.org.uk/collections/search/person/' => '',
|
||||||
|
'https://www.npg.org.uk/collections/search/person/' => '',
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (substr($id, 0, 2) === 'mp' && self::_is_numeric(substr($id, 2))) {
|
if (substr($id, 0, 2) === 'mp' && self::_is_numeric(substr($id, 2))) {
|
||||||
@@ -658,18 +664,21 @@ enum MDNodaRepository implements MDValueEnumInterface, JsonSerializable {
|
|||||||
$id = strtr($id, [
|
$id = strtr($id, [
|
||||||
'http://www.wikidata.org/wiki/' => '',
|
'http://www.wikidata.org/wiki/' => '',
|
||||||
'http://www.wikidata.org/entity/' => '',
|
'http://www.wikidata.org/entity/' => '',
|
||||||
|
'http://www.wikidata.org/w/index.php?search=&search=' => '',
|
||||||
'https://www.wikidata.org/wiki/' => '',
|
'https://www.wikidata.org/wiki/' => '',
|
||||||
'https://www.wikidata.org/entity/' => '',
|
'https://www.wikidata.org/entity/' => '',
|
||||||
'https://www.wikidata.org/w/index.php?search=&search=' => '',
|
'https://www.wikidata.org/w/index.php?search=&search=' => '',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (str_starts_with($id, 'https://www.wikidata.org/w/index.php?title=')) {
|
foreach (['http://www.wikidata.org/w/index.php?title=', 'https://www.wikidata.org/w/index.php?title='] as $urlPrefix) {
|
||||||
$id = str_replace('https://www.wikidata.org/w/index.php?title=', '', $id);
|
if (str_starts_with($id, $urlPrefix)) {
|
||||||
|
$id = str_replace($urlPrefix, '', $id);
|
||||||
if (($endPos = strpos($id, '&')) !== false) {
|
if (($endPos = strpos($id, '&')) !== false) {
|
||||||
$id = substr($id, 0, $endPos);
|
$id = substr($id, 0, $endPos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (substr($id, 0, 1) !== 'Q') {
|
if (substr($id, 0, 1) !== 'Q') {
|
||||||
throw new MDInvalidNodaLinkException("Wikidata IDs must be Q IDs - and start with that letter (provided: $id)");
|
throw new MDInvalidNodaLinkException("Wikidata IDs must be Q IDs - and start with that letter (provided: $id)");
|
||||||
|
|||||||
@@ -6,6 +6,9 @@
|
|||||||
*/
|
*/
|
||||||
declare(strict_types = 1);
|
declare(strict_types = 1);
|
||||||
use PHPUnit\Framework\TestCase;
|
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/MDValueEnumInterface.php';
|
||||||
require_once __DIR__ . '/../src/enums/MDNodaRepository.php';
|
require_once __DIR__ . '/../src/enums/MDNodaRepository.php';
|
||||||
@@ -13,85 +16,353 @@ require_once __DIR__ . '/../src/enums/MDNodaRepository.php';
|
|||||||
/**
|
/**
|
||||||
* Tests for home page.
|
* Tests for home page.
|
||||||
*/
|
*/
|
||||||
|
#[small]
|
||||||
|
#[CoversClass(\MDNodaRepository::class)]
|
||||||
final class MDNodaRepositoryTest extends TestCase {
|
final class MDNodaRepositoryTest extends TestCase {
|
||||||
/**
|
/**
|
||||||
* Tests that valid IDs actually validate as valid.
|
* 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
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testValidIdsValidate():void {
|
#[DataProvider('wikidataIdForValidationProvider')]
|
||||||
|
public function testWikidataIdValidation(string $expected, string $inputString):void {
|
||||||
|
|
||||||
self::assertEquals("Q834961", MDNodaRepository::wikidata->validateId("https://www.wikidata.org/w/index.php?title=Q834961&oldid=2256125706"));
|
self::assertEquals($expected, MDNodaRepository::wikidata->validateId($inputString, ""));
|
||||||
|
|
||||||
self::assertEquals("XX5034943", MDNodaRepository::bne->validateId("http://datos.bne.es/persona/XX5034943"));
|
}
|
||||||
self::assertEquals("XX5034943", MDNodaRepository::bne->validateId("https://datos.bne.es/persona/XX5034943"));
|
|
||||||
self::assertEquals("XX5034943", MDNodaRepository::bne->validateId("XX5034943"));
|
|
||||||
self::assertEquals(false, MDNodaRepository::bne->validateId("XX503494safdsaf;3"));
|
|
||||||
|
|
||||||
// GND (Germany)
|
/**
|
||||||
self::assertEquals("102423008", MDNodaRepository::gnd->validateId("https://d-nb.info/gnd/102423008"));
|
* Data provider for validating BNE IDs.
|
||||||
self::assertEquals("102423008", MDNodaRepository::gnd->validateId("http://d-nb.info/gnd/102423008"));
|
*
|
||||||
self::assertEquals("102423008", MDNodaRepository::gnd->validateId("http://d-nb.info/gnd/ 102423008"));
|
* @return Generator<string, array{0: string|false, 1: string}>
|
||||||
self::assertEquals("1037602218", MDNodaRepository::gnd->validateId("http://d-nb.info/gnd/1037602218"));
|
*/
|
||||||
self::assertEquals("1037602218", MDNodaRepository::gnd->validateId("https://explore.gnd.network/gnd/1037602218"));
|
public static function bneIdForValidationProvider():Generator {
|
||||||
self::assertEquals("102423008", MDNodaRepository::gnd->validateId("102423008"));
|
|
||||||
self::assertEquals("102423008", MDNodaRepository::gnd->validateId("102423008,"));
|
|
||||||
self::assertEquals("4114170-2", MDNodaRepository::gnd->validateId("4114170-2"));
|
|
||||||
self::assertEquals("4114170-2", MDNodaRepository::gnd->validateId("4114170-2 (Fenster (Motiv)"));
|
|
||||||
self::assertEquals(false, MDNodaRepository::gnd->validateId("fkld;s102423008"));
|
|
||||||
|
|
||||||
// NDL (Japan)
|
yield "Full URL, http / XX5034943" => ["XX5034943", "http://datos.bne.es/persona/XX5034943"];
|
||||||
self::assertEquals("00967046", MDNodaRepository::ndl->validateId("https://id.ndl.go.jp/auth/ndlna/00967046"));
|
yield "Full URL, https / XX5034943" => ["XX5034943", "https://datos.bne.es/persona/XX5034943"];
|
||||||
self::assertEquals("00967046", MDNodaRepository::ndl->validateId("http://id.ndl.go.jp/auth/ndlna/00967046"));
|
yield "ID / XX5034943" => ["XX5034943", "XX5034943"];
|
||||||
self::assertEquals("00967046", MDNodaRepository::ndl->validateId("00967046"));
|
yield "Broken input / XX503494safdsaf;3" => [false, "XX503494safdsaf;3"];
|
||||||
self::assertEquals(false, MDNodaRepository::ndl->validateId("http://id.ndl.go.jp/auth/ndlna/0096704;43s6"));
|
|
||||||
|
|
||||||
// NPG: National Portrait Gallery
|
}
|
||||||
self::assertEquals('mp01751', MDNodaRepository::npg->validateId("https://www.npg.org.uk/collections/search/person/mp01751"));
|
|
||||||
self::assertEquals('mp01751', MDNodaRepository::npg->validateId("mp01751"));
|
|
||||||
self::assertEquals(false, MDNodaRepository::npg->validateId("https://www.npg.org.uk/collections/search/person/mp017;51"));
|
|
||||||
|
|
||||||
// Library of Congress
|
/**
|
||||||
self::assertEquals("n2022014604", MDNodaRepository::loc->validateId("https://id.loc.gov/authorities/names/n2022014604"));
|
* Ensure validating references to the BNE works.
|
||||||
self::assertEquals("n2022014604", MDNodaRepository::loc->validateId("http://id.loc.gov/authorities/names/n2022014604"));
|
*
|
||||||
self::assertEquals("n2022014604", MDNodaRepository::loc->validateId("n2022014604"));
|
* @param string|false $expected Expected output.
|
||||||
self::assertEquals(false, MDNodaRepository::loc->validateId("n20220146;04"));
|
* @param string $inputString Input string.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
#[DataProvider('bneIdForValidationProvider')]
|
||||||
|
public function testBneIdValidation(string|false $expected, string $inputString):void {
|
||||||
|
|
||||||
self::assertEquals("sh2022014604", MDNodaRepository::lcsh->validateId("https://id.loc.gov/authorities/names/sh2022014604"));
|
self::assertEquals($expected, MDNodaRepository::bne->validateId($inputString));
|
||||||
self::assertEquals("sh2022014604", MDNodaRepository::lcsh->validateId("http://id.loc.gov/authorities/names/sh2022014604"));
|
|
||||||
self::assertEquals("sh85081569", MDNodaRepository::lcsh->validateId("http://id.loc.gov/authorities/subjects/sh85081569.html"));
|
|
||||||
self::assertEquals("sh2022014604", MDNodaRepository::lcsh->validateId("sh2022014604"));
|
|
||||||
self::assertEquals(false, MDNodaRepository::lcsh->validateId("sh20220146;;04"));
|
|
||||||
|
|
||||||
// PRIM
|
}
|
||||||
self::assertEquals("PIM71684", MDNodaRepository::pim->validateId("https://opac-nevter.pim.hu/en/record/-/record/PIM71684"));
|
|
||||||
self::assertEquals("PIM71684", MDNodaRepository::pim->validateId("https://resolver.pim.hu/auth/PIM71684"));
|
|
||||||
self::assertEquals("PIM71684", MDNodaRepository::pim->validateId("PIM71684"));
|
|
||||||
self::assertEquals(false, MDNodaRepository::pim->validateId("PIM7168;;4"));
|
|
||||||
|
|
||||||
self::assertEquals("248941990", MDNodaRepository::viaf->validateId("https://viaf.org/viaf/248941990"));
|
/**
|
||||||
self::assertEquals("248941990", MDNodaRepository::viaf->validateId("http://viaf.org/viaf/248941990"));
|
* Data provider for validating GND IDs.
|
||||||
self::assertEquals("42893419", MDNodaRepository::viaf->validateId("https://viaf.org/viaf/42893419/"));
|
*
|
||||||
self::assertEquals("86145857811423020454", MDNodaRepository::viaf->validateId("86145857811423020454"));
|
* @return Generator<string, array{0: string|false, 1: string}>
|
||||||
self::assertEquals("2869150688328112660005", MDNodaRepository::viaf->validateId("2869150688328112660005"));
|
*/
|
||||||
self::assertEquals(false, MDNodaRepository::viaf->validateId("2869150688328112;;660005"));
|
public static function gndIdForValidationProvider():Generator {
|
||||||
|
|
||||||
# NDP-IKMK (Places)
|
yield "Full URL, http / 102423008" => ["102423008", "http://d-nb.info/gnd/102423008"];
|
||||||
self::assertEquals("ort/2847", MDNodaRepository::ndp_ikmk->validateId("https://ikmk.smb.museum/ndp/ort/2847"));
|
yield "Full URL, https / 102423008" => ["102423008", "https://d-nb.info/gnd/102423008"];
|
||||||
self::assertEquals("land/123", MDNodaRepository::ndp_ikmk->validateId("https://ikmk.smb.museum/ndp/land/123"));
|
yield "Full URL, http, superfluous spaces / 102423008" => ["102423008", "http://d-nb.info/gnd/ 102423008"];
|
||||||
self::assertEquals("region/123", MDNodaRepository::ndp_ikmk->validateId("https://ikmk.smb.museum/ndp/region/123"));
|
|
||||||
self::assertEquals("land/123", MDNodaRepository::ndp_ikmk->validateId("land/123"));
|
|
||||||
self::assertEquals(false, MDNodaRepository::ndp_ikmk->validateId("123123"));
|
|
||||||
|
|
||||||
# Catalogue of Life
|
yield "Full URL, http / 1037602218" => ["1037602218", "http://d-nb.info/gnd/1037602218"];
|
||||||
self::assertEquals(false, MDNodaRepository::col->validateId("123123"));
|
yield "Full URL, GND Explorer / 1037602218" => ["1037602218", "https://explore.gnd.network/gnd/1037602218"];
|
||||||
self::assertEquals("C46V", MDNodaRepository::col->validateId("https://www.catalogueoflife.org/data/taxon/C46V"));
|
yield "ID / 1037602218" => ["102423008", "102423008"];
|
||||||
self::assertEquals("CRLT8", MDNodaRepository::col->validateId("https://www.catalogueoflife.org/data/taxon/CRLT8"));
|
yield "ID, trailing comma / 102423008" => ["102423008", "102423008,"];
|
||||||
self::assertEquals("CRLT8", MDNodaRepository::col->validateId("http://www.catalogueoflife.org/data/taxon/CRLT8"));
|
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" => [false, "fkld;s102423008"];
|
||||||
|
|
||||||
self::assertEquals(false, MDNodaRepository::mindatorg->validateId("adfdasjfklasjl"));
|
}
|
||||||
self::assertEquals("2047", MDNodaRepository::mindatorg->validateId("https://www.mindat.org/min-2047.html"));
|
|
||||||
self::assertEquals("2047", MDNodaRepository::mindatorg->validateId("http://www.mindat.org/min-2047.html"));
|
/**
|
||||||
|
* 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 "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"];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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"];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user