Improve test coverage in MDNodaRepository
This commit is contained in:
2 files changed
+100
-7
No files matched your search
@@ -117,8 +117,9 @@ public static function fromString(string $input):MDNodaRepository {
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 @@ public static function fromUrl(string $input):MDNodaRepository {
|
||||
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 @@ private static function validateIconclassId(string $id):string|false {
|
||||
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 @@ private static function validateNpgId(string $id):string|false {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $id;
|
||||
return 'mp' . $id;
|
||||
|
||||
}
|
||||
|
||||
@@ -752,7 +761,7 @@ public function validateId(string $id):string|false {
|
||||
]),
|
||||
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),
|
||||
|
||||
Reference in new issue
Block a user