forked from museum-digital/MDAllowedValueSets
Compare commits
24 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
a01cf57162
|
|||
|
88c357c00f
|
|||
|
07434d41b1
|
|||
|
9a45e7bbf4
|
|||
|
51ae4c4737
|
|||
|
49ebf6fd63
|
|||
|
28ca68d0d7
|
|||
|
c680cd0f9a
|
|||
|
efbb62c6ae
|
|||
|
2fc774430c
|
|||
|
611e0bf54f
|
|||
|
a93d763ebb
|
|||
|
4bd9e010f9
|
|||
|
16440620e0
|
|||
|
7d42e416b3
|
|||
|
0792438a83
|
|||
|
ab38fe88c4
|
|||
|
e9982f4b22
|
|||
|
d31e2581cd
|
|||
|
a368e1851a
|
|||
|
fde98debcb
|
|||
|
61c05f4556
|
|||
|
2e388fc006
|
|||
|
ae1d37f050
|
+1
-1
Submodule l18n updated: 843bfd0535...fffe56da4a
@@ -84,6 +84,9 @@ final class MDEventsSet extends MDValueSet {
|
||||
// Array enthält Ereignistypen, die auf Korrespondenzen hinweisen
|
||||
public const EVENTS_CORRESPONDENCE = [11, 13];
|
||||
|
||||
// List of array types that contain ownership information.
|
||||
public const EVENTS_OWNERSHIP_RELATED = [40, 41, 42, 43, 49, 50, 56, 57, 58];
|
||||
|
||||
/*
|
||||
* Constants for event types without places, times, actors
|
||||
*/
|
||||
|
||||
@@ -17,7 +17,7 @@ final class MDObjectPositionsSet extends MDValueSet {
|
||||
'rear_side',
|
||||
'rear_left', 'rear_top_left', 'rear_top', 'rear_top_right', 'rear_right', 'rear_bottom_right', 'rear_bottom', 'rear_bottom_left', 'rear_center',
|
||||
'underside', 'topside',
|
||||
'edge', 'inside', 'other',
|
||||
'edge', 'inside', 'other', 'mock_title',
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,146 @@
|
||||
<?PHP
|
||||
declare(strict_types = 1);
|
||||
|
||||
/**
|
||||
* Represents a sort order option in DB queries (ASC, DESC).
|
||||
*/
|
||||
enum MDDbQueryAscDesc implements MDValueEnumInterface, JsonSerializable {
|
||||
|
||||
case ASC;
|
||||
case DESC;
|
||||
|
||||
/**
|
||||
* Returns a value of this type based on a string.
|
||||
*
|
||||
* @param string $input Input to get a value from.
|
||||
*
|
||||
* @return MDDbQueryAscDesc
|
||||
*/
|
||||
public static function fromString(string $input):MDDbQueryAscDesc {
|
||||
|
||||
return match($input) {
|
||||
'asc' => self::ASC,
|
||||
'ASC' => self::ASC,
|
||||
'desc' => self::DESC,
|
||||
'DESC' => self::DESC,
|
||||
default => throw new MDpageParameterNotFromListException("Unknown sort order"),
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a value of this type based on an integer.
|
||||
*
|
||||
* @param integer $input Input to get a value from.
|
||||
*
|
||||
* @return MDDbQueryAscDesc
|
||||
*/
|
||||
public static function fromInt(int $input):MDDbQueryAscDesc {
|
||||
|
||||
return match($input) {
|
||||
1 => self::ASC,
|
||||
2 => self::DESC,
|
||||
default => throw new MDpageParameterNotFromListException("Unknown sort order"),
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Lists all available names.
|
||||
*
|
||||
* @return array<string>
|
||||
*/
|
||||
public static function caseNames():array {
|
||||
|
||||
$output = [];
|
||||
|
||||
$cases = self::cases();
|
||||
foreach ($cases as $case) {
|
||||
$output[] = $case->name;
|
||||
}
|
||||
|
||||
return $output;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an integer representation of the collective (for storage in DB).
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function toInt():int {
|
||||
|
||||
return match($this) {
|
||||
self::ASC => 1,
|
||||
self::DESC => 2,
|
||||
# default => throw new MDpageParameterNotFromListException("Unknown measurement type"),
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the SQL representation of the entity.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function toDbName():string {
|
||||
|
||||
return match ($this) {
|
||||
self::ASC => 'ASC',
|
||||
self::DESC => 'DESC',
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an unsorted list of the entries in a translated version.
|
||||
*
|
||||
* @param MDTlLoader $tlLoader Translation loader.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public static function getUnsortedList(MDTlLoader $tlLoader):array {
|
||||
return MDValueSet::getTlUnsortedList($tlLoader, self::caseNames(), "query_asc_desc", "query_asc_desc");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a sorted list of the entries in a translated version.
|
||||
*
|
||||
* @param MDTlLoader $tlLoader Translation loader.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public static function getSortedList(MDTlLoader $tlLoader):array {
|
||||
return MDValueSet::getTlSortedList($tlLoader, self::caseNames(), "query_asc_desc", "query_asc_desc");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the current value in translation.
|
||||
*
|
||||
* @param MDTlLoader $tlLoader Translation loader.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTledName(MDTlLoader $tlLoader):string {
|
||||
|
||||
return $tlLoader->tl("query_asc_desc", "query_asc_desc", $this->name);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides the option to serialize as a string during json_encode().
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function jsonSerialize():string {
|
||||
|
||||
return $this->name;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -26,10 +26,14 @@ enum MDGender implements MDValueEnumInterface, JsonSerializable {
|
||||
public static function fromString(string $input):MDGender {
|
||||
|
||||
return match($input) {
|
||||
"0",
|
||||
"" => self::none,
|
||||
"none" => self::none,
|
||||
"1",
|
||||
"female" => self::female,
|
||||
"2",
|
||||
"male" => self::male,
|
||||
"3",
|
||||
"other" => self::other,
|
||||
default => throw new MDpageParameterNotFromListException("Unknown gender"),
|
||||
};
|
||||
|
||||
@@ -49,6 +49,16 @@ enum MDMeasurementType implements MDValueEnumInterface, JsonSerializable {
|
||||
case length_blade;
|
||||
case height_blade;
|
||||
case width_blade;
|
||||
case length_handle;
|
||||
case height_handle;
|
||||
case width_handle;
|
||||
case length_scabbard;
|
||||
case height_scabbard;
|
||||
case width_scabbard;
|
||||
|
||||
case length_label;
|
||||
case height_label;
|
||||
case width_label;
|
||||
|
||||
case number_of_sheets;
|
||||
case number_of_double_pages;
|
||||
@@ -61,6 +71,22 @@ enum MDMeasurementType implements MDValueEnumInterface, JsonSerializable {
|
||||
case width_of_base;
|
||||
case diameter_of_base;
|
||||
|
||||
case height_image_mount_inner;
|
||||
case height_image_mount_outer;
|
||||
case width_image_mount_inner;
|
||||
case width_image_mount_outer;
|
||||
|
||||
case height_plate;
|
||||
case width_plate;
|
||||
|
||||
case length_packaging;
|
||||
case height_packaging;
|
||||
case width_packaging;
|
||||
|
||||
case length_box;
|
||||
case height_box;
|
||||
case width_box;
|
||||
|
||||
/**
|
||||
* Returns a value of this type based on a string.
|
||||
*
|
||||
@@ -104,6 +130,15 @@ enum MDMeasurementType implements MDValueEnumInterface, JsonSerializable {
|
||||
'length_blade' => self::length_blade,
|
||||
'height_blade' => self::height_blade,
|
||||
'width_blade' => self::width_blade,
|
||||
'length_handle' => self::length_handle,
|
||||
'height_handle' => self::height_handle,
|
||||
'width_handle' => self::width_handle,
|
||||
'length_scabbard' => self::length_scabbard,
|
||||
'height_scabbard' => self::height_scabbard,
|
||||
'width_scabbard' => self::width_scabbard,
|
||||
'length_label' => self::length_label,
|
||||
'height_label' => self::height_label,
|
||||
'width_label' => self::width_label,
|
||||
'number_of_sheets' => self::number_of_sheets,
|
||||
'number_of_double_pages' => self::number_of_double_pages,
|
||||
'number_of_standalone_sheets' => self::number_of_standalone_sheets,
|
||||
@@ -113,6 +148,18 @@ enum MDMeasurementType implements MDValueEnumInterface, JsonSerializable {
|
||||
'height_of_base' => self::height_of_base,
|
||||
'width_of_base' => self::width_of_base,
|
||||
'diameter_of_base' => self::diameter_of_base,
|
||||
'height_image_mount_inner' => self::height_image_mount_inner,
|
||||
'height_image_mount_outer' => self::height_image_mount_outer,
|
||||
'width_image_mount_inner' => self::width_image_mount_inner,
|
||||
'width_image_mount_outer' => self::width_image_mount_outer,
|
||||
'height_plate' => self::height_plate,
|
||||
'width_plate' => self::width_plate,
|
||||
'length_packaging' => self::length_packaging,
|
||||
'height_packaging' => self::height_packaging,
|
||||
'width_packaging' => self::width_packaging,
|
||||
'length_box' => self::length_box,
|
||||
'height_box' => self::height_box,
|
||||
'width_box' => self::width_box,
|
||||
default => throw new MDpageParameterNotFromListException("Unknown measurement type"),
|
||||
};
|
||||
|
||||
@@ -170,6 +217,27 @@ enum MDMeasurementType implements MDValueEnumInterface, JsonSerializable {
|
||||
40 => self::height_of_base,
|
||||
41 => self::width_of_base,
|
||||
42 => self::diameter_of_base,
|
||||
43 => self::length_handle,
|
||||
44 => self::height_handle,
|
||||
45 => self::width_handle,
|
||||
46 => self::length_scabbard,
|
||||
47 => self::height_scabbard,
|
||||
48 => self::width_scabbard,
|
||||
49 => self::length_label,
|
||||
50 => self::height_label,
|
||||
51 => self::width_label,
|
||||
52 => self::height_image_mount_inner,
|
||||
53 => self::height_image_mount_outer,
|
||||
54 => self::width_image_mount_inner,
|
||||
55 => self::width_image_mount_outer,
|
||||
56 => self::height_plate,
|
||||
57 => self::width_plate,
|
||||
58 => self::length_packaging,
|
||||
59 => self::height_packaging,
|
||||
60 => self::width_packaging,
|
||||
61 => self::length_box,
|
||||
62 => self::height_box,
|
||||
63 => self::width_box,
|
||||
default => throw new MDpageParameterNotFromListException("Unknown measurement type"),
|
||||
};
|
||||
|
||||
@@ -247,6 +315,27 @@ enum MDMeasurementType implements MDValueEnumInterface, JsonSerializable {
|
||||
self::height_of_base => self::height,
|
||||
self::width_of_base => self::width,
|
||||
self::diameter_of_base => self::diameter,
|
||||
self::length_handle => self::length,
|
||||
self::height_handle => self::height,
|
||||
self::width_handle => self::width,
|
||||
self::length_scabbard => self::length,
|
||||
self::height_scabbard => self::height,
|
||||
self::width_scabbard => self::width,
|
||||
self::length_label => self::length,
|
||||
self::height_label => self::height,
|
||||
self::width_label => self::width,
|
||||
self::height_image_mount_inner => self::height,
|
||||
self::height_image_mount_outer => self::height,
|
||||
self::width_image_mount_inner => self::width,
|
||||
self::width_image_mount_outer => self::width,
|
||||
self::height_plate => self::height,
|
||||
self::width_plate => self::width,
|
||||
self::length_packaging => self::length,
|
||||
self::height_packaging => self::height,
|
||||
self::width_packaging => self::width,
|
||||
self::length_box => self::length,
|
||||
self::height_box => self::height,
|
||||
self::width_box => self::width,
|
||||
# default => throw new MDpageParameterNotFromListException("Unknown measurement type"),
|
||||
};
|
||||
|
||||
@@ -302,6 +391,27 @@ enum MDMeasurementType implements MDValueEnumInterface, JsonSerializable {
|
||||
self::height_of_base => 40,
|
||||
self::width_of_base => 41,
|
||||
self::diameter_of_base => 42,
|
||||
self::length_handle => 43,
|
||||
self::height_handle => 44,
|
||||
self::width_handle => 45,
|
||||
self::length_scabbard => 46,
|
||||
self::height_scabbard => 47,
|
||||
self::width_scabbard => 48,
|
||||
self::length_label => 49,
|
||||
self::height_label => 50,
|
||||
self::width_label => 51,
|
||||
self::height_image_mount_inner => 52,
|
||||
self::height_image_mount_outer => 53,
|
||||
self::width_image_mount_inner => 54,
|
||||
self::width_image_mount_outer => 55,
|
||||
self::height_plate => 56,
|
||||
self::width_plate => 57,
|
||||
self::length_packaging => 58,
|
||||
self::height_packaging => 59,
|
||||
self::width_packaging => 60,
|
||||
self::length_box => 61,
|
||||
self::height_box => 62,
|
||||
self::width_box => 63,
|
||||
# default => throw new MDpageParameterNotFromListException("Unknown measurement type"),
|
||||
};
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
@@ -393,11 +399,24 @@ enum MDNodaRepository implements MDValueEnumInterface, JsonSerializable {
|
||||
*/
|
||||
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(strtr($id, [
|
||||
'http://iconclass.org/rkd/' => '',
|
||||
'http://iconclass.org/' => '',
|
||||
'https://iconclass.org/' => '',
|
||||
'http://www.iconclass.org/rkd/' => '',
|
||||
'http://www.iconclass.org/' => '',
|
||||
'https://www.iconclass.org/' => '',
|
||||
]), '/');
|
||||
|
||||
if (!empty(trim($id, '0123456789abcdefghijklmnopqrstuvwxyzäüö-/ABCDEFGHIJKLMNOPQRSTUVWXYZÄÜÖ(+), '))) {
|
||||
// Try url_decoding
|
||||
$id = urldecode($id);
|
||||
if (!empty(trim($id, '0123456789abcdefghijklmnopqrstuvwxyzäüö-/ABCDEFGHIJKLMNOPQRSTUVWXYZÄÜÖ(+), '))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (preg_match("/^[0-9a-z\/]*$/", $id) === false) return false;
|
||||
if (!is_numeric(substr($id, 0, 1))) return false;
|
||||
|
||||
return $id;
|
||||
|
||||
@@ -442,6 +461,9 @@ enum MDNodaRepository implements MDValueEnumInterface, JsonSerializable {
|
||||
if (str_contains($id, '(')) {
|
||||
$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
|
||||
if (preg_match("/^[0-9-X]*$/", $id) === false) {
|
||||
@@ -620,6 +642,31 @@ enum MDNodaRepository implements MDValueEnumInterface, JsonSerializable {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates an nomisma ID, returning a string or false.
|
||||
*
|
||||
* @param string $id ID to validate.
|
||||
*
|
||||
* @return string|false
|
||||
*/
|
||||
private static function validateNomismaId(string $id):string|false {
|
||||
|
||||
$id = strtr($id, [
|
||||
"http://nomisma.org/id/" => '',
|
||||
"https://nomisma.org/id/" => '',
|
||||
"http://www.nomisma.org/id/" => '',
|
||||
"https://www.nomisma.org/id/" => '',
|
||||
]);
|
||||
|
||||
// Ensure the remaining string does not contain spaces or slashes
|
||||
foreach (['/', ' '] as $disallowedChar) {
|
||||
if (str_contains($id, $disallowedChar)) return false;
|
||||
}
|
||||
|
||||
return $id;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates an NPG ID, returning a string or false.
|
||||
*
|
||||
@@ -630,7 +677,10 @@ enum MDNodaRepository implements MDValueEnumInterface, JsonSerializable {
|
||||
private static function validateNpgId(string $id):string|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))) {
|
||||
@@ -641,7 +691,7 @@ enum MDNodaRepository implements MDValueEnumInterface, JsonSerializable {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $id;
|
||||
return 'mp' . $id;
|
||||
|
||||
}
|
||||
|
||||
@@ -658,15 +708,18 @@ enum MDNodaRepository implements MDValueEnumInterface, JsonSerializable {
|
||||
$id = strtr($id, [
|
||||
'http://www.wikidata.org/wiki/' => '',
|
||||
'http://www.wikidata.org/entity/' => '',
|
||||
'http://www.wikidata.org/w/index.php?search=&search=' => '',
|
||||
'https://www.wikidata.org/wiki/' => '',
|
||||
'https://www.wikidata.org/entity/' => '',
|
||||
'https://www.wikidata.org/w/index.php?search=&search=' => '',
|
||||
]);
|
||||
|
||||
if (str_starts_with($id, 'https://www.wikidata.org/w/index.php?title=')) {
|
||||
$id = str_replace('https://www.wikidata.org/w/index.php?title=', '', $id);
|
||||
if (($endPos = strpos($id, '&')) !== false) {
|
||||
$id = substr($id, 0, $endPos);
|
||||
foreach (['http://www.wikidata.org/w/index.php?title=', 'https://www.wikidata.org/w/index.php?title='] as $urlPrefix) {
|
||||
if (str_starts_with($id, $urlPrefix)) {
|
||||
$id = str_replace($urlPrefix, '', $id);
|
||||
if (($endPos = strpos($id, '&')) !== false) {
|
||||
$id = substr($id, 0, $endPos);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -734,7 +787,7 @@ enum MDNodaRepository implements MDValueEnumInterface, JsonSerializable {
|
||||
self::klbb => self::validateNumericId($id, ['https://www.kl-bb.de/artist/', 'https://www.kl-bb.de/?page=actor&subPage=']),
|
||||
self::lcsh => self::validateLcshId($id),
|
||||
self::loc => self::validateLocId($id),
|
||||
self::mindatorg => self::validateNumericId($id, ['https://www.mindat.org/min-', '.html']),
|
||||
self::mindatorg => self::validateNumericId($id, ['http://www.mindat.org/min-', 'https://www.mindat.org/min-', '.html']),
|
||||
self::moebeltypologie => self::validateNumericId($id, ['https://term.museum-digital.de/moebel/tag/']),
|
||||
self::ndb_adb => self::validateGndId($id, ['https://www.deutsche-biographie.de/pnd', 'https://www.deutsche-biographie.de/gnd', '.html', '#adbcontent', '#ndbcontent', '#indexcontent']),
|
||||
self::ndl => self::validateNumericId($id, [
|
||||
@@ -743,7 +796,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::validateNomismaId($id),
|
||||
self::npg => self::validateNpgId($id),
|
||||
self::oberbegriffsdatei => self::validateNumericId($id, ['https://term.museum-digital.de/oberbegriffsdatei/tag/']),
|
||||
self::orcid => self::validateOrcidId($id),
|
||||
@@ -760,6 +813,7 @@ enum MDNodaRepository implements MDValueEnumInterface, JsonSerializable {
|
||||
]),
|
||||
self::viaf => self::validateNumericId($id, [
|
||||
'https://viaf.org/viaf/',
|
||||
'https://viaf.org/de/viaf/',
|
||||
'http://viaf.org/viaf/',
|
||||
]),
|
||||
self::wikidata => self::validateWikidataId($id),
|
||||
@@ -793,7 +847,12 @@ enum MDNodaRepository implements MDValueEnumInterface, JsonSerializable {
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public static function getUnsortedList(MDTlLoader $tlLoader):array {
|
||||
return MDValueSet::getTlUnsortedList($tlLoader, self::caseNames(), "attendance_status_set", "attendance_status_set");
|
||||
|
||||
$output = [];
|
||||
foreach (self::cases() as $case) {
|
||||
$output[$case->name] = $case->toFullName();
|
||||
}
|
||||
return $output;
|
||||
|
||||
}
|
||||
|
||||
@@ -805,7 +864,10 @@ enum MDNodaRepository implements MDValueEnumInterface, JsonSerializable {
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public static function getSortedList(MDTlLoader $tlLoader):array {
|
||||
return MDValueSet::getTlSortedList($tlLoader, self::caseNames(), "attendance_status_set", "attendance_status_set");
|
||||
|
||||
$out = self::getUnsortedList($tlLoader);
|
||||
asort($out);
|
||||
return $out;
|
||||
|
||||
}
|
||||
|
||||
@@ -818,7 +880,7 @@ enum MDNodaRepository implements MDValueEnumInterface, JsonSerializable {
|
||||
*/
|
||||
public function getTledName(MDTlLoader $tlLoader):string {
|
||||
|
||||
return $tlLoader->tl("attendance_status_set", "attendance_status_set", $this->name);
|
||||
return $this->toFullName();
|
||||
|
||||
}
|
||||
|
||||
|
||||
+459
-58
@@ -6,6 +6,9 @@
|
||||
*/
|
||||
declare(strict_types = 1);
|
||||
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/MDNodaRepository.php';
|
||||
@@ -13,80 +16,478 @@ require_once __DIR__ . '/../src/enums/MDNodaRepository.php';
|
||||
/**
|
||||
* Tests for home page.
|
||||
*/
|
||||
#[small]
|
||||
#[CoversClass(\MDNodaRepository::class)]
|
||||
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
|
||||
*/
|
||||
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"));
|
||||
self::assertEquals("102423008", MDNodaRepository::gnd->validateId("http://d-nb.info/gnd/102423008"));
|
||||
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("1037602218", MDNodaRepository::gnd->validateId("https://explore.gnd.network/gnd/1037602218"));
|
||||
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"));
|
||||
/**
|
||||
* Data provider for validating BNE IDs.
|
||||
*
|
||||
* @return Generator<string, array{0: string|false, 1: string}>
|
||||
*/
|
||||
public static function bneIdForValidationProvider():Generator {
|
||||
|
||||
// NDL (Japan)
|
||||
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"));
|
||||
yield "Full URL, http / XX5034943" => ["XX5034943", "http://datos.bne.es/persona/XX5034943"];
|
||||
yield "Full URL, https / XX5034943" => ["XX5034943", "https://datos.bne.es/persona/XX5034943"];
|
||||
yield "ID / XX5034943" => ["XX5034943", "XX5034943"];
|
||||
yield "Broken input / XX503494safdsaf;3" => [false, "XX503494safdsaf;3"];
|
||||
|
||||
// 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"));
|
||||
/**
|
||||
* Ensure validating references to the BNE works.
|
||||
*
|
||||
* @param string|false $expected Expected output.
|
||||
* @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("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"));
|
||||
self::assertEquals($expected, MDNodaRepository::bne->validateId($inputString));
|
||||
|
||||
// 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"));
|
||||
self::assertEquals("42893419", MDNodaRepository::viaf->validateId("https://viaf.org/viaf/42893419/"));
|
||||
self::assertEquals("86145857811423020454", MDNodaRepository::viaf->validateId("86145857811423020454"));
|
||||
self::assertEquals("2869150688328112660005", MDNodaRepository::viaf->validateId("2869150688328112660005"));
|
||||
self::assertEquals(false, MDNodaRepository::viaf->validateId("2869150688328112;;660005"));
|
||||
/**
|
||||
* Data provider for validating GND IDs.
|
||||
*
|
||||
* @return Generator<string, array{0: string|false, 1: string}>
|
||||
*/
|
||||
public static function gndIdForValidationProvider():Generator {
|
||||
|
||||
# NDP-IKMK (Places)
|
||||
self::assertEquals("ort/2847", MDNodaRepository::ndp_ikmk->validateId("https://ikmk.smb.museum/ndp/ort/2847"));
|
||||
self::assertEquals("land/123", MDNodaRepository::ndp_ikmk->validateId("https://ikmk.smb.museum/ndp/land/123"));
|
||||
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"));
|
||||
yield "Full URL, http / 102423008" => ["102423008", "http://d-nb.info/gnd/102423008"];
|
||||
yield "Full URL, https / 102423008" => ["102423008", "https://d-nb.info/gnd/102423008"];
|
||||
yield "Full URL, http, superfluous spaces / 102423008" => ["102423008", "http://d-nb.info/gnd/ 102423008"];
|
||||
|
||||
# Catalogue of Life
|
||||
self::assertEquals(false, MDNodaRepository::col->validateId("123123"));
|
||||
self::assertEquals("C46V", MDNodaRepository::col->validateId("https://www.catalogueoflife.org/data/taxon/C46V"));
|
||||
self::assertEquals("CRLT8", MDNodaRepository::col->validateId("https://www.catalogueoflife.org/data/taxon/CRLT8"));
|
||||
yield "Full URL, http / 1037602218" => ["1037602218", "http://d-nb.info/gnd/1037602218"];
|
||||
yield "Full URL, GND Explorer / 1037602218" => ["1037602218", "https://explore.gnd.network/gnd/1037602218"];
|
||||
yield "ID / 1037602218" => ["102423008", "102423008"];
|
||||
yield "ID, trailing comma / 102423008" => ["102423008", "102423008,"];
|
||||
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; fkld;s102423008" => [false, "fkld;s102423008"];
|
||||
yield "Broken ID; s102423008-x" => [false, "s102423008-x"];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 "incomplete ID without prefix / 01751 > mp01751" => ["mp01751", "01751"];
|
||||
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"];
|
||||
yield "Broken input / 7168a" => [false, "7168a"];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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, de / 34470968" => ["34470968", "https://viaf.org/de/viaf/34470968"];
|
||||
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"];
|
||||
yield "Broken input / a/123123" => [false, "a/123123"];
|
||||
yield "Broken input / land/123123-a" => [false, "land/123123-a"];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for validating references to orcid.
|
||||
*
|
||||
* @return Generator<string, array{0: string|false, 1: string}>
|
||||
*/
|
||||
public static function orcidIdForValidationProvider():Generator {
|
||||
|
||||
yield "0000-0000-0000-0000 ; url, http" => ["0000-0000-0000-0000", "http://orcid.org/0000-0000-0000-0000"];
|
||||
yield "0000-0000-0000-0000 ; url, https" => ["0000-0000-0000-0000", "https://orcid.org/0000-0000-0000-0000"];
|
||||
yield "0000-0000-0000-0000 ; ID" => ["0000-0000-0000-0000", "0000-0000-0000-0000"];
|
||||
yield "Broken input / adfdasjfklasjl" => [false, "adfdasjfklasjl"];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure validating orcid references.
|
||||
*
|
||||
* @param string|false $expected Expected output.
|
||||
* @param string $inputString Input string.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
#[DataProvider('orcidIdForValidationProvider')]
|
||||
public function testOrcidIdValidation(string|false $expected, string $inputString):void {
|
||||
|
||||
self::assertEquals($expected, MDNodaRepository::orcid->validateId($inputString));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for validating references to iconclass.
|
||||
*
|
||||
* @return Generator<string, array{0: string|false, 1: string}>
|
||||
*/
|
||||
public static function iconclassIdForValidationProvider():Generator {
|
||||
|
||||
yield "45C221 ; url, http" => ["45C221", "http://iconclass.org/rkd/45C221"];
|
||||
yield "45C221 ; url, http, www." => ["45C221", "http://www.iconclass.org/rkd/45C221"];
|
||||
yield "45C221 ; url, http, www., trailing slash" => ["45C221", "http://www.iconclass.org/rkd/45C221/"];
|
||||
yield "45C221 ; url, https" => ["45C221", "http://iconclass.org/rkd//45C221"];
|
||||
yield "45C221(+321) ; url, https" => ["45C221(+321)", "http://iconclass.org/rkd//45C221(+321)"];
|
||||
yield "45C221 ; ID" => ["45C221", "45C221"];
|
||||
yield "45C221(+321) ; ID" => ["45C221(+321)", "45C221(+321)"];
|
||||
yield "45C221(%2B321) > 45C221(+321) ; ID" => ["45C221(+321)", "45C221(%2B321)"];
|
||||
yield "82A(Rattenfanger) ; ID" => ["82A(Rattenfanger)", "82A(Rattenfanger)"];
|
||||
yield "82A(Rattenfänger) ; URL" => ["82A(Rattenfänger)", "http://iconclass.org/rkd/82A(Rattenfänger)"];
|
||||
yield "83(BERNARDIN DE SAINT-PIERRE, Paul et Virginie) ; ID" => ["83(BERNARDIN DE SAINT-PIERRE, Paul et Virginie)", "83(BERNARDIN DE SAINT-PIERRE, Paul et Virginie)"];
|
||||
yield "Broken input / adfdasjfklasäj%l" => [false, "adfdasjfklasäj%l"];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure validating iconclass references.
|
||||
*
|
||||
* @param string|false $expected Expected output.
|
||||
* @param string $inputString Input string.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
#[DataProvider('iconclassIdForValidationProvider')]
|
||||
public function testIconclassIdValidation(string|false $expected, string $inputString):void {
|
||||
|
||||
self::assertEquals($expected, MDNodaRepository::iconclass->validateId($inputString));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for validating nomisma entries.
|
||||
*
|
||||
* @return Generator<string, array{0: string|false, 1: string}>
|
||||
*/
|
||||
public static function nomismaIdForValidationProvider():Generator {
|
||||
|
||||
yield "1234 (url, https)" => ["1234", "https://nomisma.org/id/1234"];
|
||||
yield "1234" => ["1234", "https://nomisma.org/id/1234"];
|
||||
yield "glass (url, https)" => ["glass", "https://nomisma.org/id/glass"];
|
||||
yield "glass (url, http)" => ["glass", "http://nomisma.org/id/glass"];
|
||||
yield "coin (url, http.www)" => ["coin", "http://www.nomisma.org/id/coin"];
|
||||
yield "glass" => ["glass", "glass"];
|
||||
yield "Broken input / empty string" => [false, ""];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure validating nomisma references.
|
||||
*
|
||||
* @param string|false $expected Expected output.
|
||||
* @param string $inputString Input string.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
#[DataProvider('nomismaIdForValidationProvider')]
|
||||
public function testNomismaIdValidation(string|false $expected, string $inputString):void {
|
||||
|
||||
self::assertEquals($expected, MDNodaRepository::nomisma->validateId($inputString));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests conversion of already validated and set up entries to strings.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testConversionWorks():void {
|
||||
|
||||
$entry = MDNodaRepository::fromUrl("http://www.wikidata.org/w/index.php?title=Q834961&oldid=2256125706");
|
||||
|
||||
self::assertEquals("wikidata", $entry->toDbName());
|
||||
self::assertEquals("Wikidata", $entry->toFullName());
|
||||
self::assertEquals("https://www.wikidata.org/entity/", $entry->getUrlPrefix());
|
||||
self::assertEquals("https://www.wikidata.org/entity/a", $entry->getEntityLink("a"));
|
||||
self::assertEquals("https://www.wikidata.org/w/index.php?search=&search=a&ns0=1&ns120=1", $entry->getSearchLink("a"));
|
||||
|
||||
self::assertEquals('"wikidata"', MD_STD::json_encode_object($entry));
|
||||
|
||||
self::assertNotEmpty(MDNodaRepository::caseNames());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user