PageRenderTime 26ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/classes/fUTF8/fUTF8Test.php

https://github.com/piclyf/flourish
PHP | 180 lines | 125 code | 37 blank | 18 comment | 1 complexity | 679783ddf67f25fdf8fa397a777f9e64 MD5 | raw file
  1. <?php
  2. require_once('./support/init.php');
  3. class fUTF8Test extends PHPUnit_Framework_TestCase
  4. {
  5. public function setUp()
  6. {
  7. if (defined('SKIPPING')) {
  8. $this->markTestSkipped();
  9. }
  10. }
  11. public static function explodeProvider()
  12. {
  13. $output = array();
  14. $output[] = array('', NULL, array(''));
  15. $output[] = array(' ', NULL, array(' '));
  16. $output[] = array("a\nb", NULL, array("a", "\n", "b"));
  17. $output[] = array("\na\nb\n\n", NULL, array("\n", "a", "\n", "b", "\n", "\n"));
  18. $output[] = array('abcdefg', NULL, array('a', 'b', 'c', 'd', 'e', 'f', 'g'));
  19. $output[] = array('Iñtërnâtiônàlizætiøn', NULL, array('I', 'ñ', 't', 'ë', 'r', 'n', 'â', 't', 'i', 'ô', 'n', 'à', 'l', 'i', 'z', 'æ', 't', 'i', 'ø', 'n'));
  20. $output[] = array("a\nb", '', array("a", "\n", "b"));
  21. $output[] = array("a\nb", 'a', array("", "\nb"));
  22. $output[] = array("a\nb", "\n", array("a", "b"));
  23. $output[] = array('Iñtërnâtiônàlizætiøn', 'nà', array('Iñtërnâtiô', 'lizætiøn'));
  24. return $output;
  25. }
  26. /**
  27. * @dataProvider explodeProvider
  28. */
  29. public function testExplode($input, $delimiter, $output)
  30. {
  31. $this->assertEquals($output, fUTF8::explode($input, $delimiter));
  32. }
  33. public static function rposProvider()
  34. {
  35. $output = array();
  36. $output[] = array('', '', 0, FALSE);
  37. $output[] = array(' ', '', 0, FALSE);
  38. $output[] = array('abc', '', 0, FALSE);
  39. $output[] = array("abc", 'a', 0, 0);
  40. $output[] = array("abc", 'b', 0, 1);
  41. $output[] = array("abc", 'c', 0, 2);
  42. $output[] = array("aaa", 'a', 0, 2);
  43. $output[] = array("aaa", 'a', 1, 2);
  44. $output[] = array("aaa", 'a', 2, 2);
  45. $output[] = array("aaa", 'a', -1, 2);
  46. $output[] = array("aaa", 'a', -2, 1);
  47. $output[] = array("aaa", 'a', -3, 0);
  48. $output[] = array('Iñtërnâtiônàlizætiøn', 'â', 0, 6);
  49. $output[] = array('Iñtërnâtiônàlizætiøn', 'æ', 0, 15);
  50. return $output;
  51. }
  52. /**
  53. * @dataProvider rposProvider
  54. */
  55. public function testRpos($input, $needle, $offset, $output)
  56. {
  57. $this->assertEquals($output, fUTF8::rpos($input, $needle, $offset));
  58. }
  59. public function testUpper()
  60. {
  61. $this->assertEquals('IŔ', fUTF8::upper('iŕ'));
  62. }
  63. public static function trimProvider()
  64. {
  65. $output = array();
  66. $output[] = array(' hello ', NULL, 'hello');
  67. $output[] = array('hello ', NULL, 'hello');
  68. $output[] = array('hello ', ' o', 'hell');
  69. $output[] = array('hello ', ' elo', 'h');
  70. $output[] = array(' Iñtërnâtiônàlizætiøn ', NULL, 'Iñtërnâtiônàlizætiøn');
  71. $output[] = array(' Iñtërnâtiônàlizætiøn ', ' øn', 'Iñtërnâtiônàlizæti');
  72. $output[] = array(' Iñtërnâtiônàlizætiøn ', " \x6B..\x6E", 'Iñtërnâtiônàlizætiø');
  73. return $output;
  74. }
  75. /**
  76. * @dataProvider trimProvider
  77. */
  78. public function testTrim($input, $charlist, $output)
  79. {
  80. $this->assertEquals($output, fUTF8::trim($input, $charlist));
  81. }
  82. public static function ltrimProvider()
  83. {
  84. $output = array();
  85. $output[] = array(' hello ', NULL, 'hello ');
  86. $output[] = array('hello ', NULL, 'hello ');
  87. $output[] = array('hello ', ' o', 'hello ');
  88. $output[] = array('hello ', ' elo', 'hello ');
  89. $output[] = array(' Iñtërnâtiônàlizætiøn ', NULL, 'Iñtërnâtiônàlizætiøn ');
  90. $output[] = array(' Iñtërnâtiônàlizætiøn ', ' ñI', 'tërnâtiônàlizætiøn ');
  91. $output[] = array(' Iñtërnâtiônàlizætiøn ', " \x49..\x6E", 'ñtërnâtiônàlizætiøn ');
  92. return $output;
  93. }
  94. /**
  95. * @dataProvider ltrimProvider
  96. */
  97. public function testLtrim($input, $charlist, $output)
  98. {
  99. $this->assertEquals($output, fUTF8::ltrim($input, $charlist));
  100. }
  101. public static function rtrimProvider()
  102. {
  103. $output = array();
  104. $output[] = array(' hello ', NULL, ' hello');
  105. $output[] = array('hello ', NULL, 'hello');
  106. $output[] = array('hello ', ' o', 'hell');
  107. $output[] = array('hello ', ' elo', 'h');
  108. $output[] = array(' Iñtërnâtiônàlizætiøn ', NULL, ' Iñtërnâtiônàlizætiøn');
  109. $output[] = array(' Iñtërnâtiônàlizætiøn ', ' ønI', ' Iñtërnâtiônàlizæti');
  110. $output[] = array(' Iñtërnâtiônàlizætiøn ', " \x6B..\x6EI", ' Iñtërnâtiônàlizætiø');
  111. return $output;
  112. }
  113. /**
  114. * @dataProvider rtrimProvider
  115. */
  116. public function testRtrim($input, $charlist, $output)
  117. {
  118. $this->assertEquals($output, fUTF8::rtrim($input, $charlist));
  119. }
  120. public static function ucwordsProvider()
  121. {
  122. $output = array();
  123. $output[] = array('hello', 'Hello');
  124. $output[] = array('This is a longer phrase', 'This Is A Longer Phrase');
  125. $output[] = array('This phrase (contains some) punctuation/that might cause "issues"', 'This Phrase (Contains Some) Punctuation/That Might Cause "Issues"');
  126. $output[] = array("Single prime \"apostrophes\" aren't an issue, and 'single prime' quotes work", "Single Prime \"Apostrophes\" Aren't An Issue, And 'Single Prime' Quotes Work");
  127. $output[] = array("Apostrophes aren’t an issue", "Apostrophes Aren’t An Issue");
  128. $output[] = array("‘single’ and “double” quotes are handled too", "‘Single’ And “Double” Quotes Are Handled Too");
  129. $output[] = array("Hyphens-get-handled-too", "Hyphens-Get-Handled-Too");
  130. $output[] = array("\\'Backslashed single quote'", "\\'Backslashed Single Quote'");
  131. return $output;
  132. }
  133. /**
  134. * @dataProvider ucwordsProvider
  135. */
  136. public function testUcwords($input, $output)
  137. {
  138. $this->assertEquals($output, fUTF8::ucwords($input));
  139. }
  140. public function tearDown()
  141. {
  142. }
  143. }