MDNodaHelpers/tests/NodaTagRelationIdentifierTest.php

51 lines
1.7 KiB
PHP
Raw Permalink Normal View History

<?PHP
/**
* Tests for the identification of tag relation types to objects based on input tag names.
*
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
*/
declare(strict_types = 1);
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Small;
use PHPUnit\Framework\Attributes\DataProvider;
/**
* This script contains tests for the uncertainty helper.
*/
#[small]
#[CoversClass(\NodaTagRelationIdentifier::class)]
final class NodaTagRelationIdentifierTest extends TestCase {
/**
* Returns input tag names with and without known suffixes signaling the relation type.
*
* @return array<array{0: string, 1: string, 2: false|MDTagRelationType}>
*/
public static function tagNameAndRelationTypeProvider():array {
return [
'Delfin' => ["Delfin", "Delfin", false],
'Delfin (Motiv)' => ["Delfin (Motiv)", "Delfin", MDTagRelationType::display_subject],
];
}
/**
* Test to ensure times are correctly cleaned and parsed.
*
* @param string $term Term to check.
* @param string $target_output Expected output name.
* @param false|MDTagRelationType $target_type Expected identified relation type (or false for lack thereof).
*
* @return void
*/
#[DataProvider('tagNameAndRelationTypeProvider')]
public function testIdentificationWorksCorrectly(string $term, string $target_output, false|MDTagRelationType $target_type):void {
$identification = new NodaTagRelationIdentifier("de", $term);
self::assertEquals($target_output, $identification->name);
self::assertEquals($target_type, $identification->relation);
}
}