Add tests for lookup functions by vocabulary references
This commit is contained in:
parent
a9c506497c
commit
669a8a1459
|
@ -119,16 +119,16 @@ final class NodaIDGetterTest extends TestCase {
|
||||||
*/
|
*/
|
||||||
public static function persinstByNameProvider():array {
|
public static function persinstByNameProvider():array {
|
||||||
|
|
||||||
$mysqli = md_main_mysqli_connect();
|
$mysqli = md_noda_mysqli_connect();
|
||||||
$persinstByNameSimple = self::_getNameAndIdFromDbQuery($mysqli, "SELECT `persinst_name`, `persinst_id`
|
$persinstByNameSimple = self::_getNameAndIdFromDbQuery($mysqli, "SELECT `persinst_name`, `persinst_id`
|
||||||
FROM `" . DATABASENAME_NODA . "`.`persinst`
|
FROM `persinst`
|
||||||
WHERE INSTR(`persinst_name`, 'i')");
|
WHERE INSTR(`persinst_name`, 'i')");
|
||||||
$persinstByDisplayNameSimple = self::_getNameAndIdFromDbQuery($mysqli, "SELECT `persinst_anzeigename`, `persinst_id`
|
$persinstByDisplayNameSimple = self::_getNameAndIdFromDbQuery($mysqli, "SELECT `persinst_anzeigename`, `persinst_id`
|
||||||
FROM `" . DATABASENAME_NODA . "`.`persinst`
|
FROM `persinst`
|
||||||
WHERE INSTR(`persinst_anzeigename`, 'i')
|
WHERE INSTR(`persinst_anzeigename`, 'i')
|
||||||
AND `persinst_sterbejahr` != ''");
|
AND `persinst_sterbejahr` != ''");
|
||||||
$persinstByDisplayNameSimple = self::_getNameAndIdFromDbQuery($mysqli, "SELECT `trans_name`, `persinst_id`
|
$persinstByDisplayNameSimple = self::_getNameAndIdFromDbQuery($mysqli, "SELECT `trans_name`, `persinst_id`
|
||||||
FROM `" . DATABASENAME_NODA . "`.`persinst_translation`
|
FROM `persinst_translation`
|
||||||
WHERE INSTR(`trans_name`, 'i')
|
WHERE INSTR(`trans_name`, 'i')
|
||||||
AND `trans_language` = 'de'");
|
AND `trans_language` = 'de'");
|
||||||
$mysqli->close();
|
$mysqli->close();
|
||||||
|
@ -165,9 +165,9 @@ final class NodaIDGetterTest extends TestCase {
|
||||||
*/
|
*/
|
||||||
public static function persinstByRewriteProvider():array {
|
public static function persinstByRewriteProvider():array {
|
||||||
|
|
||||||
$mysqli = md_main_mysqli_connect();
|
$mysqli = md_noda_mysqli_connect();
|
||||||
$persinstByRewriteSimple = self::_getNameAndIdFromDbQuery($mysqli, "SELECT `input_name`, `persinst_id`
|
$persinstByRewriteSimple = self::_getNameAndIdFromDbQuery($mysqli, "SELECT `input_name`, `persinst_id`
|
||||||
FROM `" . DATABASENAME_NODA . "`.`persinst_rewriting`
|
FROM `persinst_rewriting`
|
||||||
WHERE INSTR(`input_name`, 'i')");
|
WHERE INSTR(`input_name`, 'i')");
|
||||||
$mysqli->close();
|
$mysqli->close();
|
||||||
|
|
||||||
|
@ -201,12 +201,12 @@ final class NodaIDGetterTest extends TestCase {
|
||||||
*/
|
*/
|
||||||
public static function placeByNameProvider():array {
|
public static function placeByNameProvider():array {
|
||||||
|
|
||||||
$mysqli = md_main_mysqli_connect();
|
$mysqli = md_noda_mysqli_connect();
|
||||||
$placeByNameSimple = self::_getNameAndIdFromDbQuery($mysqli, "SELECT `ort_name`, `ort_id`
|
$placeByNameSimple = self::_getNameAndIdFromDbQuery($mysqli, "SELECT `ort_name`, `ort_id`
|
||||||
FROM `" . DATABASENAME_NODA . "`.`orte`
|
FROM `orte`
|
||||||
WHERE INSTR(`ort_name`, 'i')");
|
WHERE INSTR(`ort_name`, 'i')");
|
||||||
$placeByDisplayNameSimple = self::_getNameAndIdFromDbQuery($mysqli, "SELECT `trans_name`, `ort_id`
|
$placeByDisplayNameSimple = self::_getNameAndIdFromDbQuery($mysqli, "SELECT `trans_name`, `ort_id`
|
||||||
FROM `" . DATABASENAME_NODA . "`.`ort_translation`
|
FROM `ort_translation`
|
||||||
WHERE INSTR(`trans_name`, 'i')
|
WHERE INSTR(`trans_name`, 'i')
|
||||||
AND `trans_language` = 'de'");
|
AND `trans_language` = 'de'");
|
||||||
$mysqli->close();
|
$mysqli->close();
|
||||||
|
@ -242,9 +242,9 @@ final class NodaIDGetterTest extends TestCase {
|
||||||
*/
|
*/
|
||||||
public static function placeByRewriteProvider():array {
|
public static function placeByRewriteProvider():array {
|
||||||
|
|
||||||
$mysqli = md_main_mysqli_connect();
|
$mysqli = md_noda_mysqli_connect();
|
||||||
$placeByRewriteSimple = self::_getNameAndIdFromDbQuery($mysqli, "SELECT `input_name`, `ort_id`
|
$placeByRewriteSimple = self::_getNameAndIdFromDbQuery($mysqli, "SELECT `input_name`, `ort_id`
|
||||||
FROM `" . DATABASENAME_NODA . "`.`ort_rewriting`
|
FROM `ort_rewriting`
|
||||||
WHERE INSTR(`input_name`, 'i')");
|
WHERE INSTR(`input_name`, 'i')");
|
||||||
$mysqli->close();
|
$mysqli->close();
|
||||||
|
|
||||||
|
@ -278,12 +278,12 @@ final class NodaIDGetterTest extends TestCase {
|
||||||
*/
|
*/
|
||||||
public static function tagByNameProvider():array {
|
public static function tagByNameProvider():array {
|
||||||
|
|
||||||
$mysqli = md_main_mysqli_connect();
|
$mysqli = md_noda_mysqli_connect();
|
||||||
$tagByNameSimple = self::_getNameAndIdFromDbQuery($mysqli, "SELECT `tag_name`, `tag_id`
|
$tagByNameSimple = self::_getNameAndIdFromDbQuery($mysqli, "SELECT `tag_name`, `tag_id`
|
||||||
FROM `" . DATABASENAME_NODA . "`.`tag`
|
FROM `tag`
|
||||||
WHERE INSTR(`tag_name`, 'i')");
|
WHERE INSTR(`tag_name`, 'i')");
|
||||||
$tagByDisplayNameSimple = self::_getNameAndIdFromDbQuery($mysqli, "SELECT `trans_name`, `tag_id`
|
$tagByDisplayNameSimple = self::_getNameAndIdFromDbQuery($mysqli, "SELECT `trans_name`, `tag_id`
|
||||||
FROM `" . DATABASENAME_NODA . "`.`tag_translation`
|
FROM `tag_translation`
|
||||||
WHERE INSTR(`trans_name`, 'i')
|
WHERE INSTR(`trans_name`, 'i')
|
||||||
AND `trans_language` = 'de'");
|
AND `trans_language` = 'de'");
|
||||||
$mysqli->close();
|
$mysqli->close();
|
||||||
|
@ -319,9 +319,9 @@ final class NodaIDGetterTest extends TestCase {
|
||||||
*/
|
*/
|
||||||
public static function tagByRewriteProvider():array {
|
public static function tagByRewriteProvider():array {
|
||||||
|
|
||||||
$mysqli = md_main_mysqli_connect();
|
$mysqli = md_noda_mysqli_connect();
|
||||||
$tagByRewriteSimple = self::_getNameAndIdFromDbQuery($mysqli, "SELECT `input_name`, `tag_id`
|
$tagByRewriteSimple = self::_getNameAndIdFromDbQuery($mysqli, "SELECT `input_name`, `tag_id`
|
||||||
FROM `" . DATABASENAME_NODA . "`.`tag_rewriting`
|
FROM `tag_rewriting`
|
||||||
WHERE INSTR(`input_name`, 'i')");
|
WHERE INSTR(`input_name`, 'i')");
|
||||||
$mysqli->close();
|
$mysqli->close();
|
||||||
|
|
||||||
|
@ -363,12 +363,12 @@ final class NodaIDGetterTest extends TestCase {
|
||||||
*/
|
*/
|
||||||
public static function timeByNameProvider():array {
|
public static function timeByNameProvider():array {
|
||||||
|
|
||||||
$mysqli = md_main_mysqli_connect();
|
$mysqli = md_noda_mysqli_connect();
|
||||||
$timeByNameSimple = self::_getNameAndIdFromDbQuery($mysqli, "SELECT `zeit_name`, `zeit_id`
|
$timeByNameSimple = self::_getNameAndIdFromDbQuery($mysqli, "SELECT `zeit_name`, `zeit_id`
|
||||||
FROM `" . DATABASENAME_NODA . "`.`zeiten`
|
FROM `zeiten`
|
||||||
WHERE INSTR(`zeit_name`, 'i')");
|
WHERE INSTR(`zeit_name`, 'i')");
|
||||||
$timeByDisplayNameSimple = self::_getNameAndIdFromDbQuery($mysqli, "SELECT `trans_name`, `zeit_id`
|
$timeByDisplayNameSimple = self::_getNameAndIdFromDbQuery($mysqli, "SELECT `trans_name`, `zeit_id`
|
||||||
FROM `" . DATABASENAME_NODA . "`.`zeit_translation`
|
FROM `zeit_translation`
|
||||||
WHERE INSTR(`trans_name`, 'i')
|
WHERE INSTR(`trans_name`, 'i')
|
||||||
AND `trans_language` = 'de'");
|
AND `trans_language` = 'de'");
|
||||||
$mysqli->close();
|
$mysqli->close();
|
||||||
|
@ -404,9 +404,9 @@ final class NodaIDGetterTest extends TestCase {
|
||||||
*/
|
*/
|
||||||
public static function timeByRewriteProvider():array {
|
public static function timeByRewriteProvider():array {
|
||||||
|
|
||||||
$mysqli = md_main_mysqli_connect();
|
$mysqli = md_noda_mysqli_connect();
|
||||||
$timeByRewriteSimple = self::_getNameAndIdFromDbQuery($mysqli, "SELECT `input_name`, `zeit_id`
|
$timeByRewriteSimple = self::_getNameAndIdFromDbQuery($mysqli, "SELECT `input_name`, `zeit_id`
|
||||||
FROM `" . DATABASENAME_NODA . "`.`zeit_rewriting`
|
FROM `zeit_rewriting`
|
||||||
WHERE INSTR(`input_name`, 'i')");
|
WHERE INSTR(`input_name`, 'i')");
|
||||||
$mysqli->close();
|
$mysqli->close();
|
||||||
|
|
||||||
|
@ -430,4 +430,132 @@ final class NodaIDGetterTest extends TestCase {
|
||||||
$this->runRegularComparisonTests("getTimeIDByRewrite", $name, $expected_id);
|
$this->runRegularComparisonTests("getTimeIDByRewrite", $name, $expected_id);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Entity getters by norm data references
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data provider for norm data reference for actors.
|
||||||
|
*
|
||||||
|
* @return array<array{0: MDNodaLink, 1: integer}>
|
||||||
|
*/
|
||||||
|
public static function nodaRefForActorsProvider():array {
|
||||||
|
|
||||||
|
$mysqli = md_noda_mysqli_connect();
|
||||||
|
$nodaSimple = self::_getNameAndIdFromDbQuery($mysqli, "SELECT `noda_link`, `persinst_id`
|
||||||
|
FROM `noda`
|
||||||
|
WHERE `noda_source` = 'Wikidata'
|
||||||
|
AND `noda_link` != ''");
|
||||||
|
$mysqli->close();
|
||||||
|
|
||||||
|
return [
|
||||||
|
'Valid actor ID by norm data reference: ' . $nodaSimple[0] => [
|
||||||
|
new MDNodaLink(MDNodaRepository::wikidata, $nodaSimple[0]),
|
||||||
|
$nodaSimple[1],
|
||||||
|
],
|
||||||
|
'Invalid, non-existing Wikidata ID' => [
|
||||||
|
new MDNodaLink(MDNodaRepository::wikidata, 'Q11111111111111'),
|
||||||
|
0,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test getting actor ID by norm data reference.
|
||||||
|
*
|
||||||
|
* @param MDNodaLink $link Noda link.
|
||||||
|
* @param integer $expected_id Expected target ID.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
#[DataProvider('nodaRefForActorsProvider')]
|
||||||
|
public function testGetPersinstByNodaLinkWorks(MDNodaLink $link, int $expected_id):void {
|
||||||
|
|
||||||
|
self::assertEquals($expected_id, NodaIDGetter::getPersinstIDByNodaLink($this->_mysqli, $link));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data provider for norm data reference for places.
|
||||||
|
*
|
||||||
|
* @return array<array{0: MDNodaLink, 1: integer}>
|
||||||
|
*/
|
||||||
|
public static function nodaRefForPlacesProvider():array {
|
||||||
|
|
||||||
|
$mysqli = md_noda_mysqli_connect();
|
||||||
|
$nodaSimple = self::_getNameAndIdFromDbQuery($mysqli, "SELECT `noda_link`, `ort_id`
|
||||||
|
FROM `noda_orte`
|
||||||
|
WHERE `noda_source` = 'Wikidata'
|
||||||
|
AND `noda_link` != ''");
|
||||||
|
$mysqli->close();
|
||||||
|
|
||||||
|
return [
|
||||||
|
'Valid place ID by norm data reference: ' . $nodaSimple[0] => [
|
||||||
|
new MDNodaLink(MDNodaRepository::wikidata, $nodaSimple[0]),
|
||||||
|
$nodaSimple[1],
|
||||||
|
],
|
||||||
|
'Invalid, non-existing Wikidata ID' => [
|
||||||
|
new MDNodaLink(MDNodaRepository::wikidata, 'Q11111111111111'),
|
||||||
|
0,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test getting place ID by norm data reference.
|
||||||
|
*
|
||||||
|
* @param MDNodaLink $link Noda link.
|
||||||
|
* @param integer $expected_id Expected target ID.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
#[DataProvider('nodaRefForPlacesProvider')]
|
||||||
|
public function testGetPlaceByNodaLinkWorks(MDNodaLink $link, int $expected_id):void {
|
||||||
|
|
||||||
|
self::assertEquals($expected_id, NodaIDGetter::getPlaceIDByNodaLink($this->_mysqli, $link));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data provider for norm data reference for tags.
|
||||||
|
*
|
||||||
|
* @return array<array{0: MDNodaLink, 1: integer}>
|
||||||
|
*/
|
||||||
|
public static function nodaRefForTagsProvider():array {
|
||||||
|
|
||||||
|
$mysqli = md_noda_mysqli_connect();
|
||||||
|
$nodaSimple = self::_getNameAndIdFromDbQuery($mysqli, "SELECT `noda_link`, `tag_id`
|
||||||
|
FROM `noda_tag`
|
||||||
|
WHERE `noda_source` = 'Wikidata'
|
||||||
|
AND `noda_link` != ''");
|
||||||
|
$mysqli->close();
|
||||||
|
|
||||||
|
return [
|
||||||
|
'Valid tag ID by norm data reference: ' . $nodaSimple[0] => [
|
||||||
|
new MDNodaLink(MDNodaRepository::wikidata, $nodaSimple[0]),
|
||||||
|
$nodaSimple[1],
|
||||||
|
],
|
||||||
|
'Invalid, non-existing Wikidata ID' => [
|
||||||
|
new MDNodaLink(MDNodaRepository::wikidata, 'Q11111111111111'),
|
||||||
|
0,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test getting tag ID by norm data reference.
|
||||||
|
*
|
||||||
|
* @param MDNodaLink $link Noda link.
|
||||||
|
* @param integer $expected_id Expected target ID.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
#[DataProvider('nodaRefForTagsProvider')]
|
||||||
|
public function testGetTagByNodaLinkWorks(MDNodaLink $link, int $expected_id):void {
|
||||||
|
|
||||||
|
self::assertEquals($expected_id, NodaIDGetter::getTagIDByNodaLink($this->_mysqli, $link));
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,10 @@ declare(strict_types = 1);
|
||||||
__DIR__ . '/../../MDErrorReporter/exceptions/generic',
|
__DIR__ . '/../../MDErrorReporter/exceptions/generic',
|
||||||
__DIR__ . '/../../MDErrorReporter/exceptions/updates',
|
__DIR__ . '/../../MDErrorReporter/exceptions/updates',
|
||||||
__DIR__ . '/../../MDMysqli/src',
|
__DIR__ . '/../../MDMysqli/src',
|
||||||
|
__DIR__ . '/../../MDAllowedValueSets/src',
|
||||||
|
__DIR__ . '/../../MDAllowedValueSets/src/classes',
|
||||||
|
__DIR__ . '/../../MDAllowedValueSets/src/enums',
|
||||||
|
__DIR__ . '/../../MDAllowedValueSets/exceptions',
|
||||||
__DIR__ . '/../../MDMysqli/exceptions',
|
__DIR__ . '/../../MDMysqli/exceptions',
|
||||||
]) as $classDir) {
|
]) as $classDir) {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user