diff options
author | sgiehl <stefan@piwik.org> | 2013-08-30 20:46:42 +0400 |
---|---|---|
committer | sgiehl <stefan@piwik.org> | 2013-09-04 02:15:15 +0400 |
commit | 236f0379ba878604441d24ba2ea03cc324260919 (patch) | |
tree | 90d7f5a5c2c4dcd623d9be78507b3ae5e6fcc288 /tests | |
parent | 8b01230fc5f0424e2dc8721c29737f7f4b25498c (diff) |
added translation validators
Diffstat (limited to 'tests')
-rw-r--r-- | tests/PHPUnit/Core/Translate/Validate/BaseTranslationsTest.php | 138 | ||||
-rw-r--r-- | tests/PHPUnit/Core/Translate/Validate/NoScriptsTest.php | 109 |
2 files changed, 247 insertions, 0 deletions
diff --git a/tests/PHPUnit/Core/Translate/Validate/BaseTranslationsTest.php b/tests/PHPUnit/Core/Translate/Validate/BaseTranslationsTest.php new file mode 100644 index 0000000000..d8a89bd140 --- /dev/null +++ b/tests/PHPUnit/Core/Translate/Validate/BaseTranslationsTest.php @@ -0,0 +1,138 @@ +<?php +use Piwik\Translate\Validate\BaseTranslations; + +/** + * Piwik - Open source web analytics + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ +class BaseTranslationsTest extends PHPUnit_Framework_TestCase +{ + public function getFilterTestDataValid() + { + return array( + array( + array( + 'General' => array_merge(array_fill(0, 251, 'test'), array( + 'Locale' => 'de_DE.UTF-8', + 'TranslatorName' => 'name', + 'TranslatorEmail' => 'email', + ) + ) + ), + ) + ); + } + + /** + * @dataProvider getFilterTestDataValid + * @group Core + * @group Translate + */ + public function testFilterValid($translations) + { + $filter = new BaseTranslations(); + $result = $filter->isValid($translations); + $this->assertTrue($result); + } + + public function getFilterTestDataInvalid() + { + return array( + array( + array( + 'General' => array( + 'bla' => 'test text' + ) + ), + BaseTranslations::__ERRORSTATE_MINIMUMTRANSLATIONS__ + ), + array( + array( + 'General' => array_merge(array_fill(0, 251, 'test'), array( + 'bla' => 'test text' + )) + ), + BaseTranslations::__ERRORSTATE_LOCALEREQUIRED__ + ), + array( + array( + 'General' => array_merge(array_fill(0, 251, 'test'), array( + 'Locale' => 'de_DE.UTF-8' + )) + ), + BaseTranslations::__ERRORSTATE_TRANSLATORINFOREQUIRED__ + ), + array( + array( + 'General' => array_merge(array_fill(0, 251, 'test'), array( + 'Locale' => 'de_DE.UTF-8', + 'TranslatorName' => 'name', + )) + ), + BaseTranslations::__ERRORSTATE_TRANSLATOREMAILREQUIRED__ + ), + array( + array( + 'General' => array_merge(array_fill(0, 251, 'test'), array( + 'Locale' => 'de_DE.UTF-8', + 'TranslatorName' => 'name', + 'TranslatorEmail' => 'emails', + 'LayoutDirection' => 'afd' + )) + ), + BaseTranslations::__ERRORSTATE_LAYOUTDIRECTIONINVALID__ + ), + array( + array( + 'General' => array_merge(array_fill(0, 251, 'test'), array( + 'Locale' => 'invalid', + 'TranslatorName' => 'name', + 'TranslatorEmail' => 'emails', + 'LayoutDirection' => 'ltr' + )) + ), + BaseTranslations::__ERRORSTATE_LOCALEINVALID__ + ), + array( + array( + 'General' => array_merge(array_fill(0, 251, 'test'), array( + 'Locale' => 'xx_DE.UTF-8', + 'TranslatorName' => 'name', + 'TranslatorEmail' => 'emails', + 'LayoutDirection' => 'ltr' + )) + ), + BaseTranslations::__ERRORSTATE_LOCALEINVALIDLANGUAGE__ + ), + array( + array( + 'General' => array_merge(array_fill(0, 251, 'test'), array( + 'Locale' => 'de_XX.UTF-8', + 'TranslatorName' => 'name', + 'TranslatorEmail' => 'emails', + 'LayoutDirection' => 'ltr' + )) + ), + BaseTranslations::__ERRORSTATE_LOCALEINVALIDCOUNTRY__ + ), + ); + } + + /** + * @dataProvider getFilterTestDataInvalid + * @group Core + * @group Translate + */ + public function testFilterInvalid($translations, $msg) + { + include PIWIK_INCLUDE_PATH . '/core/DataFiles/Languages.php'; + include PIWIK_INCLUDE_PATH . '/core/DataFiles/Countries.php'; + + $filter = new BaseTranslations(); + $result = $filter->isValid($translations); + $this->assertFalse($result); + $this->assertEquals($msg, $filter->getError()); + } +} diff --git a/tests/PHPUnit/Core/Translate/Validate/NoScriptsTest.php b/tests/PHPUnit/Core/Translate/Validate/NoScriptsTest.php new file mode 100644 index 0000000000..75df78b1fe --- /dev/null +++ b/tests/PHPUnit/Core/Translate/Validate/NoScriptsTest.php @@ -0,0 +1,109 @@ +<?php +use Piwik\Translate\Validate\NoScripts; + +/** + * Piwik - Open source web analytics + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ +class NoScriptsTest extends PHPUnit_Framework_TestCase +{ + public function getFilterTestDataValid() + { + return array( + array( + array(), + ), + array( + array( + 'test' => array() + ), + ), + array( + array( + 'test' => array( + 'key' => 'val%sue', + 'test' => 'test' + ) + ), + ), + ); + } + + /** + * @dataProvider getFilterTestDataValid + * @group Core + * @group Translate + */ + public function testFilterValid($translations) + { + $filter = new NoScripts(); + $result = $filter->isValid($translations); + $this->assertTrue($result); + } + + public function getFilterTestDataInvalid() + { + return array( + array( + array( + 'test' => array( + 'test' => 'test text <script' + ) + ), + ), + array( + array( + 'empty' => array( + 'test' => 'tüsest' + ), + 'test' => array( + 'test' => 'bla <a href="javascript:alert();"> link </a>', + 'empty' => '˜', + ) + ), + ), + array( + array( + 'test' => array( + 'test' => 'bla <a onload="alert();">link</a>' + ) + ), + ), + array( + array( + 'test' => array( + 'test' => 'no <img src="test" />' + ) + ), + ), + array( + array( + 'test' => array( + 'test' => 'that will fail on document. or not?' + ) + ), + ), + array( + array( + 'test' => array( + 'test' => 'bla <a background="yellow">link</a>' + ) + ), + ), + ); + } + + /** + * @dataProvider getFilterTestDataInvalid + * @group Core + * @group Translate + */ + public function testFilterInvalid($translations) + { + $filter = new NoScripts(); + $result = $filter->isValid($translations); + $this->assertFalse($result); + } +} |