MultiByteTest.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Text
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. // Call Zend_Text_MultiByteTest::main() if this source file is executed directly.
  23. if (!defined("PHPUnit_MAIN_METHOD")) {
  24. define("PHPUnit_MAIN_METHOD", "Zend_Text_MultiByteTest::main");
  25. }
  26. /**
  27. * Zend_Text_MultiByte
  28. */
  29. require_once 'Zend/Text/MultiByte.php';
  30. /**
  31. * @category Zend
  32. * @package Zend_Text
  33. * @subpackage UnitTests
  34. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  35. * @license http://framework.zend.com/license/new-bsd New BSD License
  36. * @group Zend_Text
  37. */
  38. class Zend_Text_MultiByteTest extends PHPUnit_Framework_TestCase
  39. {
  40. /**
  41. * Runs the test methods of this class.
  42. *
  43. * @return void
  44. */
  45. public static function main()
  46. {
  47. $suite = new PHPUnit_Framework_TestSuite("Zend_Text_MultiByteTest");
  48. $result = PHPUnit_TextUI_TestRunner::run($suite);
  49. }
  50. /**
  51. * Standard cut tests
  52. */
  53. public function testWordWrapCutSingleLine()
  54. {
  55. $line = Zend_Text_MultiByte::wordWrap('äbüöcß', 2, ' ', true);
  56. $this->assertEquals('äb üö cß', $line);
  57. }
  58. public function testWordWrapCutMultiLine()
  59. {
  60. $line = Zend_Text_MultiByte::wordWrap('äbüöc ß äbüöcß', 2, ' ', true);
  61. $this->assertEquals('äb üö c ß äb üö cß', $line);
  62. }
  63. public function testWordWrapCutMultiLineShortWords()
  64. {
  65. $line = Zend_Text_MultiByte::wordWrap('Ä very long wöööööööööööörd.', 8, "\n", true);
  66. $this->assertEquals("Ä very\nlong\nwööööööö\nööööörd.", $line);
  67. }
  68. public function testWordWrapCutMultiLineWithPreviousNewlines()
  69. {
  70. $line = Zend_Text_MultiByte::wordWrap("Ä very\nlong wöööööööööööörd.", 8, "\n", false);
  71. $this->assertEquals("Ä very\nlong\nwöööööööööööörd.", $line);
  72. }
  73. /**
  74. * Long-Break tests
  75. */
  76. public function testWordWrapLongBreak()
  77. {
  78. $line = Zend_Text_MultiByte::wordWrap("Ä very<br>long wöö<br>öööööööö<br>öörd.", 8, '<br>', false);
  79. $this->assertEquals("Ä very<br>long<br>wöö<br>öööööööö<br>öörd.", $line);
  80. }
  81. /**
  82. * Alternative cut tests
  83. */
  84. public function testWordWrapCutBeginningSingleSpace()
  85. {
  86. $line = Zend_Text_MultiByte::wordWrap(' äüöäöü', 3, ' ', true);
  87. $this->assertEquals(' äüö äöü', $line);
  88. }
  89. public function testWordWrapCutEndingSingleSpace()
  90. {
  91. $line = Zend_Text_MultiByte::wordWrap('äüöäöü ', 3, ' ', true);
  92. $this->assertEquals('äüö äöü ', $line);
  93. }
  94. public function testWordWrapCutEndingTwoSpaces()
  95. {
  96. $line = Zend_Text_MultiByte::wordWrap('äüöäöü ', 3, ' ', true);
  97. $this->assertEquals('äüö äöü ', $line);
  98. }
  99. public function testWordWrapCutEndingThreeSpaces()
  100. {
  101. $line = Zend_Text_MultiByte::wordWrap('äüöäöü ', 3, ' ', true);
  102. $this->assertEquals('äüö äöü ', $line);
  103. }
  104. public function testWordWrapCutEndingTwoBreaks()
  105. {
  106. $line = Zend_Text_MultiByte::wordWrap('äüöäöü--', 3, '-', true);
  107. $this->assertEquals('äüö-äöü--', $line);
  108. }
  109. public function testWordWrapCutTab()
  110. {
  111. $line = Zend_Text_MultiByte::wordWrap("äbü\töcß", 3, ' ', true);
  112. $this->assertEquals("äbü \töc ß", $line);
  113. }
  114. public function testWordWrapCutNewlineWithSpace()
  115. {
  116. $line = Zend_Text_MultiByte::wordWrap("äbü\nößt", 3, ' ', true);
  117. $this->assertEquals("äbü \nöß t", $line);
  118. }
  119. public function testWordWrapCutNewlineWithNewline()
  120. {
  121. $line = Zend_Text_MultiByte::wordWrap("äbü\nößte", 3, "\n", true);
  122. $this->assertEquals("äbü\nößt\ne", $line);
  123. }
  124. /**
  125. * Break cut tests
  126. */
  127. public function testWordWrapCutBreakBefore()
  128. {
  129. $line = Zend_Text_MultiByte::wordWrap('foobar-foofoofoo', 8, '-', true);
  130. $this->assertEquals('foobar-foofoofo-o', $line);
  131. }
  132. public function testWordWrapCutBreakWith()
  133. {
  134. $line = Zend_Text_MultiByte::wordWrap('foobar-foobar', 6, '-', true);
  135. $this->assertEquals('foobar-foobar', $line);
  136. }
  137. public function testWordWrapCutBreakWithin()
  138. {
  139. $line = Zend_Text_MultiByte::wordWrap('foobar-foobar', 7, '-', true);
  140. $this->assertEquals('foobar-foobar', $line);
  141. }
  142. public function testWordWrapCutBreakWithinEnd()
  143. {
  144. $line = Zend_Text_MultiByte::wordWrap('foobar-', 7, '-', true);
  145. $this->assertEquals('foobar-', $line);
  146. }
  147. public function testWordWrapCutBreakAfter()
  148. {
  149. $line = Zend_Text_MultiByte::wordWrap('foobar-foobar', 5, '-', true);
  150. $this->assertEquals('fooba-r-fooba-r', $line);
  151. }
  152. /**
  153. * Standard no-cut tests
  154. */
  155. public function testWordWrapNoCutSingleLine()
  156. {
  157. $line = Zend_Text_MultiByte::wordWrap('äbüöcß', 2, ' ', false);
  158. $this->assertEquals('äbüöcß', $line);
  159. }
  160. public function testWordWrapNoCutMultiLine()
  161. {
  162. $line = Zend_Text_MultiByte::wordWrap('äbüöc ß äbüöcß', 2, "\n", false);
  163. $this->assertEquals("äbüöc\nß\näbüöcß", $line);
  164. }
  165. public function testWordWrapNoCutMultiWord()
  166. {
  167. $line = Zend_Text_MultiByte::wordWrap('äöü äöü äöü', 5, "\n", false);
  168. $this->assertEquals("äöü\näöü\näöü", $line);
  169. }
  170. /**
  171. * Break no-cut tests
  172. */
  173. public function testWordWrapNoCutBreakBefore()
  174. {
  175. $line = Zend_Text_MultiByte::wordWrap('foobar-foofoofoo', 8, '-', false);
  176. $this->assertEquals('foobar-foofoofoo', $line);
  177. }
  178. public function testWordWrapNoCutBreakWith()
  179. {
  180. $line = Zend_Text_MultiByte::wordWrap('foobar-foobar', 6, '-', false);
  181. $this->assertEquals('foobar-foobar', $line);
  182. }
  183. public function testWordWrapNoCutBreakWithin()
  184. {
  185. $line = Zend_Text_MultiByte::wordWrap('foobar-foobar', 7, '-', false);
  186. $this->assertEquals('foobar-foobar', $line);
  187. }
  188. public function testWordWrapNoCutBreakWithinEnd()
  189. {
  190. $line = Zend_Text_MultiByte::wordWrap('foobar-', 7, '-', false);
  191. $this->assertEquals('foobar-', $line);
  192. }
  193. public function testWordWrapNoCutBreakAfter()
  194. {
  195. $line = Zend_Text_MultiByte::wordWrap('foobar-foobar', 5, '-', false);
  196. $this->assertEquals('foobar-foobar', $line);
  197. }
  198. /**
  199. * Pad tests
  200. */
  201. public function testLeftPad()
  202. {
  203. $text = Zend_Text_MultiByte::strPad('äää', 5, 'ö', STR_PAD_LEFT);
  204. $this->assertEquals('ööäää', $text);
  205. }
  206. public function testCenterPad()
  207. {
  208. $text = Zend_Text_MultiByte::strPad('äää', 6, 'ö', STR_PAD_BOTH);
  209. $this->assertEquals('öäääöö', $text);
  210. }
  211. public function testRightPad()
  212. {
  213. $text = Zend_Text_MultiByte::strPad('äääöö', 5, 'ö', STR_PAD_RIGHT);
  214. $this->assertEquals('äääöö', $text);
  215. }
  216. }
  217. // Call Zend_Text_MultiByteTest::main() if this source file is executed directly.
  218. if (PHPUnit_MAIN_METHOD == "Zend_Text_MultiByteTest::main") {
  219. Zend_Text_MultiByteTest::main();
  220. }