PageRenderTime 59ms CodeModel.GetById 30ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/PHPUnit/Core/Translate/Filter/ByParameterCountTest.php

https://github.com/CodeYellowBV/piwik
PHP | 121 lines | 104 code | 2 blank | 15 comment | 0 complexity | 86d20f6f2b08578ddea51b2835565b1f MD5 | raw file
Possible License(s): LGPL-3.0, JSON, MIT, GPL-3.0, LGPL-2.1, GPL-2.0, AGPL-1.0, BSD-2-Clause, BSD-3-Clause
  1. <?php
  2. use Piwik\Translate\Filter\ByParameterCount;
  3. /**
  4. * Piwik - free/libre analytics platform
  5. *
  6. * @link http://piwik.org
  7. * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
  8. */
  9. class ByParameterCountTest extends PHPUnit_Framework_TestCase
  10. {
  11. public function getFilterTestData()
  12. {
  13. return array(
  14. // empty stays empty - nothing to filter
  15. array(
  16. array(),
  17. array(),
  18. array(),
  19. array()
  20. ),
  21. // empty plugin is removed
  22. array(
  23. array(
  24. 'test' => array()
  25. ),
  26. array(),
  27. array(),
  28. array(),
  29. ),
  30. // value with %s will be removed, as it isn't there in base
  31. array(
  32. array(
  33. 'test' => array(
  34. 'key' => 'val%sue',
  35. 'test' => 'test'
  36. )
  37. ),
  38. array(
  39. 'test' => array(
  40. 'key' => 'value',
  41. )
  42. ),
  43. array(
  44. 'test' => array(
  45. 'test' => 'test',
  46. )
  47. ),
  48. array(
  49. 'test' => array(
  50. 'key' => 'val%sue',
  51. )
  52. ),
  53. ),
  54. // no change if placeholder count is the same
  55. array(
  56. array(
  57. 'test' => array(
  58. 'test' => 'te%sst'
  59. )
  60. ),
  61. array(
  62. 'test' => array(
  63. 'test' => 'test%s'
  64. )
  65. ),
  66. array(
  67. 'test' => array(
  68. 'test' => 'te%sst'
  69. )
  70. ),
  71. array()
  72. ),
  73. // missing placeholder will be removed
  74. array(
  75. array(
  76. 'empty' => array(
  77. 'test' => 't%1$sest'
  78. ),
  79. 'test' => array(
  80. 'test' => '%1$stest',
  81. 'empty' => ' ',
  82. )
  83. ),
  84. array(
  85. 'empty' => array(
  86. 'test' => 'test%1$s'
  87. ),
  88. 'test' => array(
  89. 'test' => '%1$stest%2$s',
  90. )
  91. ),
  92. array(
  93. 'empty' => array(
  94. 'test' => 't%1$sest'
  95. ),
  96. 'test' => array(
  97. 'empty' => ' ',
  98. )
  99. ),
  100. array(
  101. 'test' => array(
  102. 'test' => '%1$stest',
  103. )
  104. )
  105. ),
  106. );
  107. }
  108. /**
  109. * @dataProvider getFilterTestData
  110. * @group Core
  111. */
  112. public function testFilter($translations, $baseTranslations, $expected, $filteredData)
  113. {
  114. $filter = new ByParameterCount($baseTranslations);
  115. $result = $filter->filter($translations);
  116. $this->assertEquals($expected, $result);
  117. $this->assertEquals($filteredData, $filter->getFilteredData());
  118. }
  119. }