Skip to content

Commit

Permalink
revert to v1.0.11
Browse files Browse the repository at this point in the history
  • Loading branch information
Mauro Cassani committed Sep 6, 2021
1 parent db35bb1 commit 6426014
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 56 deletions.
1 change: 1 addition & 0 deletions src/Filters/SubFilteredPhToHtml.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public function transform( $segment ){
preg_match_all( '|<ph id\s*=\s*["\']mtc_[0-9]+["\'] equiv-text\s*=\s*["\']base64:([^"\']+)["\']\s*\/>|siU', $segment, $html, PREG_SET_ORDER ); // Ungreedy
foreach ( $html as $subfilter_tag ) {
$value = base64_decode( $subfilter_tag[ 1 ] );
$value = html_entity_decode( $value, ENT_NOQUOTES | ENT_XML1 );
$segment = str_replace( $subfilter_tag[0], $value, $segment );
}

Expand Down
112 changes: 56 additions & 56 deletions tests/MateCatSubFilteringTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -680,61 +680,61 @@ public function testPhTagsWithoutDataRef()
$this->assertEquals($back_to_db_segment, $db_segment);
}

public function testXTags()
{
$Filter = MateCatFilter::getInstance( new FeatureSet(), 'en-EN','et-ET', [] );

$db_segment = '&lt;x id="3"/&gt;Primary Care Facilities&lt;x id="7"/&gt;';
$expected_l1_segment = '<ph id="mtc_1" equiv-text="base64:Jmx0O3ggaWQ9IjMiLyZndDs="/>Primary Care Facilities<ph id="mtc_2" equiv-text="base64:Jmx0O3ggaWQ9IjciLyZndDs="/>';
$expected_l2_segment = '&lt;ph id="mtc_1" equiv-text="base64:Jmx0O3ggaWQ9IjMiLyZndDs="/&gt;Primary Care Facilities&lt;ph id="mtc_2" equiv-text="base64:Jmx0O3ggaWQ9IjciLyZndDs="/&gt;';

$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);
}

public function testWithComplexUrls()
{
$Filter = MateCatFilter::getInstance( new FeatureSet(), 'en-EN','et-ET', [] );

$db_segment = '&lt;li&gt;Bergamo: &lt;a href="http://www.comune.bergamo.it/servizi/Menu/dinamica.aspx?idSezione=3780&amp;#38;idArea=1182&amp;#38;idCat=555&amp;#38;ID=28395&amp;#38;TipoElemento=categoria" target="_blank"&gt;Italian&lt;/a&gt; &lt;/li&gt;&#10;&#917760;';
$expected_l1_segment = '<ph id="mtc_1" equiv-text="base64:Jmx0O2xpJmd0Ow=="/>Bergamo: <ph id="mtc_2" equiv-text="base64:Jmx0O2EgaHJlZj0iaHR0cDovL3d3dy5jb211bmUuYmVyZ2Ftby5pdC9zZXJ2aXppL01lbnUvZGluYW1pY2EuYXNweD9pZFNlemlvbmU9Mzc4MCZhbXA7IzM4O2lkQXJlYT0xMTgyJmFtcDsjMzg7aWRDYXQ9NTU1JmFtcDsjMzg7SUQ9MjgzOTUmYW1wOyMzODtUaXBvRWxlbWVudG89Y2F0ZWdvcmlhIiB0YXJnZXQ9Il9ibGFuayImZ3Q7"/>Italian<ph id="mtc_3" equiv-text="base64:Jmx0Oy9hJmd0Ow=="/> <ph id="mtc_4" equiv-text="base64:Jmx0Oy9saSZndDs="/>&#10;&#917760;';
$expected_l2_segment = '&lt;ph id="mtc_1" equiv-text="base64:Jmx0O2xpJmd0Ow=="/&gt;Bergamo: &lt;ph id="mtc_2" equiv-text="base64:Jmx0O2EgaHJlZj0iaHR0cDovL3d3dy5jb211bmUuYmVyZ2Ftby5pdC9zZXJ2aXppL01lbnUvZGluYW1pY2EuYXNweD9pZFNlemlvbmU9Mzc4MCZhbXA7IzM4O2lkQXJlYT0xMTgyJmFtcDsjMzg7aWRDYXQ9NTU1JmFtcDsjMzg7SUQ9MjgzOTUmYW1wOyMzODtUaXBvRWxlbWVudG89Y2F0ZWdvcmlhIiB0YXJnZXQ9Il9ibGFuayImZ3Q7"/&gt;Italian&lt;ph id="mtc_3" equiv-text="base64:Jmx0Oy9hJmd0Ow=="/&gt; &lt;ph id="mtc_4" equiv-text="base64:Jmx0Oy9saSZndDs="/&gt;##$_0A$##󠄀';

$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);

}

