/Tests/Unit/Utility/Unicode/FunctionsTest.php

https://github.com/arbyte/FLOW3-X-TYPO3.FLOW3 · PHP · 207 lines · 88 code · 21 blank · 98 comment · 0 complexity · 74774abd34deb87e107b12415ec07169 MD5 · raw file

  1. <?php
  2. namespace TYPO3\FLOW3\Tests\Unit\Utility\Unicode;
  3. /* *
  4. * This script belongs to the FLOW3 package "PHP6". *
  5. * *
  6. * It is free software; you can redistribute it and/or modify it under *
  7. * the terms of the GNU Lesser General Public License, either version 3 *
  8. * of the License, or (at your option) any later version. *
  9. * *
  10. * The TYPO3 project - inspiring people to share! *
  11. * */
  12. /**
  13. * Testcase for the PHP6 Functions backport
  14. *
  15. */
  16. class FunctionsTest extends \TYPO3\FLOW3\Tests\UnitTestCase {
  17. /**
  18. * Checks if strtotitle() at least works with latin characters.
  19. *
  20. * @test
  21. */
  22. public function strtotitleWorksWithLatinCharacters() {
  23. $testString = 'this Is - my TestString.';
  24. $this->assertEquals('This Is - My Teststring.', \TYPO3\FLOW3\Utility\Unicode\Functions::strtotitle($testString), 'strtotitle() did not return the expected string.');
  25. }
  26. /**
  27. * Checks if strtotitle() works with unicode strings
  28. *
  29. * @test
  30. */
  31. public function strtotitleWorksWithUnicodeStrings() {
  32. $testString = ' öl Ist nicht das GLEICHE wie øl.';
  33. $expectedString = ' Öl Ist Nicht Das Gleiche Wie Øl.';
  34. $this->assertEquals($expectedString, \TYPO3\FLOW3\Utility\Unicode\Functions::strtotitle($testString), 'strtotitle() did not return the expected string for the unicode test.');
  35. }
  36. /**
  37. * Checks if substr() basically works with latin characters.
  38. *
  39. * @test
  40. */
  41. public function substrWorksWithLatinCharacters() {
  42. $testString = 'I say "hello world".';
  43. $this->assertEquals('hello world', \TYPO3\FLOW3\Utility\Unicode\Functions::substr($testString, 7, 11), 'substr() with latin characters did not return the expected string.');
  44. }
  45. /**
  46. * Checks if substr() can handle UTF8 strings
  47. *
  48. * @test
  49. */
  50. public function substrWorksWithUTF8Characters() {
  51. $testString = 'Kasper Skårhøj implemented most versions of TYPO3.';
  52. $this->assertEquals('Kasper Skårhøj', \TYPO3\FLOW3\Utility\Unicode\Functions::substr($testString, 0, 14), 'substr() with UTF8 characters did not return the expected string.');
  53. }
  54. /**
  55. * Checks if substr() can handle UTF8 strings, specifying no length
  56. *
  57. * @test
  58. */
  59. public function substrWorksWithUTF8CharactersSpecifyingNoLength() {
  60. $testString = 'Kasper Skårhøj implemented most versions of TYPO3.';
  61. $this->assertEquals('implemented most versions of TYPO3.', \TYPO3\FLOW3\Utility\Unicode\Functions::substr($testString, 15), 'substr() with UTF8 characters did not return the expected string after specifying no length.');
  62. }
  63. /**
  64. * Checks if our version of \TYPO3\FLOW3\Utility\Unicode\Functions::strtoupper basically works
  65. *
  66. * @test
  67. */
  68. public function strtoupperWorksWithLatinCharacters() {
  69. $testString = 'typo3';
  70. $this->assertEquals('TYPO3', \TYPO3\FLOW3\Utility\Unicode\Functions::strtoupper($testString), 'TYPO3\PHP6\Functions::strtoupper() with latin characters didn\'t work out.');
  71. }
  72. /**
  73. * Checks if our version of \TYPO3\FLOW3\Utility\Unicode\Functions::strtoupper can at least handle some common special chars
  74. *
  75. * @test
  76. */
  77. public function strtoupperWorksWithCertainSpecialChars() {
  78. $testString = 'Here are some characters: äöüÄÖÜßéèêåÅøØæÆœŒ ...';
  79. $expectedResult = 'HERE ARE SOME CHARACTERS: ÄÖÜÄÖÜSSÉÈÊÅÅØØÆÆŒŒ ...';
  80. $result = \TYPO3\FLOW3\Utility\Unicode\Functions::strtoupper($testString);
  81. $this->assertEquals($expectedResult, $result, 'TYPO3\PHP6\Functions::strtoupper() could not convert our selection of special characters.');
  82. }
  83. /**
  84. * Checks if our version of strtolower basically works
  85. *
  86. * @test
  87. */
  88. public function strtolowerWorksWithLatinCharacters() {
  89. $testString = 'TYPO3';
  90. $this->assertEquals('typo3', \TYPO3\FLOW3\Utility\Unicode\Functions::strtolower($testString), 'strtolower() with latin characters didn\'t work out.');
  91. }
  92. /**
  93. * Checks if our version of strtolower can at least handle some common special chars
  94. *
  95. * @test
  96. */
  97. public function strtolowerWorksWithCertainSpecialChars() {
  98. $testString = 'HERE ARE SOME CHARACTERS: ÄÖÜÄÖÜßÉÈÊÅÅØØÆÆŒŒ ...';
  99. $expectedResult = 'here are some characters: äöüäöüßéèêååøøææœœ ...';
  100. $result = \TYPO3\FLOW3\Utility\Unicode\Functions::strtolower($testString);
  101. $this->assertEquals($expectedResult, $result, 'strtolower() could not convert our selection of special characters.');
  102. }
  103. /**
  104. * Checks if our version of strlen can handle some regular latin characters.
  105. *
  106. * @test
  107. */
  108. public function strlenWorksWithLatinCharacters() {
  109. $testString = 'Feugiat tincidunt duo id, 23 quam delenit vocibus nam eu';
  110. $this->assertEquals(56, \TYPO3\FLOW3\Utility\Unicode\Functions::strlen($testString), 'strlen() did not return the correct string length for latin character string.');
  111. }
  112. /**
  113. * Checks if our version of strlen can handle some common special chars
  114. *
  115. * @test
  116. */
  117. public function strlenWorksWithCertainSpecialChars() {
  118. $testString = 'here are some characters: äöüäöüßéèêååøøææœœ“” ...';
  119. $this->assertEquals(50, \TYPO3\FLOW3\Utility\Unicode\Functions::strlen($testString), 'strlen() did not return the correct string length for unicode string.');
  120. }
  121. /**
  122. * Checks if our version of ucfirst can handle some regular latin characters.
  123. *
  124. * @test
  125. */
  126. public function ucfirstWorksWithLatinCharacters() {
  127. $testString = 'feugiat tincidunt duo id, 23 quam delenit vocibus nam eu';
  128. $expectedResult = 'Feugiat tincidunt duo id, 23 quam delenit vocibus nam eu';
  129. $this->assertEquals($expectedResult, \TYPO3\FLOW3\Utility\Unicode\Functions::ucfirst($testString), 'ucfirst() did not return the correct string for latin string.');
  130. }
  131. /**
  132. * Checks if our version of ucfirst can handle some common special chars.
  133. *
  134. * @test
  135. */
  136. public function ucfirstWorksWithCertainSpecialChars() {
  137. $testString = 'äeugiat tincidunt duo id, 23 quam delenit vocibus nam eu';
  138. $expectedResult = 'Äeugiat tincidunt duo id, 23 quam delenit vocibus nam eu';
  139. $this->assertEquals($expectedResult, \TYPO3\FLOW3\Utility\Unicode\Functions::ucfirst($testString), 'ucfirst() did not return the correct string for a umlaut.');
  140. $testString = 'åeugiat tincidunt duo id, 23 quam delenit vocibus nam eu';
  141. $expectedResult = 'Åeugiat tincidunt duo id, 23 quam delenit vocibus nam eu';
  142. $this->assertEquals($expectedResult, \TYPO3\FLOW3\Utility\Unicode\Functions::ucfirst($testString), 'ucfirst() did not return the correct string for danish a.');
  143. }
  144. /**
  145. * Checks if our version of lcfirst can handle some regular latin characters.
  146. *
  147. * @test
  148. */
  149. public function lcfirstWorksWithLatinCharacters() {
  150. $testString = 'FEUGIAT TINCIDUNT DUO ID, 23 QUAM DELENIT VOCIBUS NAM EU';
  151. $expectedResult = 'fEUGIAT TINCIDUNT DUO ID, 23 QUAM DELENIT VOCIBUS NAM EU';
  152. $this->assertEquals($expectedResult, \TYPO3\FLOW3\Utility\Unicode\Functions::lcfirst($testString), 'lcfirst() did not return the correct string for latin string.');
  153. }
  154. /**
  155. * Checks if our version of lcfirst can handle some common special chars.
  156. *
  157. * @test
  158. */
  159. public function lcfirstWorksWithCertainSpecialChars() {
  160. $testString = 'ÄEUGIAT TINCIDUNT DUO ID, 23 QUAM DELENIT VOCIBUS NAM EU';
  161. $expectedResult = 'äEUGIAT TINCIDUNT DUO ID, 23 QUAM DELENIT VOCIBUS NAM EU';
  162. $this->assertEquals($expectedResult, \TYPO3\FLOW3\Utility\Unicode\Functions::lcfirst($testString), 'lcfirst() did not return the correct string for a umlaut.');
  163. $testString = 'ÅEUGIAT TINCIDUNT DUO ID, 23 QUAM DELENIT VOCIBUS NAM EU';
  164. $expectedResult = 'åEUGIAT TINCIDUNT DUO ID, 23 QUAM DELENIT VOCIBUS NAM EU';
  165. $this->assertEquals($expectedResult, \TYPO3\FLOW3\Utility\Unicode\Functions::lcfirst($testString), 'lcfirst() did not return the correct string for danish a.');
  166. }
  167. /**
  168. * Checks if our version of strpos can handle some regular latin characters.
  169. *
  170. * @test
  171. */
  172. public function strposWorksWithLatinCharacters() {
  173. $testString = 'Feugiat tincidunt duo id, 23 quam delenit vocibus nam eu';
  174. $this->assertEquals(8, strpos($testString, 'tincidunt'), 'strpos() did not return the correct position for a latin character string.');
  175. }
  176. /**
  177. * Checks if our version of strpos can handle some common special characters
  178. *
  179. * @test
  180. */
  181. public function strposWorksWithCertainSpecialChars() {
  182. $testString = 'Åeugiat tincidunt duo id, 23 quam delenit vocibus nam eu';
  183. $this->assertEquals(8, \TYPO3\FLOW3\Utility\Unicode\Functions::strpos($testString, 'tincidunt'), 'strpos() did not return the correct positions for a unicode string.');
  184. }
  185. }
  186. ?>