From f14d7edc6ef767daadf8e35c41f8655816a93122 Mon Sep 17 00:00:00 2001 From: Joshua Ramon Enslin Date: Wed, 18 Oct 2023 22:42:49 +0200 Subject: [PATCH] Add tests to ensure invalid IDs are not validated --- src/enums/MDNodaRepository.php | 5 ++--- tests/MDNodaRepositoryTest.php | 21 ++++++++++++++++----- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/enums/MDNodaRepository.php b/src/enums/MDNodaRepository.php index 9a91043..44cd702 100644 --- a/src/enums/MDNodaRepository.php +++ b/src/enums/MDNodaRepository.php @@ -375,7 +375,6 @@ enum MDNodaRepository implements MDValueEnumInterface, JsonSerializable { return false; } if (self::_is_numeric(strtr($id, ['-' => '', 'X' => ''])) === false) { - throw new Exception($id); return false; } @@ -611,9 +610,9 @@ enum MDNodaRepository implements MDValueEnumInterface, JsonSerializable { 'https://vocab.getty.edu/page/aat/', ]), self::ackerbau => self::validateNumericId($id, ['https://term.museum-digital.de/ackerbau/tag/']), - self::bne => self::validateBneId($id, ['http://datos.bne.es/persona/']), + self::bne => self::validateBneId($id, ['http://datos.bne.es/persona/', 'https://datos.bne.es/persona/']), self::bnf => self::validateBnfId($id), - self::cona => self::validateNumericId($id, ['https://vocab.getty.edu/page/cona/']), + self::cona => self::validateNumericId($id, ['http://vocab.getty.edu/page/cona/', 'https://vocab.getty.edu/page/cona/']), self::editionhumboldtdigital => self::validateGndId($id, ['https://edition-humboldt.de/register/personen/detail.xql?normid=http://d-nb.info/gnd/']), self::gnd => self::validateGndId($id, ['http://d-nb.info/gnd/', 'https://d-nb.info/gnd/']), self::grobsystematik => self::validateNumericId($id, ['https://term.museum-digital.de/grobsystematik/tag/']), diff --git a/tests/MDNodaRepositoryTest.php b/tests/MDNodaRepositoryTest.php index 48c5727..b06932f 100644 --- a/tests/MDNodaRepositoryTest.php +++ b/tests/MDNodaRepositoryTest.php @@ -22,7 +22,9 @@ final class MDNodaRepositoryTest extends TestCase { public function testValidIdsValidate():void { 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")); @@ -30,33 +32,42 @@ final class MDNodaRepositoryTest extends TestCase { self::assertEquals("102423008", MDNodaRepository::gnd->validateId("http://d-nb.info/gnd/ 102423008")); self::assertEquals("1037602218", MDNodaRepository::gnd->validateId("http://d-nb.info/gnd/1037602218")); self::assertEquals("102423008", MDNodaRepository::gnd->validateId("102423008")); + self::assertEquals(false, MDNodaRepository::gnd->validateId("fkld;s102423008")); // NDL (Japan) - self::assertEquals("00967046", MDNodaRepository::ndl->validateId("00967046")); self::assertEquals("00967046", MDNodaRepository::ndl->validateId("https://id.ndl.go.jp/auth/ndlna/00967046")); self::assertEquals("00967046", MDNodaRepository::ndl->validateId("http://id.ndl.go.jp/auth/ndlna/00967046")); + self::assertEquals("00967046", MDNodaRepository::ndl->validateId("00967046")); + 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")); self::assertEquals("n2022014604", MDNodaRepository::loc->validateId("http://id.loc.gov/authorities/names/n2022014604")); self::assertEquals("n2022014604", MDNodaRepository::loc->validateId("n2022014604")); + self::assertEquals(false, MDNodaRepository::loc->validateId("n20220146;04")); self::assertEquals("sh2022014604", MDNodaRepository::lcsh->validateId("https://id.loc.gov/authorities/names/sh2022014604")); self::assertEquals("sh2022014604", MDNodaRepository::lcsh->validateId("http://id.loc.gov/authorities/names/sh2022014604")); - self::assertEquals("sh2022014604", MDNodaRepository::lcsh->validateId("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")); - self::assertEquals("PIM71684", MDNodaRepository::pim->validateId("PIM71684")); + // 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("86145857811423020454", MDNodaRepository::viaf->validateId("86145857811423020454")); - self::assertEquals("2869150688328112660005", MDNodaRepository::viaf->validateId("2869150688328112660005")); self::assertEquals("248941990", MDNodaRepository::viaf->validateId("https://viaf.org/viaf/248941990")); self::assertEquals("248941990", MDNodaRepository::viaf->validateId("http://viaf.org/viaf/248941990")); + self::assertEquals("86145857811423020454", MDNodaRepository::viaf->validateId("86145857811423020454")); + self::assertEquals("2869150688328112660005", MDNodaRepository::viaf->validateId("2869150688328112660005")); + self::assertEquals(false, MDNodaRepository::viaf->validateId("2869150688328112;;660005")); } }