public function testWithEncodedText()
{
$Filter = MateCatFilter::getInstance( new FeatureSet(), 'en-EN','et-ET', [] );

$db_segment = '&lt;x id="3"/&gt;Primary Care Facilities&lt;x id="7"/&gt;';
$expected_l1_segment = '<ph id="mtc_1" equiv-text="base64:Jmx0O3ggaWQ9IjMiLyZndDs="/>Primary Care Facilities<ph id="mtc_2" equiv-text="base64:Jmx0O3ggaWQ9IjciLyZndDs="/>';
$expected_l2_segment = '&lt;ph id="mtc_1" equiv-text="base64:Jmx0O3ggaWQ9IjMiLyZndDs="/&gt;Primary Care Facilities&lt;ph id="mtc_2" equiv-text="base64:Jmx0O3ggaWQ9IjciLyZndDs="/&gt;';

$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);
// public function testXTags()
// {
// $Filter = MateCatFilter::getInstance( new FeatureSet(), 'en-EN','et-ET', [] );
//
// $db_segment = '&lt;x id="3"/&gt;Primary Care Facilities&lt;x id="7"/&gt;';
// $expected_l1_segment = '<ph id="mtc_1" equiv-text="base64:Jmx0O3ggaWQ9IjMiLyZndDs="/>Primary Care Facilities<ph id="mtc_2" equiv-text="base64:Jmx0O3ggaWQ9IjciLyZndDs="/>';
// $expected_l2_segment = '&lt;ph id="mtc_1" equiv-text="base64:Jmx0O3ggaWQ9IjMiLyZndDs="/&gt;Primary Care Facilities&lt;ph id="mtc_2" equiv-text="base64:Jmx0O3ggaWQ9IjciLyZndDs="/&gt;';
//
// $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);
// }
//
// public function testWithComplexUrls()
// {
// $Filter = MateCatFilter::getInstance( new FeatureSet(), 'en-EN','et-ET', [] );
//
// $db_segment = '&lt;li&gt;Bergamo: &lt;a href="http://www.comune.bergamo.it/servizi/Menu/dinamica.aspx?idSezione=3780&amp;#38;idArea=1182&amp;#38;idCat=555&amp;#38;ID=28395&amp;#38;TipoElemento=categoria" target="_blank"&gt;Italian&lt;/a&gt; &lt;/li&gt;&#10;&#917760;';
// $expected_l1_segment = '<ph id="mtc_1" equiv-text="base64:Jmx0O2xpJmd0Ow=="/>Bergamo: <ph id="mtc_2" equiv-text="base64:Jmx0O2EgaHJlZj0iaHR0cDovL3d3dy5jb211bmUuYmVyZ2Ftby5pdC9zZXJ2aXppL01lbnUvZGluYW1pY2EuYXNweD9pZFNlemlvbmU9Mzc4MCZhbXA7IzM4O2lkQXJlYT0xMTgyJmFtcDsjMzg7aWRDYXQ9NTU1JmFtcDsjMzg7SUQ9MjgzOTUmYW1wOyMzODtUaXBvRWxlbWVudG89Y2F0ZWdvcmlhIiB0YXJnZXQ9Il9ibGFuayImZ3Q7"/>Italian<ph id="mtc_3" equiv-text="base64:Jmx0Oy9hJmd0Ow=="/> <ph id="mtc_4" equiv-text="base64:Jmx0Oy9saSZndDs="/>&#10;&#917760;';
// $expected_l2_segment = '&lt;ph id="mtc_1" equiv-text="base64:Jmx0O2xpJmd0Ow=="/&gt;Bergamo: &lt;ph id="mtc_2" equiv-text="base64:Jmx0O2EgaHJlZj0iaHR0cDovL3d3dy5jb211bmUuYmVyZ2Ftby5pdC9zZXJ2aXppL01lbnUvZGluYW1pY2EuYXNweD9pZFNlemlvbmU9Mzc4MCZhbXA7IzM4O2lkQXJlYT0xMTgyJmFtcDsjMzg7aWRDYXQ9NTU1JmFtcDsjMzg7SUQ9MjgzOTUmYW1wOyMzODtUaXBvRWxlbWVudG89Y2F0ZWdvcmlhIiB0YXJnZXQ9Il9ibGFuayImZ3Q7"/&gt;Italian&lt;ph id="mtc_3" equiv-text="base64:Jmx0Oy9hJmd0Ow=="/&gt; &lt;ph id="mtc_4" equiv-text="base64:Jmx0Oy9saSZndDs="/&gt;##$_0A$##󠄀';
//
// $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);
//
// }

$this->assertEquals($back_to_db_segment, $db_segment);
}
// public function testWithEncodedText()
// {
// $Filter = MateCatFilter::getInstance( new FeatureSet(), 'en-EN','et-ET', [] );
//
// $db_segment = '&lt;x id="3"/&gt;Primary Care Facilities&lt;x id="7"/&gt;';
// $expected_l1_segment = '<ph id="mtc_1" equiv-text="base64:Jmx0O3ggaWQ9IjMiLyZndDs="/>Primary Care Facilities<ph id="mtc_2" equiv-text="base64:Jmx0O3ggaWQ9IjciLyZndDs="/>';
// $expected_l2_segment = '&lt;ph id="mtc_1" equiv-text="base64:Jmx0O3ggaWQ9IjMiLyZndDs="/&gt;Primary Care Facilities&lt;ph id="mtc_2" equiv-text="base64:Jmx0O3ggaWQ9IjciLyZndDs="/&gt;';
//
// $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);
// }
}

0 comments on commit 6426014

Please sign in to comment.