From f34c48d0b95d1868295765752327579c1713d66b Mon Sep 17 00:00:00 2001 From: Mauro Cassani Date: Fri, 20 Aug 2021 15:19:22 +0200 Subject: [PATCH] Fix handling for with no dataRef attribute --- src/Filters/DataRefReplace.php | 21 +++++++++++++++------ tests/MateCatSubFilteringTest.php | 20 ++++++++++++++++++++ 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/src/Filters/DataRefReplace.php b/src/Filters/DataRefReplace.php index 8834a94..9db8bdf 100644 --- a/src/Filters/DataRefReplace.php +++ b/src/Filters/DataRefReplace.php @@ -94,12 +94,21 @@ private function isAPhTagWithNoDataRefCorrespondence($phTag) { $parsed = HtmlParser::parse($phTag); - return ( - isset($parsed[0]) and - isset($parsed[0]->attributes['dataRef']) and - !isset($parsed[0]->attributes['equiv-text']) and - !array_key_exists($parsed[0]->attributes['dataRef'], $this->dataRefMap - )); + if(!isset($parsed[0])){ + return false; + } + + // if has equiv-text don't touch + if(isset($parsed[0]->attributes['equiv-text'])){ + return false; + } + + // if has dataRef attribute check if there is correspondence on dataRef map + if(isset($parsed[0]->attributes['dataRef'])){ + return !array_key_exists($parsed[0]->attributes['dataRef'], $this->dataRefMap); + } + + return true; } /** diff --git a/tests/MateCatSubFilteringTest.php b/tests/MateCatSubFilteringTest.php index 691a13c..c643eb4 100644 --- a/tests/MateCatSubFilteringTest.php +++ b/tests/MateCatSubFilteringTest.php @@ -659,4 +659,24 @@ public function testHtmlStringsWithDataTypeAttribute() $this->assertEquals($back_to_db_segment, $db_segment); } + + public function testPhTagsWithoutDataRef() + { + $Filter = MateCatFilter::getInstance( new FeatureSet(), 'en-EN','et-ET', [] ); + + //dataRef="source1" + $db_segment = ''; + $expected_l1_segment = ''; + $expected_l2_segment = '<ph id="mtc_ph_u_1" equiv-text="base64:Jmx0O3BoIGlkPSIxaiIgdHlwZT0ib3RoZXIiIHN1YlR5cGU9Im06aiIvJmd0Ow=="/>'; + + $l1_segment = $Filter->fromLayer0ToLayer1( $db_segment ); + $l2_segment = $Filter->fromLayer1ToLayer2( $l1_segment ); + + $this->assertEquals($l1_segment, $expected_l1_segment); + $this->assertEquals($l2_segment, $expected_l2_segment); + + $back_to_db_segment = $Filter->fromLayer1ToLayer0($l1_segment); + + $this->assertEquals($back_to_db_segment, $db_segment); + } } \ No newline at end of file