2
0

MultiByteTest.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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. /**
  73. * Alternative cut tests
  74. */
  75. public function testWordWrapCutBeginningSingleSpace()
  76. {
  77. $line = Zend_Text_MultiByte::wordWrap(' äüöäöü', 3, ' ', true);
  78. $this->assertEquals(' äüö äöü', $line);
  79. }
  80. public function testWordWrapCutEndingSingleSpace()
  81. {
  82. $line = Zend_Text_MultiByte::wordWrap('äüöäöü ', 3, ' ', true);
  83. $this->assertEquals('äüö äöü ', $line);
  84. }
  85. public function testWordWrapCutEndingTwoSpaces()
  86. {
  87. $line = Zend_Text_MultiByte::wordWrap('äüöäöü ', 3, ' ', true);
  88. $this->assertEquals('äüö äöü ', $line);
  89. }
  90. public function testWordWrapCutEndingThreeSpaces()
  91. {
  92. $line = Zend_Text_MultiByte::wordWrap('äüöäöü ', 3, ' ', true);
  93. $this->assertEquals('äüö äöü ', $line);
  94. }
  95. public function testWordWrapCutEndingTwoBreaks()
  96. {
  97. $line = Zend_Text_MultiByte::wordWrap('äüöäöü--', 3, '-', true);
  98. $this->assertEquals('äüö-äöü--', $line);
  99. }
  100. public function testWordWrapCutTab()
  101. {
  102. $line = Zend_Text_MultiByte::wordWrap("äbü\töcß", 3, ' ', true);
  103. $this->assertEquals("äbü \töc ß", $line);
  104. }
  105. public function testWordWrapCutNewlineWithSpace()
  106. {
  107. $line = Zend_Text_MultiByte::wordWrap("äbü\nößt", 3, ' ', true);
  108. $this->assertEquals("äbü \nöß t", $line);
  109. }
  110. public function testWordWrapCutNewlineWithNewline()
  111. {
  112. $line = Zend_Text_MultiByte::wordWrap("äbü\nößte", 3, "\n", true);
  113. $this->assertEquals("äbü\nößt\ne", $line);
  114. }
  115. /**
  116. * Break cut tests
  117. */
  118. public function testWordWrapCutBreakBefore()
  119. {
  120. $line = Zend_Text_MultiByte::wordWrap('foobar-foofoofoo', 8, '-', true);
  121. $this->assertEquals('foobar-foofoofo-o', $line);
  122. }
  123. public function testWordWrapCutBreakWith()
  124. {
  125. $line = Zend_Text_MultiByte::wordWrap('foobar-foobar', 6, '-', true);
  126. $this->assertEquals('foobar-foobar', $line);
  127. }
  128. public function testWordWrapCutBreakWithin()
  129. {
  130. $line = Zend_Text_MultiByte::wordWrap('foobar-foobar', 7, '-', true);
  131. $this->assertEquals('foobar-foobar', $line);
  132. }
  133. public function testWordWrapCutBreakWithinEnd()
  134. {
  135. $line = Zend_Text_MultiByte::wordWrap('foobar-', 7, '-', true);
  136. $this->assertEquals('foobar-', $line);
  137. }
  138. public function testWordWrapCutBreakAfter()
  139. {
  140. $line = Zend_Text_MultiByte::wordWrap('foobar-foobar', 5, '-', true);
  141. $this->assertEquals('fooba-r-fooba-r', $line);
  142. }
  143. /**
  144. * Standard no-cut tests
  145. */
  146. public function testWordWrapNoCutSingleLine()
  147. {
  148. $line = Zend_Text_MultiByte::wordWrap('äbüöcß', 2, ' ', false);
  149. $this->assertEquals('äbüöcß', $line);
  150. }
  151. public function testWordWrapNoCutMultiLine()
  152. {
  153. $line = Zend_Text_MultiByte::wordWrap('äbüöc ß äbüöcß', 2, "\n", false);
  154. $this->assertEquals("äbüöc\nß\näbüöcß", $line);
  155. }
  156. public function testWordWrapNoCutMultiWord()
  157. {
  158. $line = Zend_Text_MultiByte::wordWrap('äöü äöü äöü', 5, "\n", false);
  159. $this->assertEquals("äöü\näöü\näöü", $line);
  160. }
  161. /**
  162. * Break no-cut tests
  163. */
  164. public function testWordWrapNoCutBreakBefore()
  165. {
  166. $line = Zend_Text_MultiByte::wordWrap('foobar-foofoofoo', 8, '-', false);
  167. $this->assertEquals('foobar-foofoofoo', $line);
  168. }
  169. public function testWordWrapNoCutBreakWith()
  170. {
  171. $line = Zend_Text_MultiByte::wordWrap('foobar-foobar', 6, '-', false);
  172. $this->assertEquals('foobar-foobar', $line);
  173. }
  174. public function testWordWrapNoCutBreakWithin()
  175. {
  176. $line = Zend_Text_MultiByte::wordWrap('foobar-foobar', 7, '-', false);
  177. $this->assertEquals('foobar-foobar', $line);
  178. }
  179. public function testWordWrapNoCutBreakWithinEnd()
  180. {
  181. $line = Zend_Text_MultiByte::wordWrap('foobar-', 7, '-', false);
  182. $this->assertEquals('foobar-', $line);
  183. }
  184. public function testWordWrapNoCutBreakAfter()
  185. {
  186. $line = Zend_Text_MultiByte::wordWrap('foobar-foobar', 5, '-', false);
  187. $this->assertEquals('foobar-foobar', $line);
  188. }
  189. /**
  190. * Pad tests
  191. */
  192. public function testLeftPad()
  193. {
  194. $text = Zend_Text_MultiByte::strPad('äää', 5, 'ö', STR_PAD_LEFT);
  195. $this->assertEquals('ööäää', $text);
  196. }
  197. public function testCenterPad()
  198. {
  199. $text = Zend_Text_MultiByte::strPad('äää', 6, 'ö', STR_PAD_BOTH);
  200. $this->assertEquals('öäääöö', $text);
  201. }
  202. public function testRightPad()
  203. {
  204. $text = Zend_Text_MultiByte::strPad('äääöö', 5, 'ö', STR_PAD_RIGHT);
  205. $this->assertEquals('äääöö', $text);
  206. }
  207. }
  208. // Call Zend_Text_MultiByteTest::main() if this source file is executed directly.
  209. if (PHPUnit_MAIN_METHOD == "Zend_Text_MultiByteTest::main") {
  210. Zend_Text_MultiByteTest::main();
  211. }