Compare commits

..

No commits in common. "0e863619682a73625290a1092db4f218a24fe2d9" and "8090b95f494c184ceea4396bf0e5ec0c90c1054f" have entirely different histories.

3 changed files with 7 additions and 69 deletions

View File

@ -26,7 +26,7 @@ final class MDNodaLink {
$this->source = $source; $this->source = $source;
if (($validatedId = $this->source->validateId(trim($id))) === false) { if (($validatedId = $this->source->validateId(trim($id))) === false) {
throw new MDInvalidNodaLink("Invalid noda ID / link: \"" . $id . "\" [Repository: " . $this->source->toDbName() . "]"); throw new MDInvalidNodaLink("Invalid noda ID / link: " . $id . " [Repository: " . $this->source->toDbName() . "]");
} }
$this->id = $validatedId; $this->id = $validatedId;

View File

@ -251,16 +251,11 @@ enum MDNodaRepository implements MDValueEnumInterface, JsonSerializable {
if (filter_var($id, FILTER_VALIDATE_URL) !== false) { if (filter_var($id, FILTER_VALIDATE_URL) !== false) {
$toRemove = []; $toRemove = [];
foreach ($prefixes as $prefix) { foreach ($prefixes as $prefix) $toRemove[$prefix] = "";
$toRemove[$prefix] = "";
}
$id = strtr($id, $toRemove); $id = strtr($id, $toRemove);
} }
// Strings starting with 0 are quite often linked, notably with the NDL. if (filter_var($id, FILTER_VALIDATE_INT) === false) {
// PHP's FILTER_VALIDATE_INT does not accept a leading 0 however, so it
// is stripped before checking.
if (filter_var(ltrim($id, '0'), FILTER_VALIDATE_INT) === false) {
return false; return false;
} }
@ -325,10 +320,7 @@ enum MDNodaRepository implements MDValueEnumInterface, JsonSerializable {
private static function validateLocId(string $id):string|false { private static function validateLocId(string $id):string|false {
if (filter_var($id, FILTER_VALIDATE_URL) !== false) { if (filter_var($id, FILTER_VALIDATE_URL) !== false) {
$id = strtr($id, [ $id = strtr($id, ['http://id.loc.gov/authorities/names/' => '']);
'http://id.loc.gov/authorities/names/' => '',
'https://id.loc.gov/authorities/names/' => '',
]);
} }
if (substr($id, 0, 1) !== 'n') { if (substr($id, 0, 1) !== 'n') {
@ -407,7 +399,7 @@ enum MDNodaRepository implements MDValueEnumInterface, JsonSerializable {
self::aat => self::validateNumericId($id, ['https://vocab.getty.edu/page/aat/']), self::aat => self::validateNumericId($id, ['https://vocab.getty.edu/page/aat/']),
self::ackerbau => self::validateNumericId($id, ['https://term.museum-digital.de/ackerbau/tag/']), self::ackerbau => self::validateNumericId($id, ['https://term.museum-digital.de/ackerbau/tag/']),
self::bne => self::validateNumericId($id, ['http://datos.bne.es/persona/']), self::bne => self::validateNumericId($id, ['http://datos.bne.es/persona/']),
self::bnf => self::validateNumericId(rtrim($id, 't'), ["https://catalogue.bnf.fr/ark:/12148/cb"]), // cb11960399t is a valid entry, too (general) self::bnf => self::validateNumericId($id, ["https://catalogue.bnf.fr/ark:/12148/cb"]),
self::cona => self::validateNumericId($id, ['https://vocab.getty.edu/page/cona/']), self::cona => self::validateNumericId($id, ['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::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::gnd => self::validateGndId($id, ['http://d-nb.info/gnd/', 'https://d-nb.info/gnd/']),
@ -419,17 +411,11 @@ enum MDNodaRepository implements MDValueEnumInterface, JsonSerializable {
self::mindatorg => self::validateNumericId($id, ['https://www.mindat.org/min-', '.html']), self::mindatorg => self::validateNumericId($id, ['https://www.mindat.org/min-', '.html']),
self::moebeltypologie => self::validateNumericId($id, ['https://term.museum-digital.de/moebel/tag/']), self::moebeltypologie => self::validateNumericId($id, ['https://term.museum-digital.de/moebel/tag/']),
self::ndb_adb => self::validateGndId($id, ['https://www.deutsche-biographie.de/pnd', '.html']), self::ndb_adb => self::validateGndId($id, ['https://www.deutsche-biographie.de/pnd', '.html']),
self::ndl => self::validateNumericId($id, [ self::ndl => self::validateNumericId($id, ['https://id.ndl.go.jp/auth/ndlna/']),
'http://id.ndl.go.jp/auth/ndlna/',
'https://id.ndl.go.jp/auth/ndlna/',
]),
self::ndp_ikmk => self::validateNumericId($id, ['https://ikmk.smb.museum/ndp/land/']), self::ndp_ikmk => self::validateNumericId($id, ['https://ikmk.smb.museum/ndp/land/']),
self::ndp_ikmk_persons => self::validateNumericId($id, ['https://ikmk.smb.museum/ndp/person/']), self::ndp_ikmk_persons => self::validateNumericId($id, ['https://ikmk.smb.museum/ndp/person/']),
self::nomisma => str_replace('http://nomisma.org/id/', '', $id), self::nomisma => str_replace('http://nomisma.org/id/', '', $id),
self::npg => self::validateNumericId($id, [ self::npg => self::validateNumericId($id, ['https://www.npg.org.uk/collections/search/person/']),
'https://www.npg.org.uk/collections/search/person/',
'https://www.npg.org.uk/collections/search/person/mp',
]),
self::oberbegriffsdatei => self::validateNumericId($id, ['https://term.museum-digital.de/oberbegriffsdatei/tag/']), self::oberbegriffsdatei => self::validateNumericId($id, ['https://term.museum-digital.de/oberbegriffsdatei/tag/']),
self::orcid => preg_match('/^[0-9]{4}-[0-9]{4}-[0-9]{4}-[0-9]{4}$/', $id) ? $id : false, self::orcid => preg_match('/^[0-9]{4}-[0-9]{4}-[0-9]{4}-[0-9]{4}$/', $id) ? $id : false,
self::osm => self::validateNumericId($id, ['https://www.openstreetmap.org/relation/']), self::osm => self::validateNumericId($id, ['https://www.openstreetmap.org/relation/']),

View File

@ -1,48 +0,0 @@
<?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;
require_once __DIR__ . '/../src/enums/MDValueEnumInterface.php';
require_once __DIR__ . '/../src/enums/MDNodaRepository.php';
/**
* Tests for home page.
*/
final class MDNodaRepositoryTest extends TestCase {
/**
* Tests that valid IDs actually validate as valid.
*
* @return void
*/
public function testValidIdsValidate():void {
// GND (Germany)
self::assertNotFalse(MDNodaRepository::gnd->validateId("https://d-nb.info/gnd/102423008"));
self::assertNotFalse(MDNodaRepository::gnd->validateId("http://d-nb.info/gnd/102423008"));
self::assertNotFalse(MDNodaRepository::gnd->validateId("102423008"));
// NDL (Japan)
self::assertNotFalse(MDNodaRepository::ndl->validateId("00967046"));
self::assertNotFalse(MDNodaRepository::ndl->validateId("https://id.ndl.go.jp/auth/ndlna/00967046"));
self::assertNotFalse(MDNodaRepository::ndl->validateId("http://id.ndl.go.jp/auth/ndlna/00967046"));
// NPG: National Portrait Gallery
self::assertNotFalse(MDNodaRepository::npg->validateId("https://www.npg.org.uk/collections/search/person/mp01751"));
// Library of Congress
self::assertNotFalse(MDNodaRepository::loc->validateId("https://id.loc.gov/authorities/names/n2022014604"));
self::assertNotFalse(MDNodaRepository::loc->validateId("http://id.loc.gov/authorities/names/n2022014604"));
self::assertNotFalse(MDNodaRepository::loc->validateId("n2022014604"));
self::assertNotFalse(MDNodaRepository::loc->validateId("https://id.loc.gov/authorities/names/n2022014604"));
self::assertNotFalse(MDNodaRepository::loc->validateId("http://id.loc.gov/authorities/names/n2022014604"));
self::assertNotFalse(MDNodaRepository::loc->validateId("n2022014604"));
}
}