*/ 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(\NodaUncertaintyHelper::class)] final class NodaUncertaintyHelperTest extends TestCase { /** * Returns time names with expected cleaned version and expected parsed certainty. * * @return array */ public static function uncertainTimesProvider():array { return [ 'uncertainty prefix: "wohl 1950"' => ["wohl 1950", "1950", false], 'uncertainty suffix: "1950?"' => ["1950?", "1950", false], 'uncertainty suffix and superfluous chars: "1950 ?,"' => ["1950 ?,", "1950", false], 'certain term with superfluous chars: "1950 ,"' => ["1950 ,", "1950", true], 'certain term: 1950' => ["1950", "1950", true], ]; } /** * Returns place names with expected cleaned version and expected parsed certainty. * * @return array */ public static function uncertainPlacesProvider():array { return [ 'uncertainty prefix: "wohl Berlin"' => ["wohl Berlin", "Berlin", false], 'uncertainty prefix: "vermutl. Berlin"' => ["vermutl. Berlin", "Berlin", false], 'uncertainty prefix and superfluous chars: "?-Berlin"' => ["?-Berlin", "Berlin", false], 'uncertainty suffix: "Berlin?"' => ["Berlin?", "Berlin", false], 'uncertainty suffix: "Berlin (?)"' => ["Berlin (?)", "Berlin", false], 'uncertainty suffix and superfluous chars: "Berlin ?,"' => ["Berlin ?,", "Berlin", false], 'certain term with superfluous chars: "Berlin ,"' => ["Berlin ,", "Berlin", true], 'certain term: Berlin' => ["Berlin", "Berlin", true], 'Berlin ? (Deutschland)' => ["Berlin ? (Deutschland)", "Berlin (Deutschland)", false], 'Berli?n (Deutschland)' => ["Berl?n (Deutschland)", "Berl?n (Deutschland)", true], ]; } /** * Returns actor names with expected cleaned version and expected parsed certainty. * * @return array */ public static function uncertainPersinstProvider():array { return [ 'uncertainty prefix: "wohl Barbarossa"' => ["wohl Barbarossa", "Barbarossa", false], 'uncertainty prefix: "vermutl. Barbarossa"' => ["vermutl. Barbarossa", "Barbarossa", false], 'uncertainty prefix and superfluous chars: "?-Barbarossa"' => ["?-Barbarossa", "Barbarossa", false], 'uncertainty suffix: "Barbarossa?"' => ["Barbarossa?", "Barbarossa", false], 'uncertainty suffix and superfluous chars: "Barbarossa ?,"' => ["Barbarossa ?,", "Barbarossa", false], 'certain term with superfluous chars: "Barbarossa ,"' => ["Barbarossa ,", "Barbarossa", true], 'certain term: Barbarossa' => ["Barbarossa", "Barbarossa", true], ]; } /** * Test to ensure times are correctly cleaned and parsed. * * @param string $term Term to check. * @param string $target_output Expected output name. * @param boolean $target_certainty Expected output certainty. * * @return void */ #[DataProvider('uncertainTimesProvider')] public function testParsingUncertaintyFromTimes(string $term, string $target_output, bool $target_certainty):void { self::assertEquals($target_output, NodaUncertaintyHelper::cleanUncertaintyIndicatorsTime($term)); self::assertEquals($target_certainty, NodaUncertaintyHelper::guessTimeCertainty($term)); } /** * Test to ensure places are correctly cleaned and parsed. * * @param string $term Term to check. * @param string $target_output Expected output name. * @param boolean $target_certainty Expected output certainty. * * @return void */ #[DataProvider('uncertainPlacesProvider')] public function testParsingUncertaintyFromPlaces(string $term, string $target_output, bool $target_certainty):void { self::assertEquals($target_output, NodaUncertaintyHelper::cleanUncertaintyIndicatorsPlace($term)); self::assertEquals($target_certainty, NodaUncertaintyHelper::guessPlaceCertainty($term)); } /** * Test to ensure actor names are correctly cleaned and parsed. * * @param string $term Term to check. * @param string $target_output Expected output name. * @param boolean $target_certainty Expected output certainty. * * @return void */ #[DataProvider('uncertainPersinstProvider')] public function testParsingUncertaintyFromPersinst(string $term, string $target_output, bool $target_certainty):void { self::assertEquals($target_output, NodaUncertaintyHelper::cleanUncertaintyIndicatorsPersinst($term)); self::assertEquals($target_certainty, NodaUncertaintyHelper::guessPersinstCertainty($term)); } }