TextHelperTest.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  1. <?php
  2. /**
  3. * TextHelperTest file
  4. *
  5. * PHP 5
  6. *
  7. * CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
  8. * Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
  9. *
  10. * Licensed under The MIT License
  11. * Redistributions of files must retain the above copyright notice
  12. *
  13. * @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
  14. * @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
  15. * @package Cake.Test.Case.View.Helper
  16. * @since CakePHP(tm) v 1.2.0.4206
  17. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  18. */
  19. App::uses('View', 'View');
  20. App::uses('TextHelper', 'View/Helper');
  21. /**
  22. * TextHelperTest class
  23. *
  24. * @package Cake.Test.Case.View.Helper
  25. */
  26. class TextHelperTest extends CakeTestCase {
  27. /**
  28. * setUp method
  29. *
  30. * @return void
  31. */
  32. public function setUp() {
  33. $controller = null;
  34. $this->View = new View($controller);
  35. $this->Text = new TextHelper($this->View);
  36. }
  37. /**
  38. * tearDown method
  39. *
  40. * @return void
  41. */
  42. public function tearDown() {
  43. unset($this->View, $this->Text);
  44. }
  45. /**
  46. * testTruncate method
  47. *
  48. * @return void
  49. */
  50. public function testTruncate() {
  51. $text1 = 'The quick brown fox jumps over the lazy dog';
  52. $text2 = 'Heiz&ouml;lr&uuml;cksto&szlig;abd&auml;mpfung';
  53. $text3 = '<b>&copy; 2005-2007, Cake Software Foundation, Inc.</b><br />written by Alexander Wegener';
  54. $text4 = '<img src="mypic.jpg"> This image tag is not XHTML conform!<br><hr/><b>But the following image tag should be conform <img src="mypic.jpg" alt="Me, myself and I" /></b><br />Great, or?';
  55. $text5 = '0<b>1<i>2<span class="myclass">3</span>4<u>5</u>6</i>7</b>8<b>9</b>0';
  56. $text6 = '<p><strong>Extra dates have been announced for this year\'s tour.</strong></p><p>Tickets for the new shows in</p>';
  57. $text7 = 'El moño está en el lugar correcto. Eso fue lo que dijo la niña, ¿habrá dicho la verdad?';
  58. $text8 = 'Vive la R' . chr(195) . chr(169) . 'publique de France';
  59. $text9 = 'НОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыь';
  60. $this->assertSame($this->Text->truncate($text1, 15), 'The quick br...');
  61. $this->assertSame($this->Text->truncate($text1, 15, array('exact' => false)), 'The quick...');
  62. $this->assertSame($this->Text->truncate($text1, 100), 'The quick brown fox jumps over the lazy dog');
  63. $this->assertSame($this->Text->truncate($text2, 10), 'Heiz&ou...');
  64. $this->assertSame($this->Text->truncate($text2, 10, array('exact' => false)), '...');
  65. $this->assertSame($this->Text->truncate($text3, 20), '<b>&copy; 2005-20...');
  66. $this->assertSame($this->Text->truncate($text4, 15), '<img src="my...');
  67. $this->assertSame($this->Text->truncate($text5, 6, array('ending' => '')), '0<b>1<');
  68. $this->assertSame($this->Text->truncate($text1, 15, array('html' => true)), 'The quick br...');
  69. $this->assertSame($this->Text->truncate($text1, 15, array('exact' => false, 'html' => true)), 'The quick...');
  70. $this->assertSame($this->Text->truncate($text2, 10, array('html' => true)), 'Heiz&ouml;lr...');
  71. $this->assertSame($this->Text->truncate($text2, 10, array('exact' => false, 'html' => true)), '...');
  72. $this->assertSame($this->Text->truncate($text3, 20, array('html' => true)), '<b>&copy; 2005-2007, Cake...</b>');
  73. $this->assertSame($this->Text->truncate($text4, 15, array('html' => true)), '<img src="mypic.jpg"> This image ...');
  74. $this->assertSame($this->Text->truncate($text4, 45, array('html' => true)), '<img src="mypic.jpg"> This image tag is not XHTML conform!<br><hr/><b>But t...</b>');
  75. $this->assertSame($this->Text->truncate($text4, 90, array('html' => true)), '<img src="mypic.jpg"> This image tag is not XHTML conform!<br><hr/><b>But the following image tag should be conform <img src="mypic.jpg" alt="Me, myself and I" /></b><br />Grea...');
  76. $this->assertSame($this->Text->truncate($text5, 6, array('ending' => '', 'html' => true)), '0<b>1<i>2<span class="myclass">3</span>4<u>5</u></i></b>');
  77. $this->assertSame($this->Text->truncate($text5, 20, array('ending' => '', 'html' => true)), $text5);
  78. $this->assertSame($this->Text->truncate($text6, 57, array('exact' => false, 'html' => true)), "<p><strong>Extra dates have been announced for this year's...</strong></p>");
  79. $this->assertSame($this->Text->truncate($text7, 255), $text7);
  80. $this->assertSame($this->Text->truncate($text7, 15), 'El moño está...');
  81. $this->assertSame($this->Text->truncate($text8, 15), 'Vive la R'.chr(195).chr(169).'pu...');
  82. $this->assertSame($this->Text->truncate($text9, 10), 'НОПРСТУ...');
  83. $text = '<p><span style="font-size: medium;"><a>Iamatestwithnospacesandhtml</a></span></p>';
  84. $result = $this->Text->truncate($text, 10, array(
  85. 'ending' => '...',
  86. 'exact' => false,
  87. 'html' => true
  88. ));
  89. $expected = '<p><span style="font-size: medium;"><a>...</a></span></p>';
  90. $this->assertEquals($expected, $result);
  91. $text = '<p><span style="font-size: medium;">El biógrafo de Steve Jobs, Walter
  92. Isaacson, explica porqué Jobs le pidió que le hiciera su biografía en
  93. este artículo de El País.</span></p>
  94. <p><span style="font-size: medium;"><span style="font-size:
  95. large;">Por qué Steve era distinto.</span></span></p>
  96. <p><span style="font-size: medium;"><a href="http://www.elpais.com/
  97. articulo/primer/plano/Steve/era/distinto/elpepueconeg/
  98. 20111009elpneglse_4/Tes">http://www.elpais.com/articulo/primer/plano/
  99. Steve/era/distinto/elpepueconeg/20111009elpneglse_4/Tes</a></span></p>
  100. <p><span style="font-size: medium;">Ya se ha publicado la biografía de
  101. Steve Jobs escrita por Walter Isaacson "<strong>Steve Jobs by Walter
  102. Isaacson</strong>", aquí os dejamos la dirección de amazon donde
  103. podeís adquirirla.</span></p>
  104. <p><span style="font-size: medium;"><a>http://www.amazon.com/Steve-
  105. Jobs-Walter-Isaacson/dp/1451648537</a></span></p>';
  106. $result = $this->Text->truncate($text, 500, array(
  107. 'ending' => '... ',
  108. 'exact' => false,
  109. 'html' => true
  110. ));
  111. $expected = '<p><span style="font-size: medium;">El biógrafo de Steve Jobs, Walter
  112. Isaacson, explica porqué Jobs le pidió que le hiciera su biografía en
  113. este artículo de El País.</span></p>
  114. <p><span style="font-size: medium;"><span style="font-size:
  115. large;">Por qué Steve era distinto.</span></span></p>
  116. <p><span style="font-size: medium;"><a href="http://www.elpais.com/
  117. articulo/primer/plano/Steve/era/distinto/elpepueconeg/
  118. 20111009elpneglse_4/Tes">http://www.elpais.com/articulo/primer/plano/
  119. Steve/era/distinto/elpepueconeg/20111009elpneglse_4/Tes</a></span></p>
  120. <p><span style="font-size: medium;">Ya se ha publicado la biografía de
  121. Steve Jobs escrita por Walter Isaacson "<strong>Steve Jobs by Walter
  122. Isaacson</strong>", aquí os dejamos la dirección de amazon donde
  123. podeís adquirirla.</span></p>
  124. <p><span style="font-size: medium;"><a>... </a></span></p>';
  125. $this->assertEquals($expected, $result);
  126. }
  127. /**
  128. * testHighlight method
  129. *
  130. * @return void
  131. */
  132. public function testHighlight() {
  133. $text = 'This is a test text';
  134. $phrases = array('This', 'text');
  135. $result = $this->Text->highlight($text, $phrases, array('format' => '<b>\1</b>'));
  136. $expected = '<b>This</b> is a test <b>text</b>';
  137. $this->assertEquals($expected, $result);
  138. $text = 'This is a test text';
  139. $phrases = null;
  140. $result = $this->Text->highlight($text, $phrases, array('format' => '<b>\1</b>'));
  141. $this->assertEquals($result, $text);
  142. $text = 'This is a (test) text';
  143. $phrases = '(test';
  144. $result = $this->Text->highlight($text, $phrases, array('format' => '<b>\1</b>'));
  145. $this->assertEquals('This is a <b>(test</b>) text', $result);
  146. $text = 'Ich saß in einem Café am Übergang';
  147. $expected = 'Ich <b>saß</b> in einem <b>Café</b> am <b>Übergang</b>';
  148. $phrases = array('saß', 'café', 'übergang');
  149. $result = $this->Text->highlight($text, $phrases, array('format' => '<b>\1</b>'));
  150. $this->assertEquals($expected, $result);
  151. }
  152. /**
  153. * testHighlightHtml method
  154. *
  155. * @return void
  156. */
  157. public function testHighlightHtml() {
  158. $text1 = '<p>strongbow isn&rsquo;t real cider</p>';
  159. $text2 = '<p>strongbow <strong>isn&rsquo;t</strong> real cider</p>';
  160. $text3 = '<img src="what-a-strong-mouse.png" alt="What a strong mouse!" />';
  161. $text4 = 'What a strong mouse: <img src="what-a-strong-mouse.png" alt="What a strong mouse!" />';
  162. $options = array('format' => '<b>\1</b>', 'html' => true);
  163. $expected = '<p><b>strong</b>bow isn&rsquo;t real cider</p>';
  164. $this->assertEquals($this->Text->highlight($text1, 'strong', $options), $expected);
  165. $expected = '<p><b>strong</b>bow <strong>isn&rsquo;t</strong> real cider</p>';
  166. $this->assertEquals($this->Text->highlight($text2, 'strong', $options), $expected);
  167. $this->assertEquals($this->Text->highlight($text3, 'strong', $options), $text3);
  168. $this->assertEquals($this->Text->highlight($text3, array('strong', 'what'), $options), $text3);
  169. $expected = '<b>What</b> a <b>strong</b> mouse: <img src="what-a-strong-mouse.png" alt="What a strong mouse!" />';
  170. $this->assertEquals($this->Text->highlight($text4, array('strong', 'what'), $options), $expected);
  171. }
  172. /**
  173. * testHighlightMulti method
  174. *
  175. * @return void
  176. */
  177. public function testHighlightMulti() {
  178. $text = 'This is a test text';
  179. $phrases = array('This', 'text');
  180. $result = $this->Text->highlight($text, $phrases, array('format' => array('<b>\1</b>', '<em>\1</em>')));
  181. $expected = '<b>This</b> is a test <em>text</em>';
  182. $this->assertEquals($expected, $result);
  183. }
  184. /**
  185. * testStripLinks method
  186. *
  187. * @return void
  188. */
  189. public function testStripLinks() {
  190. $text = 'This is a test text';
  191. $expected = 'This is a test text';
  192. $result = $this->Text->stripLinks($text);
  193. $this->assertEquals($expected, $result);
  194. $text = 'This is a <a href="#">test</a> text';
  195. $expected = 'This is a test text';
  196. $result = $this->Text->stripLinks($text);
  197. $this->assertEquals($expected, $result);
  198. $text = 'This <strong>is</strong> a <a href="#">test</a> <a href="#">text</a>';
  199. $expected = 'This <strong>is</strong> a test text';
  200. $result = $this->Text->stripLinks($text);
  201. $this->assertEquals($expected, $result);
  202. $text = 'This <strong>is</strong> a <a href="#">test</a> and <abbr>some</abbr> other <a href="#">text</a>';
  203. $expected = 'This <strong>is</strong> a test and <abbr>some</abbr> other text';
  204. $result = $this->Text->stripLinks($text);
  205. $this->assertEquals($expected, $result);
  206. }
  207. /**
  208. * testAutoLink method
  209. *
  210. * @return void
  211. */
  212. public function testAutoLink() {
  213. $text = 'This is a test text';
  214. $expected = 'This is a test text';
  215. $result = $this->Text->autoLink($text);
  216. $this->assertEquals($expected, $result);
  217. $text = 'Text with a partial www.cakephp.org URL and test@cakephp.org email address';
  218. $result = $this->Text->autoLink($text);
  219. $expected = 'Text with a partial <a href="http://www.cakephp.org">www.cakephp.org</a> URL and <a href="mailto:test@cakephp\.org">test@cakephp\.org</a> email address';
  220. $this->assertRegExp('#^' . $expected . '$#', $result);
  221. $text = 'This is a test text with URL http://www.cakephp.org';
  222. $expected = 'This is a test text with URL <a href="http://www.cakephp.org">http://www.cakephp.org</a>';
  223. $result = $this->Text->autoLink($text);
  224. $this->assertEquals($expected, $result);
  225. $text = 'This is a test text with URL http://www.cakephp.org and some more text';
  226. $expected = 'This is a test text with URL <a href="http://www.cakephp.org">http://www.cakephp.org</a> and some more text';
  227. $result = $this->Text->autoLink($text);
  228. $this->assertEquals($expected, $result);
  229. $text = "This is a test text with URL http://www.cakephp.org\tand some more text";
  230. $expected = "This is a test text with URL <a href=\"http://www.cakephp.org\">http://www.cakephp.org</a>\tand some more text";
  231. $result = $this->Text->autoLink($text);
  232. $this->assertEquals($expected, $result);
  233. $text = 'This is a test text with URL http://www.cakephp.org(and some more text)';
  234. $expected = 'This is a test text with URL <a href="http://www.cakephp.org">http://www.cakephp.org</a>(and some more text)';
  235. $result = $this->Text->autoLink($text);
  236. $this->assertEquals($expected, $result);
  237. $text = 'This is a test text with URL http://www.cakephp.org';
  238. $expected = 'This is a test text with URL <a href="http://www.cakephp.org" class="link">http://www.cakephp.org</a>';
  239. $result = $this->Text->autoLink($text, array('class' => 'link'));
  240. $this->assertEquals($expected, $result);
  241. $text = 'This is a test text with URL http://www.cakephp.org';
  242. $expected = 'This is a test text with URL <a href="http://www.cakephp.org" class="link" id="MyLink">http://www.cakephp.org</a>';
  243. $result = $this->Text->autoLink($text, array('class' => 'link', 'id' => 'MyLink'));
  244. $this->assertEquals($expected, $result);
  245. }
  246. /**
  247. * Test escaping for autoLink
  248. *
  249. * @return void
  250. */
  251. public function testAutoLinkEscape() {
  252. $text = 'This is a <b>test</b> text with URL http://www.cakephp.org';
  253. $expected = 'This is a &lt;b&gt;test&lt;/b&gt; text with URL <a href="http://www.cakephp.org">http://www.cakephp.org</a>';
  254. $result = $this->Text->autoLink($text);
  255. $this->assertEquals($expected, $result);
  256. $text = 'This is a <b>test</b> text with URL http://www.cakephp.org';
  257. $expected = 'This is a <b>test</b> text with URL <a href="http://www.cakephp.org">http://www.cakephp.org</a>';
  258. $result = $this->Text->autoLink($text, array('escape' => false));
  259. $this->assertEquals($expected, $result);
  260. }
  261. /**
  262. * testAutoLinkUrls method
  263. *
  264. * @return void
  265. */
  266. public function testAutoLinkUrls() {
  267. $text = 'This is a test text';
  268. $expected = 'This is a test text';
  269. $result = $this->Text->autoLinkUrls($text);
  270. $this->assertEquals($expected, $result);
  271. $text = 'This is a test that includes (www.cakephp.org)';
  272. $expected = 'This is a test that includes (<a href="http://www.cakephp.org">www.cakephp.org</a>)';
  273. $result = $this->Text->autoLinkUrls($text);
  274. $this->assertEquals($expected, $result);
  275. $text = 'Text with a partial www.cakephp.org URL';
  276. $expected = 'Text with a partial <a href="http://www.cakephp.org"\s*>www.cakephp.org</a> URL';
  277. $result = $this->Text->autoLinkUrls($text);
  278. $this->assertRegExp('#^' . $expected . '$#', $result);
  279. $text = 'Text with a partial www.cakephp.org URL';
  280. $expected = 'Text with a partial <a href="http://www.cakephp.org" \s*class="link">www.cakephp.org</a> URL';
  281. $result = $this->Text->autoLinkUrls($text, array('class' => 'link'));
  282. $this->assertRegExp('#^' . $expected . '$#', $result);
  283. $text = 'Text with a partial WWW.cakephp.org URL';
  284. $expected = 'Text with a partial <a href="http://WWW.cakephp.org"\s*>WWW.cakephp.org</a> URL';
  285. $result = $this->Text->autoLinkUrls($text);
  286. $this->assertRegExp('#^' . $expected . '$#', $result);
  287. $text = 'Text with a partial WWW.cakephp.org &copy; URL';
  288. $expected = 'Text with a partial <a href="http://WWW.cakephp.org"\s*>WWW.cakephp.org</a> &copy; URL';
  289. $result = $this->Text->autoLinkUrls($text, array('escape' => false));
  290. $this->assertRegExp('#^' . $expected . '$#', $result);
  291. $text = 'Text with a url www.cot.ag/cuIb2Q and more';
  292. $expected = 'Text with a url <a href="http://www.cot.ag/cuIb2Q">www.cot.ag/cuIb2Q</a> and more';
  293. $result = $this->Text->autoLinkUrls($text);
  294. $this->assertEquals($expected, $result);
  295. $text = 'Text with a url http://www.does--not--work.com and more';
  296. $expected = 'Text with a url <a href="http://www.does--not--work.com">http://www.does--not--work.com</a> and more';
  297. $result = $this->Text->autoLinkUrls($text);
  298. $this->assertEquals($expected, $result);
  299. $text = 'Text with a url http://www.not--work.com and more';
  300. $expected = 'Text with a url <a href="http://www.not--work.com">http://www.not--work.com</a> and more';
  301. $result = $this->Text->autoLinkUrls($text);
  302. $this->assertEquals($expected, $result);
  303. }
  304. /**
  305. * Test autoLinkUrls with the escape option.
  306. *
  307. * @return void
  308. */
  309. public function testAutoLinkUrlsEscape() {
  310. $text = 'Text with a partial <a href="http://www.cakephp.org">link</a> link';
  311. $expected = 'Text with a partial <a href="http://www.cakephp.org">link</a> link';
  312. $result = $this->Text->autoLinkUrls($text, array('escape' => false));
  313. $this->assertEquals($expected, $result);
  314. $text = 'Text with a partial <iframe src="http://www.cakephp.org" /> link';
  315. $expected = 'Text with a partial <iframe src="http://www.cakephp.org" /> link';
  316. $result = $this->Text->autoLinkUrls($text, array('escape' => false));
  317. $this->assertEquals($expected, $result);
  318. $text = 'Text with a partial <iframe src="http://www.cakephp.org" /> link';
  319. $expected = 'Text with a partial &lt;iframe src=&quot;http://www.cakephp.org&quot; /&gt; link';
  320. $result = $this->Text->autoLinkUrls($text, array('escape' => true));
  321. $this->assertEquals($expected, $result);
  322. }
  323. /**
  324. * testAutoLinkEmails method
  325. *
  326. * @return void
  327. */
  328. public function testAutoLinkEmails() {
  329. $text = 'This is a test text';
  330. $expected = 'This is a test text';
  331. $result = $this->Text->autoLinkUrls($text);
  332. $this->assertEquals($expected, $result);
  333. $text = 'Text with email@example.com address';
  334. $expected = 'Text with <a href="mailto:email@example.com"\s*>email@example.com</a> address';
  335. $result = $this->Text->autoLinkEmails($text);
  336. $this->assertRegExp('#^' . $expected . '$#', $result);
  337. $text = "Text with o'hare._-bob@example.com address";
  338. $expected = 'Text with <a href="mailto:o&#039;hare._-bob@example.com">o&#039;hare._-bob@example.com</a> address';
  339. $result = $this->Text->autoLinkEmails($text);
  340. $this->assertEquals($expected, $result);
  341. $text = 'Text with email@example.com address';
  342. $expected = 'Text with <a href="mailto:email@example.com" \s*class="link">email@example.com</a> address';
  343. $result = $this->Text->autoLinkEmails($text, array('class' => 'link'));
  344. $this->assertRegExp('#^' . $expected . '$#', $result);
  345. }
  346. /**
  347. * test invalid email addresses.
  348. *
  349. * @return void
  350. */
  351. public function testAutoLinkEmailInvalid() {
  352. $result = $this->Text->autoLinkEmails('this is a myaddress@gmx-de test');
  353. $expected = 'this is a myaddress@gmx-de test';
  354. $this->assertEquals($expected, $result);
  355. }
  356. /**
  357. * testHighlightCaseInsensitivity method
  358. *
  359. * @return void
  360. */
  361. public function testHighlightCaseInsensitivity() {
  362. $text = 'This is a Test text';
  363. $expected = 'This is a <b>Test</b> text';
  364. $result = $this->Text->highlight($text, 'test', array('format' => '<b>\1</b>'));
  365. $this->assertEquals($expected, $result);
  366. $result = $this->Text->highlight($text, array('test'), array('format' => '<b>\1</b>'));
  367. $this->assertEquals($expected, $result);
  368. }
  369. /**
  370. * testExcerpt method
  371. *
  372. * @return void
  373. */
  374. public function testExcerpt() {
  375. $text = 'This is a phrase with test text to play with';
  376. $expected = '...ase with test text to ...';
  377. $result = $this->Text->excerpt($text, 'test', 9, '...');
  378. $this->assertEquals($expected, $result);
  379. $expected = 'This is a...';
  380. $result = $this->Text->excerpt($text, 'not_found', 9, '...');
  381. $this->assertEquals($expected, $result);
  382. $expected = 'This is a phras...';
  383. $result = $this->Text->excerpt($text, null, 9, '...');
  384. $this->assertEquals($expected, $result);
  385. $expected = $text;
  386. $result = $this->Text->excerpt($text, null, 200, '...');
  387. $this->assertEquals($expected, $result);
  388. $expected = '...a phrase w...';
  389. $result = $this->Text->excerpt($text, 'phrase', 2, '...');
  390. $this->assertEquals($expected, $result);
  391. $phrase = 'This is a phrase with test text';
  392. $expected = $text;
  393. $result = $this->Text->excerpt($text, $phrase, 13, '...');
  394. $this->assertEquals($expected, $result);
  395. $text = 'aaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbaaaaaaaaaaaaaaaaaaaaaaaa';
  396. $phrase = 'bbbbbbbb';
  397. $result = $this->Text->excerpt($text, $phrase, 10);
  398. $expected = '...aaaaaaaaaabbbbbbbbaaaaaaaaaa...';
  399. $this->assertEquals($expected, $result);
  400. }
  401. /**
  402. * testExcerptCaseInsensitivity method
  403. *
  404. * @return void
  405. */
  406. public function testExcerptCaseInsensitivity() {
  407. $text = 'This is a phrase with test text to play with';
  408. $expected = '...ase with test text to ...';
  409. $result = $this->Text->excerpt($text, 'TEST', 9, '...');
  410. $this->assertEquals($expected, $result);
  411. $expected = 'This is a...';
  412. $result = $this->Text->excerpt($text, 'NOT_FOUND', 9, '...');
  413. $this->assertEquals($expected, $result);
  414. }
  415. /**
  416. * testListGeneration method
  417. *
  418. * @return void
  419. */
  420. public function testListGeneration() {
  421. $result = $this->Text->toList(array());
  422. $this->assertEquals($result, '');
  423. $result = $this->Text->toList(array('One'));
  424. $this->assertEquals($result, 'One');
  425. $result = $this->Text->toList(array('Larry', 'Curly', 'Moe'));
  426. $this->assertEquals($result, 'Larry, Curly and Moe');
  427. $result = $this->Text->toList(array('Dusty', 'Lucky', 'Ned'), 'y');
  428. $this->assertEquals($result, 'Dusty, Lucky y Ned');
  429. $result = $this->Text->toList(array(1 => 'Dusty', 2 => 'Lucky', 3 => 'Ned'), 'y');
  430. $this->assertEquals($result, 'Dusty, Lucky y Ned');
  431. $result = $this->Text->toList(array(1 => 'Dusty', 2 => 'Lucky', 3 => 'Ned'), 'and', ' + ');
  432. $this->assertEquals($result, 'Dusty + Lucky and Ned');
  433. $result = $this->Text->toList(array('name1' => 'Dusty', 'name2' => 'Lucky'));
  434. $this->assertEquals($result, 'Dusty and Lucky');
  435. $result = $this->Text->toList(array('test_0' => 'banana', 'test_1' => 'apple', 'test_2' => 'lemon'));
  436. $this->assertEquals($result, 'banana, apple and lemon');
  437. }
  438. }