Improve test coverage in MDNodaRepository

This commit is contained in:
2026-01-29 17:55:06 +01:00
parent fde98debcb
commit a368e1851a
2 changed files with 100 additions and 7 deletions

View File

@@ -117,8 +117,9 @@ enum MDNodaRepository implements MDValueEnumInterface, JsonSerializable {
}
/**
* Attempts to get a repository based on a provided link. This function is rather expensive
* and should be avoided as much as possible.
* Attempts to get a repository based on a provided link.
* This function is rather expensive and should be avoided
* as much as possible.
*
* @param string $input Input to get a value from.
*
@@ -130,7 +131,12 @@ enum MDNodaRepository implements MDValueEnumInterface, JsonSerializable {
foreach ($cases as $case) {
if ($case === self::allgemein) continue;
$output = $case->validateId($input);
try {
$output = $case->validateId($input);
}
catch (MDInvalidNodaLinkException $e) {
continue;
}
if ($output !== false) return $case;
}
@@ -396,8 +402,11 @@ enum MDNodaRepository implements MDValueEnumInterface, JsonSerializable {
if (filter_var($id, FILTER_VALIDATE_URL) !== false) {
$id = strtr($id, ['http://iconclass.org/rkd/' => '', 'http://iconclass.org/' => '', 'https://iconclass.org/' => '']);
}
$id = trim($id, "/");
if (preg_match("/^[0-9a-z\/]*$/", $id) === false) return false;
if (!empty(trim($id, '0123456789abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ'))) {
return false;
}
return $id;
@@ -647,7 +656,7 @@ enum MDNodaRepository implements MDValueEnumInterface, JsonSerializable {
return false;
}
return $id;
return 'mp' . $id;
}
@@ -752,7 +761,7 @@ enum MDNodaRepository implements MDValueEnumInterface, JsonSerializable {
]),
self::ndp_ikmk => self::validateNdpIkmkForPlaces($id),
self::ndp_ikmk_persons => self::validateNumericId($id, ['https://ikmk.smb.museum/ndp/person/']),
self::nomisma => str_replace('http://nomisma.org/id/', '', $id),
self::nomisma => self::validateNumericId($id, ['http://nomisma.org/id/']),
self::npg => self::validateNpgId($id),
self::oberbegriffsdatei => self::validateNumericId($id, ['https://term.museum-digital.de/oberbegriffsdatei/tag/']),
self::orcid => self::validateOrcidId($id),