update Piwik to version 2.16 (fixes #91)
This commit is contained in:
parent
296343bf3b
commit
d885a4baa9
5833 changed files with 418860 additions and 226988 deletions
|
|
@ -0,0 +1,162 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace Piwik\Plugins\LanguagesManager\Test\Unit\TranslationWriter\Filter;
|
||||
|
||||
use Piwik\Plugins\LanguagesManager\TranslationWriter\Filter\ByBaseTranslations;
|
||||
|
||||
/**
|
||||
* @group LanguagesManager
|
||||
*/
|
||||
class ByBaseTranslationsTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function getFilterTestData()
|
||||
{
|
||||
return array(
|
||||
// empty stays empty
|
||||
array(
|
||||
array(),
|
||||
array(),
|
||||
array(),
|
||||
array()
|
||||
),
|
||||
// empty plugin is removed
|
||||
array(
|
||||
array(
|
||||
'test' => array()
|
||||
),
|
||||
array(),
|
||||
array(),
|
||||
array(
|
||||
'test' => array()
|
||||
),
|
||||
),
|
||||
// not existing values/plugins are removed
|
||||
array(
|
||||
array(
|
||||
'test' => array(
|
||||
'key' => 'value',
|
||||
'test' => 'test'
|
||||
)
|
||||
),
|
||||
array(
|
||||
'test' => array(
|
||||
'key' => 'value',
|
||||
'x' => 'y'
|
||||
)
|
||||
),
|
||||
array(
|
||||
'test' => array(
|
||||
'key' => 'value',
|
||||
)
|
||||
),
|
||||
array(
|
||||
'test' => array(
|
||||
'test' => 'test',
|
||||
)
|
||||
),
|
||||
),
|
||||
// no change if all exist
|
||||
array(
|
||||
array(
|
||||
'test' => array(
|
||||
'test' => 'test'
|
||||
)
|
||||
),
|
||||
array(
|
||||
'test' => array(
|
||||
'test' => 'test'
|
||||
)
|
||||
),
|
||||
array(
|
||||
'test' => array(
|
||||
'test' => 'test'
|
||||
)
|
||||
),
|
||||
array()
|
||||
),
|
||||
// unavailable removed, others stay
|
||||
array(
|
||||
array(
|
||||
'empty' => array(
|
||||
'test' => 'test'
|
||||
),
|
||||
'test' => array(
|
||||
'test' => 'test',
|
||||
'empty' => ' ',
|
||||
)
|
||||
),
|
||||
array(
|
||||
'empty' => array(
|
||||
'test' => 'test'
|
||||
),
|
||||
'test' => array(
|
||||
'test' => 'test',
|
||||
)
|
||||
),
|
||||
array(
|
||||
'empty' => array(
|
||||
'test' => 'test'
|
||||
),
|
||||
'test' => array(
|
||||
'test' => 'test'
|
||||
)
|
||||
),
|
||||
array(
|
||||
'test' => array(
|
||||
'empty' => ' ',
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'empty' => array(
|
||||
'test' => 'test'
|
||||
),
|
||||
'test' => array(
|
||||
'test' => 'test',
|
||||
'empty' => ' ',
|
||||
)
|
||||
),
|
||||
array(
|
||||
'empty' => array(
|
||||
'bla' => 'test'
|
||||
),
|
||||
'test' => array(
|
||||
'test' => 'test',
|
||||
)
|
||||
),
|
||||
array(
|
||||
'test' => array(
|
||||
'test' => 'test'
|
||||
)
|
||||
),
|
||||
array(
|
||||
'empty' => array(
|
||||
'test' => 'test'
|
||||
),
|
||||
'test' => array(
|
||||
'empty' => ' ',
|
||||
)
|
||||
)
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getFilterTestData
|
||||
* @group Core
|
||||
*/
|
||||
public function testFilter($translations, $baseTranslations, $expected, $filteredData)
|
||||
{
|
||||
$filter = new ByBaseTranslations($baseTranslations);
|
||||
$result = $filter->filter($translations);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($filteredData, $filter->getFilteredData());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,121 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace Piwik\Plugins\LanguagesManager\Test\Unit\TranslationWriter\Filter;
|
||||
|
||||
use Piwik\Plugins\LanguagesManager\TranslationWriter\Filter\ByParameterCount;
|
||||
|
||||
/**
|
||||
* @group LanguagesManager
|
||||
*/
|
||||
class ByParameterCountTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function getFilterTestData()
|
||||
{
|
||||
return array(
|
||||
// empty stays empty - nothing to filter
|
||||
array(
|
||||
array(),
|
||||
array(),
|
||||
array(),
|
||||
array()
|
||||
),
|
||||
// empty plugin is removed
|
||||
array(
|
||||
array(
|
||||
'test' => array()
|
||||
),
|
||||
array(),
|
||||
array(),
|
||||
array(),
|
||||
),
|
||||
// value with %s will be removed, as it isn't there in base
|
||||
array(
|
||||
array(
|
||||
'test' => array(
|
||||
'key' => 'val%sue',
|
||||
'test' => 'test'
|
||||
)
|
||||
),
|
||||
array(
|
||||
'test' => array(
|
||||
'key' => 'value',
|
||||
)
|
||||
),
|
||||
array(),
|
||||
array(
|
||||
'test' => array(
|
||||
'key' => 'val%sue',
|
||||
)
|
||||
),
|
||||
),
|
||||
// no change if placeholder count is the same
|
||||
array(
|
||||
array(
|
||||
'test' => array(
|
||||
'test' => 'te%sst'
|
||||
)
|
||||
),
|
||||
array(
|
||||
'test' => array(
|
||||
'test' => 'test%s'
|
||||
)
|
||||
),
|
||||
array(
|
||||
'test' => array(
|
||||
'test' => 'te%sst'
|
||||
)
|
||||
),
|
||||
array()
|
||||
),
|
||||
// missing placeholder will be removed
|
||||
array(
|
||||
array(
|
||||
'empty' => array(
|
||||
'test' => 't%1$sest'
|
||||
),
|
||||
'test' => array(
|
||||
'test' => '%1$stest',
|
||||
'empty' => ' ',
|
||||
)
|
||||
),
|
||||
array(
|
||||
'empty' => array(
|
||||
'test' => 'test%1$s'
|
||||
),
|
||||
'test' => array(
|
||||
'test' => '%1$stest%2$s',
|
||||
)
|
||||
),
|
||||
array(
|
||||
'empty' => array(
|
||||
'test' => 't%1$sest'
|
||||
),
|
||||
),
|
||||
array(
|
||||
'test' => array(
|
||||
'test' => '%1$stest',
|
||||
)
|
||||
)
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getFilterTestData
|
||||
* @group Core
|
||||
*/
|
||||
public function testFilter($translations, $baseTranslations, $expected, $filteredData)
|
||||
{
|
||||
$filter = new ByParameterCount($baseTranslations);
|
||||
$result = $filter->filter($translations);
|
||||
$message = sprintf("got %s but expected %s", var_export($result, true), var_export($expected, true));
|
||||
$this->assertEquals($expected, $result, $message);
|
||||
$this->assertEquals($filteredData, $filter->getFilteredData());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,99 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace Piwik\Plugins\LanguagesManager\Test\Unit\TranslationWriter\Filter;
|
||||
|
||||
use Piwik\Plugins\LanguagesManager\TranslationWriter\Filter\EmptyTranslations;
|
||||
|
||||
/**
|
||||
* @group LanguagesManager
|
||||
*/
|
||||
class EmptyTranslationsTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function getFilterTestData()
|
||||
{
|
||||
return array(
|
||||
// empty stays empty
|
||||
array(
|
||||
array(),
|
||||
array(),
|
||||
array()
|
||||
),
|
||||
// empty plugin is removed
|
||||
array(
|
||||
array(
|
||||
'test' => array()
|
||||
),
|
||||
array(),
|
||||
array(),
|
||||
),
|
||||
// empty values/plugins are removed
|
||||
array(
|
||||
array(
|
||||
'test' => array(
|
||||
'empty' => '',
|
||||
'whitespace' => ' '
|
||||
)
|
||||
),
|
||||
array(),
|
||||
array(
|
||||
'test' => array(
|
||||
'empty' => '',
|
||||
'whitespace' => ' '
|
||||
)
|
||||
),
|
||||
),
|
||||
// no change if no empty value
|
||||
array(
|
||||
array(
|
||||
'test' => array(
|
||||
'test' => 'test'
|
||||
)
|
||||
),
|
||||
array(
|
||||
'test' => array(
|
||||
'test' => 'test'
|
||||
)
|
||||
),
|
||||
array()
|
||||
),
|
||||
// empty values are removed, others stay
|
||||
array(
|
||||
array(
|
||||
'empty' => array(),
|
||||
'test' => array(
|
||||
'test' => 'test',
|
||||
'empty' => ' ',
|
||||
)
|
||||
),
|
||||
array(
|
||||
'test' => array(
|
||||
'test' => 'test'
|
||||
)
|
||||
),
|
||||
array(
|
||||
'test' => array(
|
||||
'empty' => ' ',
|
||||
)
|
||||
)
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getFilterTestData
|
||||
* @group Core
|
||||
*/
|
||||
public function testFilter($translations, $expected, $filteredData)
|
||||
{
|
||||
$filter = new EmptyTranslations();
|
||||
$result = $filter->filter($translations);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($filteredData, $filter->getFilteredData());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,113 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace Piwik\Plugins\LanguagesManager\Test\Unit\TranslationWriter\Filter;
|
||||
|
||||
use Piwik\Plugins\LanguagesManager\TranslationWriter\Filter\EncodedEntities;
|
||||
|
||||
/**
|
||||
* @group LanguagesManager
|
||||
*/
|
||||
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&st'
|
||||
)
|
||||
),
|
||||
array(
|
||||
'test' => array(
|
||||
'test' => 'te&st'
|
||||
)
|
||||
),
|
||||
array(
|
||||
'test' => array(
|
||||
'test' => 'te&st'
|
||||
)
|
||||
),
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'empty' => array(
|
||||
'test' => 'tüsest'
|
||||
),
|
||||
'test' => array(
|
||||
'test' => '%1$stest',
|
||||
'empty' => '˜',
|
||||
)
|
||||
),
|
||||
array(
|
||||
'empty' => array(
|
||||
'test' => 'tüsest'
|
||||
),
|
||||
'test' => array(
|
||||
'test' => '%1$stest',
|
||||
'empty' => '˜',
|
||||
)
|
||||
),
|
||||
array(
|
||||
'empty' => array(
|
||||
'test' => 'tüsest'
|
||||
),
|
||||
'test' => array(
|
||||
'empty' => '˜',
|
||||
)
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getFilterTestData
|
||||
* @group Core
|
||||
*/
|
||||
public function testFilter($translations, $expected, $filteredData)
|
||||
{
|
||||
$filter = new EncodedEntities();
|
||||
$result = $filter->filter($translations);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($filteredData, $filter->getFilteredData());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,158 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace Piwik\Plugins\LanguagesManager\Test\Unit\TranslationWriter\Filter;
|
||||
|
||||
use Piwik\Plugins\LanguagesManager\TranslationWriter\Filter\UnnecassaryWhitespaces;
|
||||
|
||||
/**
|
||||
* @group LanguagesManager
|
||||
*/
|
||||
class UnnecassaryWhitepsacesTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function getFilterTestData()
|
||||
{
|
||||
return array(
|
||||
// empty stays empty - nothing to filter
|
||||
array(
|
||||
array(),
|
||||
array(),
|
||||
array(),
|
||||
array()
|
||||
),
|
||||
// no entites - nothing to filter
|
||||
array(
|
||||
array(
|
||||
'test' => array(
|
||||
'key' => "val\n\n\r\n\nue",
|
||||
'test' => 'test'
|
||||
)
|
||||
),
|
||||
array(
|
||||
'test' => array(
|
||||
'key' => "base val\n\nue",
|
||||
'test' => 'test'
|
||||
)
|
||||
),
|
||||
array(
|
||||
'test' => array(
|
||||
'key' => "val\n\nue",
|
||||
'test' => 'test'
|
||||
)
|
||||
),
|
||||
array(
|
||||
'test' => array(
|
||||
'key' => "val\n\n\r\n\nue",
|
||||
)
|
||||
|
||||
),
|
||||
),
|
||||
// entities needs to be decodded
|
||||
array(
|
||||
array(
|
||||
'test' => array(
|
||||
'test' => 'test palim'
|
||||
)
|
||||
),
|
||||
array(
|
||||
'test' => array(
|
||||
'test' => 'no line breaks'
|
||||
)
|
||||
),
|
||||
array(
|
||||
'test' => array(
|
||||
'test' => 'test palim'
|
||||
)
|
||||
),
|
||||
array(
|
||||
'test' => array(
|
||||
'test' => 'test palim'
|
||||
)
|
||||
),
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'empty' => array(
|
||||
'test' => "test\n\n\ntest"
|
||||
),
|
||||
),
|
||||
array(
|
||||
'empty' => array(
|
||||
'test' => 'no line break'
|
||||
),
|
||||
),
|
||||
array(
|
||||
'empty' => array(
|
||||
'test' => 'test test'
|
||||
),
|
||||
),
|
||||
array(
|
||||
'empty' => array(
|
||||
'test' => "test\n\n\ntest"
|
||||
),
|
||||
),
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'empty' => array(
|
||||
'test' => "test\n \n\n test"
|
||||
),
|
||||
),
|
||||
array(
|
||||
'empty' => array(
|
||||
'test' => 'no line break'
|
||||
),
|
||||
),
|
||||
array(
|
||||
'empty' => array(
|
||||
'test' => 'test test'
|
||||
),
|
||||
),
|
||||
array(
|
||||
'empty' => array(
|
||||
'test' => "test\n \n\n test"
|
||||
),
|
||||
),
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'empty' => array(
|
||||
'test' => "test\n \n\n test"
|
||||
),
|
||||
),
|
||||
array(
|
||||
'empty' => array(
|
||||
'test' => "line\n break"
|
||||
),
|
||||
),
|
||||
array(
|
||||
'empty' => array(
|
||||
'test' => "test\n\ntest"
|
||||
),
|
||||
),
|
||||
array(
|
||||
'empty' => array(
|
||||
'test' => "test\n \n\n test"
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getFilterTestData
|
||||
* @group Core
|
||||
*/
|
||||
public function testFilter($translations, $baseTranslations, $expected, $filteredData)
|
||||
{
|
||||
$filter = new UnnecassaryWhitespaces($baseTranslations);
|
||||
$result = $filter->filter($translations);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($filteredData, $filter->getFilteredData());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,104 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace Piwik\Plugins\LanguagesManager\Test\Unit\TranslationWriter\Validate;
|
||||
|
||||
use Piwik\Plugins\LanguagesManager\TranslationWriter\Validate\CoreTranslations;
|
||||
|
||||
/**
|
||||
* @group LanguagesManager
|
||||
*/
|
||||
class CoreTranslationsTest 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'
|
||||
)
|
||||
)
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getFilterTestDataValid
|
||||
* @group Core
|
||||
*/
|
||||
public function testFilterValid($translations)
|
||||
{
|
||||
$filter = new CoreTranslations();
|
||||
$result = $filter->isValid($translations);
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
public function getFilterTestDataInvalid()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
array(
|
||||
'General' => array(
|
||||
'bla' => 'test text'
|
||||
)
|
||||
),
|
||||
CoreTranslations::ERRORSTATE_LOCALEREQUIRED
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'General' => array(
|
||||
'Locale' => 'de_DE.UTF-8'
|
||||
)
|
||||
),
|
||||
CoreTranslations::ERRORSTATE_TRANSLATORINFOREQUIRED
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'General' => array(
|
||||
'Locale' => 'invalid',
|
||||
'TranslatorName' => 'name'
|
||||
)
|
||||
),
|
||||
CoreTranslations::ERRORSTATE_LOCALEINVALID
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'General' => array(
|
||||
'Locale' => 'xx_DE.UTF-8',
|
||||
'TranslatorName' => 'name'
|
||||
)
|
||||
),
|
||||
CoreTranslations::ERRORSTATE_LOCALEINVALIDLANGUAGE
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'General' => array(
|
||||
'Locale' => 'de_XX.UTF-8',
|
||||
'TranslatorName' => 'name'
|
||||
)
|
||||
),
|
||||
CoreTranslations::ERRORSTATE_LOCALEINVALIDCOUNTRY
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getFilterTestDataInvalid
|
||||
* @group Core
|
||||
*/
|
||||
public function testFilterInvalid($translations, $msg)
|
||||
{
|
||||
$filter = new CoreTranslations();
|
||||
$result = $filter->isValid($translations);
|
||||
$this->assertFalse($result);
|
||||
$this->assertEquals($msg, $filter->getMessage());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,113 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace Piwik\Plugins\LanguagesManager\Test\Unit\TranslationWriter\Validate;
|
||||
|
||||
use Piwik\Plugins\LanguagesManager\TranslationWriter\Validate\NoScripts;
|
||||
|
||||
/**
|
||||
* @group LanguagesManager
|
||||
*/
|
||||
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
|
||||
*/
|
||||
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(\'test\');">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
|
||||
*/
|
||||
public function testFilterInvalid($translations)
|
||||
{
|
||||
$filter = new NoScripts();
|
||||
$result = $filter->isValid($translations);
|
||||
$this->assertFalse($result);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,267 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace Piwik\Plugins\LanguagesManager\Test\Unit\TranslationWriter;
|
||||
|
||||
use Piwik\Container\StaticContainer;
|
||||
use Piwik\Plugins\LanguagesManager\TranslationWriter\Filter\ByBaseTranslations;
|
||||
use Piwik\Plugins\LanguagesManager\TranslationWriter\Filter\ByParameterCount;
|
||||
use Piwik\Plugins\LanguagesManager\TranslationWriter\Filter\UnnecassaryWhitespaces;
|
||||
use Piwik\Plugins\LanguagesManager\TranslationWriter\Validate\CoreTranslations;
|
||||
use Piwik\Plugins\LanguagesManager\TranslationWriter\Validate\NoScripts;
|
||||
use Piwik\Plugins\LanguagesManager\TranslationWriter\Writer;
|
||||
|
||||
/**
|
||||
* @group LanguagesManager
|
||||
*/
|
||||
class WriterTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @group Core
|
||||
*
|
||||
* @dataProvider getValidConstructorData
|
||||
*/
|
||||
public function testConstructorValid($language, $plugin)
|
||||
{
|
||||
$translationWriter = new Writer($language, $plugin);
|
||||
$this->assertEquals($language, $translationWriter->getLanguage());
|
||||
$this->assertFalse($translationWriter->hasTranslations());
|
||||
}
|
||||
|
||||
public function getValidConstructorData()
|
||||
{
|
||||
return array(
|
||||
array('en', ''),
|
||||
array('de', ''),
|
||||
array('en', 'ExamplePlugin'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group Core
|
||||
*
|
||||
* @expectedException \Exception
|
||||
*/
|
||||
public function testConstructorInvalid()
|
||||
{
|
||||
new Writer('en', 'InValIdPlUGin');
|
||||
}
|
||||
|
||||
/**
|
||||
* @group Core
|
||||
*/
|
||||
public function testHasTranslations()
|
||||
{
|
||||
$writer = new Writer('de');
|
||||
$writer->setTranslations(array('General' => array('test' => 'test')));
|
||||
$this->assertTrue($writer->hasTranslations());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group Core
|
||||
*/
|
||||
public function testHasNoTranslations()
|
||||
{
|
||||
$writer = new Writer('de');
|
||||
$this->assertFalse($writer->hasTranslations());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group Core
|
||||
*/
|
||||
public function testSetTranslationsEmpty()
|
||||
{
|
||||
$writer = new Writer('de');
|
||||
$writer->setTranslations(array());
|
||||
$this->assertTrue($writer->isValid());
|
||||
$this->assertFalse($writer->hasTranslations());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group Core
|
||||
*
|
||||
* @dataProvider getInvalidTranslations
|
||||
*/
|
||||
public function testSetTranslationsInvalid($translations, $error)
|
||||
{
|
||||
$writer = new Writer('de');
|
||||
$writer->setTranslations($translations);
|
||||
$writer->addValidator(new NoScripts());
|
||||
$writer->addValidator(new CoreTranslations());
|
||||
$this->assertFalse($writer->isValid());
|
||||
$this->assertEquals($error, $writer->getValidationMessage());
|
||||
}
|
||||
|
||||
public function getInvalidTranslations()
|
||||
{
|
||||
$translations = json_decode(file_get_contents(PIWIK_INCLUDE_PATH.'/lang/de.json'), true);
|
||||
return array(
|
||||
array(array('General' => array('Locale' => '')) + $translations, CoreTranslations::ERRORSTATE_LOCALEREQUIRED),
|
||||
array(array('General' => array('Locale' => 'de_DE.UTF-8')) + $translations, CoreTranslations::ERRORSTATE_TRANSLATORINFOREQUIRED),
|
||||
array(array('General' => array('Locale' => 'invalid',
|
||||
'TranslatorName' => 'name')) + $translations, CoreTranslations::ERRORSTATE_LOCALEINVALID),
|
||||
array(array('General' => array('Locale' => 'xx_DE.UTF-8',
|
||||
'TranslatorName' => 'name')) + $translations, CoreTranslations::ERRORSTATE_LOCALEINVALIDLANGUAGE),
|
||||
array(array('General' => array('Locale' => 'de_XX.UTF-8',
|
||||
'TranslatorName' => 'name')) + $translations, CoreTranslations::ERRORSTATE_LOCALEINVALIDCOUNTRY),
|
||||
array(array('General' => array('Locale' => '<script>')) + $translations, 'script tags restricted for language files'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group Core
|
||||
*
|
||||
* @expectedException \Exception
|
||||
*/
|
||||
public function testSaveException()
|
||||
{
|
||||
$writer = new Writer('it');
|
||||
$writer->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* @group Core
|
||||
*
|
||||
* @expectedException \Exception
|
||||
*/
|
||||
public function testSaveTemporaryException()
|
||||
{
|
||||
$writer = new Writer('it');
|
||||
$writer->saveTemporary();
|
||||
}
|
||||
|
||||
/**
|
||||
* @group Core
|
||||
*/
|
||||
public function testSaveTranslation()
|
||||
{
|
||||
$translations = json_decode(file_get_contents(PIWIK_INCLUDE_PATH.'/lang/en.json'), true);
|
||||
|
||||
$translationsToWrite = array();
|
||||
$translationsToWrite['General'] = $translations['General'];
|
||||
$translationsToWrite['Mobile'] = $translations['Mobile'];
|
||||
|
||||
$translationsToWrite['General']['Yes'] = 'string with %1$s';
|
||||
$translationsToWrite['Plugin'] = array(
|
||||
'Body' => "Message\nBody"
|
||||
);
|
||||
|
||||
$translationWriter = new Writer('fr');
|
||||
|
||||
$translationWriter->addFilter(new UnnecassaryWhitespaces($translations));
|
||||
$translationWriter->addFilter(new ByBaseTranslations($translations));
|
||||
$translationWriter->addFilter(new ByParameterCount($translations));
|
||||
|
||||
$translationWriter->setTranslations($translationsToWrite);
|
||||
|
||||
$rc = $translationWriter->saveTemporary();
|
||||
|
||||
@unlink(PIWIK_INCLUDE_PATH.'/tmp/fr.json');
|
||||
|
||||
$this->assertGreaterThan(25000, $rc);
|
||||
|
||||
$this->assertCount(4, $translationWriter->getFilterMessages());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group Core
|
||||
*
|
||||
* @dataProvider getTranslationPathTestData
|
||||
*/
|
||||
public function testGetTranslationsPath($language, $plugin, $path)
|
||||
{
|
||||
$writer = new Writer($language, $plugin);
|
||||
$this->assertEquals($path, $writer->getTranslationPath());
|
||||
}
|
||||
|
||||
public function getTranslationPathTestData()
|
||||
{
|
||||
return array(
|
||||
array('de', null, PIWIK_INCLUDE_PATH . '/lang/de.json'),
|
||||
array('te', null, PIWIK_INCLUDE_PATH . '/lang/te.json'),
|
||||
array('de', 'CoreHome', PIWIK_INCLUDE_PATH . '/plugins/CoreHome/lang/de.json'),
|
||||
array('pt-br', 'Actions', PIWIK_INCLUDE_PATH . '/plugins/Actions/lang/pt-br.json'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group Core
|
||||
*
|
||||
* @dataProvider getTranslationPathTemporaryTestData
|
||||
*/
|
||||
public function testGetTemporaryTranslationPath($language, $plugin, $path)
|
||||
{
|
||||
$writer = new Writer($language, $plugin);
|
||||
$this->assertEquals($path, $writer->getTemporaryTranslationPath());
|
||||
}
|
||||
|
||||
public function getTranslationPathTemporaryTestData()
|
||||
{
|
||||
$tmpPath = StaticContainer::get('path.tmp');
|
||||
|
||||
return array(
|
||||
array('de', null, $tmpPath . '/de.json'),
|
||||
array('te', null, $tmpPath . '/te.json'),
|
||||
array('de', 'CoreHome', $tmpPath . '/plugins/CoreHome/lang/de.json'),
|
||||
array('pt-br', 'Actions', $tmpPath . '/plugins/Actions/lang/pt-br.json'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group Core
|
||||
*
|
||||
* @dataProvider getValidLanguages
|
||||
*/
|
||||
public function testSetLanguageValid($language)
|
||||
{
|
||||
$writer = new Writer('en', null);
|
||||
$writer->setLanguage($language);
|
||||
$this->assertEquals(strtolower($language), $writer->getLanguage());
|
||||
}
|
||||
|
||||
public function getValidLanguages()
|
||||
{
|
||||
return array(
|
||||
array('de'),
|
||||
array('te'),
|
||||
array('pt-br'),
|
||||
array('tzm'),
|
||||
array('abc'),
|
||||
array('de-de'),
|
||||
array('DE'),
|
||||
array('DE-DE'),
|
||||
array('DE-de'),
|
||||
);
|
||||
}
|
||||
/**
|
||||
* @group Core
|
||||
*
|
||||
* @expectedException \Exception
|
||||
* @dataProvider getInvalidLanguages
|
||||
*/
|
||||
public function testSetLanguageInvalid($language)
|
||||
{
|
||||
$writer = new Writer('en', null);
|
||||
$writer->setLanguage($language);
|
||||
}
|
||||
|
||||
public function getInvalidLanguages()
|
||||
{
|
||||
return array(
|
||||
array(''),
|
||||
array('abcd'),
|
||||
array('pt-brfr'),
|
||||
array('00'),
|
||||
array('a-b'),
|
||||
array('x3'),
|
||||
array('X4-fd'),
|
||||
array('12-34'),
|
||||
array('$§'),
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue