Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsgiehl <stefan@piwik.org>2013-08-31 20:05:42 +0400
committersgiehl <stefan@piwik.org>2013-09-04 02:15:15 +0400
commit53f0ec193131d0a30721f465179aa8737a720e98 (patch)
tree195154b7865243a06b7f2fbf72e465668b2b5c6d
parent838ca1b9392e72decf6cd23751633f8adaf07243 (diff)
moved clean method to Translate instead of TranslationWriter
-rw-r--r--core/Translate.php11
-rw-r--r--core/Translate/Filter/EncodedEntities.php4
-rw-r--r--plugins/Goals/Goals.php4
-rw-r--r--tests/PHPUnit/Core/TranslateTest.php43
4 files changed, 58 insertions, 4 deletions
diff --git a/core/Translate.php b/core/Translate.php
index 5348c1a1b3..09d9734da6 100644
--- a/core/Translate.php
+++ b/core/Translate.php
@@ -33,6 +33,17 @@ class Translate
return self::$instance;
}
+ /**
+ * Clean a string that may contain HTML special chars, single/double quotes, HTML entities, leading/trailing whitespace
+ *
+ * @param string $s
+ * @return string
+ */
+ static public function clean($s)
+ {
+ return html_entity_decode(trim($s), ENT_QUOTES, 'UTF-8');
+ }
+
public function loadEnglishTranslation()
{
$this->loadCoreTranslationFile('en');
diff --git a/core/Translate/Filter/EncodedEntities.php b/core/Translate/Filter/EncodedEntities.php
index 5b0c4ee5c7..4a8b757c1f 100644
--- a/core/Translate/Filter/EncodedEntities.php
+++ b/core/Translate/Filter/EncodedEntities.php
@@ -12,7 +12,7 @@
namespace Piwik\Translate\Filter;
use Piwik\Translate\Filter\FilterAbstract;
-use Piwik\TranslationWriter;
+use Piwik\Translate;
/**
* @package Piwik
@@ -34,7 +34,7 @@ class EncodedEntities extends FilterAbstract
foreach ($pluginTranslations AS $key => $translation) {
// remove encoded entities
- $decoded = TranslationWriter::clean($translation);
+ $decoded = Translate::clean($translation);
if ($translation != $decoded) {
$this->_filteredData[$pluginName][$key] = $translation;
$translations[$pluginName][$key] = $decoded;
diff --git a/plugins/Goals/Goals.php b/plugins/Goals/Goals.php
index f15569affb..efc8582685 100644
--- a/plugins/Goals/Goals.php
+++ b/plugins/Goals/Goals.php
@@ -16,7 +16,7 @@ use Piwik\Common;
use Piwik\Plugins\Goals\API;
use Piwik\Plugins\Goals\Archiver;
use Piwik\Tracker\GoalManager;
-use Piwik\TranslationWriter;
+use Piwik\Translate;
use Piwik\Site;
use Piwik\WidgetsList;
use Piwik\Db;
@@ -471,7 +471,7 @@ class Goals extends \Piwik\Plugin
}
Piwik_AddMenu($mainGoalMenu, 'Goals_GoalsOverview', array('module' => 'Goals', 'action' => 'index'), true, 2);
foreach ($goals as $goal) {
- Piwik_AddMenu($mainGoalMenu, str_replace('%', '%%', TranslationWriter::clean($goal['name'])), array('module' => 'Goals', 'action' => 'goalReport', 'idGoal' => $goal['idgoal']));
+ Piwik_AddMenu($mainGoalMenu, str_replace('%', '%%', Translate::clean($goal['name'])), array('module' => 'Goals', 'action' => 'goalReport', 'idGoal' => $goal['idgoal']));
}
}
}
diff --git a/tests/PHPUnit/Core/TranslateTest.php b/tests/PHPUnit/Core/TranslateTest.php
new file mode 100644
index 0000000000..3acc545f77
--- /dev/null
+++ b/tests/PHPUnit/Core/TranslateTest.php
@@ -0,0 +1,43 @@
+<?php
+use Piwik\Common;
+use Piwik\Translate;
+
+/**
+ * Piwik - Open source web analytics
+ *
+ * @link http://piwik.org
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
+ */
+class TranslateTest extends PHPUnit_Framework_TestCase
+{
+ /**
+ * Dataprovider for testClean
+ */
+ public function getCleanTestData()
+ {
+ return array(
+ // empty string
+ array("", ''),
+ // newline
+ array("\n", ''),
+ // leading and trailing whitespace
+ array(" a \n", 'a'),
+ // single / double quotes
+ array(" &quot;it&#039;s&quot; ", '"it\'s"'),
+ // html special characters
+ array("&lt;tag&gt;", '<tag>'),
+ // other html entities
+ array("&hellip;", '…'),
+ );
+ }
+
+ /**
+ * @group Core
+ * @group Translate
+ * @dataProvider getCleanTestData
+ */
+ public function testClean($data, $expected)
+ {
+ $this->assertEquals($expected, Translate::clean($data));
+ }
+} \ No newline at end of file