Skip to content
Extraits de code Groupes Projets
Valider 8b01230f rédigé par sgiehl's avatar sgiehl
Parcourir les fichiers

added translations filter to filter encoded entities

parent b5caa5e2
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
<?php
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
* @category Piwik
* @package Piwik
*/
namespace Piwik\Translate\Filter;
use Piwik\Translate\Filter\FilterAbstract;
use Piwik\TranslationWriter;
/**
* @package Piwik
* @subpackage Piwik_Translate
*/
class EncodedEntities extends FilterAbstract
{
/**
* Filter the given translations
*
* @param array $translations
*
* @return array filtered translations
*
*/
public function filter($translations)
{
foreach ($translations AS $pluginName => $pluginTranslations) {
foreach ($pluginTranslations AS $key => $translation) {
// remove encoded entities
$decoded = TranslationWriter::clean($translation);
if ($translation != $decoded) {
$this->_filteredData[$pluginName][$key] = $translation;
$translations[$pluginName][$key] = $decoded;
continue;
}
}
}
return $translations;
}
}
\ No newline at end of file
<?php
use Piwik\Translate\Filter\EncodedEntities;
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
class EncodedEntitiesTest extends PHPUnit_Framework_TestCase
{
public function getFilterTestData()
{
return array(
// empty stays empty - nothing to filter
array(
array(),
array(),
array()
),
// empty plugin is removed
array(
array(
'test' => array()
),
array(
'test' => array()
),
array(),
),
// no entites - nothing to filter
array(
array(
'test' => array(
'key' => 'val%sue',
'test' => 'test'
)
),
array(
'test' => array(
'key' => 'val%sue',
'test' => 'test'
)
),
array(),
),
// entities needs to be decodded
array(
array(
'test' => array(
'test' => 'te&amp;st'
)
),
array(
'test' => array(
'test' => 'te&st'
)
),
array(
'test' => array(
'test' => 'te&amp;st'
)
),
),
array(
array(
'empty' => array(
'test' => 't&uuml;sest'
),
'test' => array(
'test' => '%1$stest',
'empty' => '&tilde;',
)
),
array(
'empty' => array(
'test' => 'tüsest'
),
'test' => array(
'test' => '%1$stest',
'empty' => '˜',
)
),
array(
'empty' => array(
'test' => 't&uuml;sest'
),
'test' => array(
'empty' => '&tilde;',
)
),
),
);
}
/**
* @dataProvider getFilterTestData
* @group Core
* @group Translate
*/
public function testFilter($translations, $expected, $filteredData)
{
$filter = new EncodedEntities();
$result = $filter->filter($translations);
$this->assertEquals($expected, $result);
$this->assertEquals($filteredData, $filter->getFilteredData());
}
}
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter