Fix bug where BNF IDs where validated too easily
This commit is contained in:
@@ -782,7 +782,7 @@ enum MDNodaRepository implements MDValueEnumInterface, JsonSerializable {
|
||||
}
|
||||
else $id = self::validateNumericId($id, ["https://catalogue.bnf.fr/ark:/12148/cb"]);
|
||||
|
||||
if ($id === false) {
|
||||
if ($id === false || strlen($id) < 6) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -112,7 +112,9 @@ final class MDNodaRepositoryTest extends TestCase {
|
||||
*/
|
||||
public static function bnfIdForValidationProvider():Generator {
|
||||
|
||||
yield "Broken input / duplicate https" => [false, "https://catalogue.bnf.fr/ark:/12148/cbhttps://catalogue.bnf.fr/ark:/12148/cbhttps://catalogue.bnf.fr/ark:/12148/cb104183522"];
|
||||
yield "Working but duplicate https" => ["104183522", "https://catalogue.bnf.fr/ark:/12148/cbhttps://catalogue.bnf.fr/ark:/12148/cbhttps://catalogue.bnf.fr/ark:/12148/cb104183522"];
|
||||
yield "Broken input / 'X'" => [false, "X"];
|
||||
yield "Broken input / GND link" => [false, "https://d-nb.info/gnd/11858815X"];
|
||||
|
||||
}
|
||||
|
||||
@@ -140,6 +142,21 @@ final class MDNodaRepositoryTest extends TestCase {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure validating references to the BNF.
|
||||
*
|
||||
* @param string|false $expected Expected output.
|
||||
* @param string $inputString Input string.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
#[DataProvider('bnfIdForValidationProvider')]
|
||||
public function testBnfIdValidation(string|false $expected, string $inputString):void {
|
||||
|
||||
self::assertEquals($expected, MDNodaRepository::bnf->validateId($inputString));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure validating references to the GND / Gemeinsame Normdatei works.
|
||||
*
|
||||
@@ -529,4 +546,17 @@ final class MDNodaRepositoryTest extends TestCase {
|
||||
self::assertNotEmpty(MDNodaRepository::caseNames());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests conversion of already validated and set up entries to strings, GND version.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testConversionWorksGnd():void {
|
||||
|
||||
$entry = MDNodaRepository::fromUrl("https://d-nb.info/gnd/11858815X");
|
||||
|
||||
self::assertEquals("gnd", $entry->toDbName());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user