2
0

MultiByteTest.php 7.4 KB

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