MultiByteTest.php 7.8 KB

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