TextHelperTest.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * For full copyright and license information, please see the LICENSE.txt
  8. * Redistributions of files must retain the above copyright notice
  9. *
  10. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  11. * @link http://cakephp.org CakePHP(tm) Project
  12. * @since 1.2.0
  13. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  14. */
  15. namespace Cake\Test\TestCase\View\Helper;
  16. use Cake\Core\App;
  17. use Cake\Core\Configure;
  18. use Cake\Core\Plugin;
  19. use Cake\TestSuite\TestCase;
  20. use Cake\View\Helper\TextHelper;
  21. use Cake\View\View;
  22. /**
  23. * Class TextHelperTestObject
  24. *
  25. */
  26. class TextHelperTestObject extends TextHelper
  27. {
  28. public function attach(StringMock $string)
  29. {
  30. $this->_engine = $string;
  31. }
  32. public function engine()
  33. {
  34. return $this->_engine;
  35. }
  36. }
  37. /**
  38. * StringMock class
  39. *
  40. */
  41. class StringMock
  42. {
  43. }
  44. /**
  45. * TextHelperTest class
  46. *
  47. */
  48. class TextHelperTest extends TestCase
  49. {
  50. /**
  51. * setUp method
  52. *
  53. * @return void
  54. */
  55. public function setUp()
  56. {
  57. parent::setUp();
  58. $this->View = new View();
  59. $this->Text = new TextHelper($this->View);
  60. $this->_appNamespace = Configure::read('App.namespace');
  61. Configure::write('App.namespace', 'TestApp');
  62. }
  63. /**
  64. * tearDown method
  65. *
  66. * @return void
  67. */
  68. public function tearDown()
  69. {
  70. unset($this->Text, $this->View);
  71. Configure::write('App.namespace', $this->_appNamespace);
  72. parent::tearDown();
  73. }
  74. /**
  75. * test String class methods are called correctly
  76. *
  77. * @return void
  78. */
  79. public function testTextHelperProxyMethodCalls()
  80. {
  81. $methods = [
  82. 'stripLinks', 'excerpt', 'toList'
  83. ];
  84. $String = $this->getMock(__NAMESPACE__ . '\StringMock', $methods);
  85. $Text = new TextHelperTestObject($this->View, ['engine' => __NAMESPACE__ . '\StringMock']);
  86. $Text->attach($String);
  87. foreach ($methods as $method) {
  88. $String->expects($this->at(0))->method($method);
  89. $Text->{$method}('who', 'what', 'when', 'where', 'how');
  90. }
  91. $methods = [
  92. 'highlight', 'truncate'
  93. ];
  94. $String = $this->getMock(__NAMESPACE__ . '\StringMock', $methods);
  95. $Text = new TextHelperTestObject($this->View, ['engine' => __NAMESPACE__ . '\StringMock']);
  96. $Text->attach($String);
  97. foreach ($methods as $method) {
  98. $String->expects($this->at(0))->method($method);
  99. $Text->{$method}('who', ['what']);
  100. }
  101. $methods = [
  102. 'tail'
  103. ];
  104. $String = $this->getMock(__NAMESPACE__ . '\StringMock', $methods);
  105. $Text = new TextHelperTestObject($this->View, ['engine' => __NAMESPACE__ . '\StringMock']);
  106. $Text->attach($String);
  107. foreach ($methods as $method) {
  108. $String->expects($this->at(0))->method($method);
  109. $Text->{$method}('who', 1, ['what']);
  110. }
  111. }
  112. /**
  113. * test engine override
  114. *
  115. * @return void
  116. */
  117. public function testEngineOverride()
  118. {
  119. $Text = new TextHelperTestObject($this->View, ['engine' => 'TestAppEngine']);
  120. $this->assertInstanceOf('TestApp\Utility\TestAppEngine', $Text->engine());
  121. Plugin::load('TestPlugin');
  122. $Text = new TextHelperTestObject($this->View, ['engine' => 'TestPlugin.TestPluginEngine']);
  123. $this->assertInstanceOf('TestPlugin\Utility\TestPluginEngine', $Text->engine());
  124. Plugin::unload('TestPlugin');
  125. }
  126. /**
  127. * testAutoLink method
  128. *
  129. * @return void
  130. */
  131. public function testAutoLink()
  132. {
  133. $text = 'The AWWWARD show happened today';
  134. $result = $this->Text->autoLink($text);
  135. $this->assertEquals($text, $result);
  136. $text = 'This is a test text';
  137. $expected = 'This is a test text';
  138. $result = $this->Text->autoLink($text);
  139. $this->assertEquals($expected, $result);
  140. $text = 'Text with a partial www.cakephp.org URL and test@cakephp.org email address';
  141. $result = $this->Text->autoLink($text);
  142. $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';
  143. $this->assertRegExp('#^' . $expected . '$#', $result);
  144. $text = 'This is a test text with URL http://www.cakephp.org';
  145. $expected = 'This is a test text with URL <a href="http://www.cakephp.org">http://www.cakephp.org</a>';
  146. $result = $this->Text->autoLink($text);
  147. $this->assertEquals($expected, $result);
  148. $text = 'This is a test text with URL http://www.cakephp.org and some more text';
  149. $expected = 'This is a test text with URL <a href="http://www.cakephp.org">http://www.cakephp.org</a> and some more text';
  150. $result = $this->Text->autoLink($text);
  151. $this->assertEquals($expected, $result);
  152. $text = "This is a test text with URL http://www.cakephp.org\tand some more text";
  153. $expected = "This is a test text with URL <a href=\"http://www.cakephp.org\">http://www.cakephp.org</a>\tand some more text";
  154. $result = $this->Text->autoLink($text);
  155. $this->assertEquals($expected, $result);
  156. $text = 'This is a test text with URL http://www.cakephp.org(and some more text)';
  157. $expected = 'This is a test text with URL <a href="http://www.cakephp.org">http://www.cakephp.org</a>(and some more text)';
  158. $result = $this->Text->autoLink($text);
  159. $this->assertEquals($expected, $result);
  160. $text = 'This is a test text with URL (http://www.cakephp.org/page/4) in brackets';
  161. $expected = 'This is a test text with URL (<a href="http://www.cakephp.org/page/4">http://www.cakephp.org/page/4</a>) in brackets';
  162. $result = $this->Text->autoLink($text);
  163. $this->assertEquals($expected, $result);
  164. $text = 'This is a test text with URL [http://www.cakephp.org/page/4] in square brackets';
  165. $expected = 'This is a test text with URL [<a href="http://www.cakephp.org/page/4">http://www.cakephp.org/page/4</a>] in square brackets';
  166. $result = $this->Text->autoLink($text);
  167. $this->assertEquals($expected, $result);
  168. $text = 'This is a test text with URL [http://www.example.com?aParam[]=value1&aParam[]=value2&aParam[]=value3] in square brackets';
  169. $expected = 'This is a test text with URL [<a href="http://www.example.com?aParam[]=value1&amp;aParam[]=value2&amp;aParam[]=value3">http://www.example.com?aParam[]=value1&amp;aParam[]=value2&amp;aParam[]=value3</a>] in square brackets';
  170. $result = $this->Text->autoLink($text);
  171. $this->assertEquals($expected, $result);
  172. $text = 'This is a test text with URL ;http://www.cakephp.org/page/4; semi-colon';
  173. $expected = 'This is a test text with URL ;<a href="http://www.cakephp.org/page/4">http://www.cakephp.org/page/4</a>; semi-colon';
  174. $result = $this->Text->autoLink($text);
  175. $this->assertEquals($expected, $result);
  176. $text = 'This is a test text with URL (http://www.cakephp.org/page/4/other(thing)) brackets';
  177. $expected = 'This is a test text with URL (<a href="http://www.cakephp.org/page/4/other(thing)">http://www.cakephp.org/page/4/other(thing)</a>) brackets';
  178. $result = $this->Text->autoLink($text);
  179. $this->assertEquals($expected, $result);
  180. }
  181. /**
  182. * Test mixing URLs and Email addresses in one confusing string.
  183. *
  184. * @return void
  185. */
  186. public function testAutoLinkMixed()
  187. {
  188. $text = 'Text with a url/email http://example.com/store?email=mark@example.com and email.';
  189. $expected = 'Text with a url/email <a href="http://example.com/store?email=mark@example.com">' .
  190. 'http://example.com/store?email=mark@example.com</a> and email.';
  191. $result = $this->Text->autoLink($text);
  192. $this->assertEquals($expected, $result);
  193. }
  194. /**
  195. * test autoLink() and options.
  196. *
  197. * @return void
  198. */
  199. public function testAutoLinkOptions()
  200. {
  201. $text = 'This is a test text with URL http://www.cakephp.org';
  202. $expected = 'This is a test text with URL <a href="http://www.cakephp.org" class="link">http://www.cakephp.org</a>';
  203. $result = $this->Text->autoLink($text, ['class' => 'link']);
  204. $this->assertEquals($expected, $result);
  205. $text = 'This is a test text with URL http://www.cakephp.org';
  206. $expected = 'This is a test text with URL <a href="http://www.cakephp.org" class="link" id="MyLink">http://www.cakephp.org</a>';
  207. $result = $this->Text->autoLink($text, ['class' => 'link', 'id' => 'MyLink']);
  208. $this->assertEquals($expected, $result);
  209. }
  210. /**
  211. * Test escaping for autoLink
  212. *
  213. * @return void
  214. */
  215. public function testAutoLinkEscape()
  216. {
  217. $text = 'This is a <b>test</b> text with URL http://www.cakephp.org';
  218. $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>';
  219. $result = $this->Text->autoLink($text);
  220. $this->assertEquals($expected, $result);
  221. $text = 'This is a <b>test</b> text with URL http://www.cakephp.org';
  222. $expected = 'This is a <b>test</b> text with URL <a href="http://www.cakephp.org">http://www.cakephp.org</a>';
  223. $result = $this->Text->autoLink($text, ['escape' => false]);
  224. $this->assertEquals($expected, $result);
  225. $text = 'test <ul>
  226. <li>lorem: http://example.org?some</li>
  227. <li>ipsum: http://othersite.com/abc</li>
  228. </ul> test';
  229. $expected = 'test <ul>
  230. <li>lorem: <a href="http://example.org?some">http://example.org?some</a></li>
  231. <li>ipsum: <a href="http://othersite.com/abc">http://othersite.com/abc</a></li>
  232. </ul> test';
  233. $result = $this->Text->autoLink($text, ['escape' => false]);
  234. $this->assertEquals($expected, $result);
  235. }
  236. /**
  237. * Data provider for autoLinking
  238. *
  239. * @return array
  240. */
  241. public static function autoLinkProvider()
  242. {
  243. return [
  244. [
  245. 'This is a test text',
  246. 'This is a test text',
  247. ],
  248. [
  249. 'This is a test that includes (www.cakephp.org)',
  250. 'This is a test that includes (<a href="http://www.cakephp.org">www.cakephp.org</a>)',
  251. ],
  252. [
  253. 'This is a test that includes www.cakephp.org:8080',
  254. 'This is a test that includes <a href="http://www.cakephp.org:8080">www.cakephp.org:8080</a>',
  255. ],
  256. [
  257. 'This is a test that includes http://de.wikipedia.org/wiki/Kanton_(Schweiz)#fragment',
  258. 'This is a test that includes <a href="http://de.wikipedia.org/wiki/Kanton_(Schweiz)#fragment">http://de.wikipedia.org/wiki/Kanton_(Schweiz)#fragment</a>',
  259. ],
  260. [
  261. 'This is a test that includes www.wikipedia.org/wiki/Kanton_(Schweiz)#fragment',
  262. 'This is a test that includes <a href="http://www.wikipedia.org/wiki/Kanton_(Schweiz)#fragment">www.wikipedia.org/wiki/Kanton_(Schweiz)#fragment</a>',
  263. ],
  264. [
  265. 'This is a test that includes http://example.com/test.php?foo=bar text',
  266. 'This is a test that includes <a href="http://example.com/test.php?foo=bar">http://example.com/test.php?foo=bar</a> text',
  267. ],
  268. [
  269. 'This is a test that includes www.example.com/test.php?foo=bar text',
  270. 'This is a test that includes <a href="http://www.example.com/test.php?foo=bar">www.example.com/test.php?foo=bar</a> text',
  271. ],
  272. [
  273. 'Text with a partial www.cakephp.org URL',
  274. 'Text with a partial <a href="http://www.cakephp.org">www.cakephp.org</a> URL',
  275. ],
  276. [
  277. 'Text with a partial WWW.cakephp.org URL',
  278. 'Text with a partial <a href="http://WWW.cakephp.org">WWW.cakephp.org</a> URL',
  279. ],
  280. [
  281. 'Text with a partial WWW.cakephp.org &copy, URL',
  282. 'Text with a partial <a href="http://WWW.cakephp.org">WWW.cakephp.org</a> &amp;copy, URL',
  283. ],
  284. [
  285. 'Text with a url www.cot.ag/cuIb2Q and more',
  286. 'Text with a url <a href="http://www.cot.ag/cuIb2Q">www.cot.ag/cuIb2Q</a> and more',
  287. ],
  288. [
  289. 'Text with a url http://www.does--not--work.com and more',
  290. 'Text with a url <a href="http://www.does--not--work.com">http://www.does--not--work.com</a> and more',
  291. ],
  292. [
  293. 'Text with a url http://www.not--work.com and more',
  294. 'Text with a url <a href="http://www.not--work.com">http://www.not--work.com</a> and more',
  295. ],
  296. [
  297. 'Text with a url http://www.sub_domain.domain.pl and more',
  298. 'Text with a url <a href="http://www.sub_domain.domain.pl">http://www.sub_domain.domain.pl</a> and more',
  299. ],
  300. [
  301. 'Text with a partial www.küchenschöhn-not-working.de URL',
  302. 'Text with a partial <a href="http://www.küchenschöhn-not-working.de">www.küchenschöhn-not-working.de</a> URL'
  303. ],
  304. [
  305. 'Text with a partial http://www.küchenschöhn-not-working.de URL',
  306. 'Text with a partial <a href="http://www.küchenschöhn-not-working.de">http://www.küchenschöhn-not-working.de</a> URL'
  307. ],
  308. ];
  309. }
  310. /**
  311. * testAutoLinkUrls method
  312. *
  313. * @dataProvider autoLinkProvider
  314. * @return void
  315. */
  316. public function testAutoLinkUrls($text, $expected)
  317. {
  318. $result = $this->Text->autoLinkUrls($text);
  319. $this->assertEquals($expected, $result);
  320. }
  321. /**
  322. * Test the options for autoLinkUrls
  323. *
  324. * @return void
  325. */
  326. public function testAutoLinkUrlsOptions()
  327. {
  328. $text = 'Text with a partial www.cakephp.org URL';
  329. $expected = 'Text with a partial <a href="http://www.cakephp.org" \s*class="link">www.cakephp.org</a> URL';
  330. $result = $this->Text->autoLinkUrls($text, ['class' => 'link']);
  331. $this->assertRegExp('#^' . $expected . '$#', $result);
  332. $text = 'Text with a partial WWW.cakephp.org &copy; URL';
  333. $expected = 'Text with a partial <a href="http://WWW.cakephp.org"\s*>WWW.cakephp.org</a> &copy; URL';
  334. $result = $this->Text->autoLinkUrls($text, ['escape' => false]);
  335. $this->assertRegExp('#^' . $expected . '$#', $result);
  336. }
  337. /**
  338. * Test autoLinkUrls with the escape option.
  339. *
  340. * @return void
  341. */
  342. public function testAutoLinkUrlsEscape()
  343. {
  344. $text = 'Text with a partial <a href="http://www.example.com">http://www.example.com</a> link';
  345. $expected = 'Text with a partial <a href="http://www.example.com">http://www.example.com</a> link';
  346. $result = $this->Text->autoLinkUrls($text, ['escape' => false]);
  347. $this->assertEquals($expected, $result);
  348. $text = 'Text with a partial <a href="http://www.example.com">www.example.com</a> link';
  349. $expected = 'Text with a partial <a href="http://www.example.com">www.example.com</a> link';
  350. $result = $this->Text->autoLinkUrls($text, ['escape' => false]);
  351. $this->assertEquals($expected, $result);
  352. $text = 'Text with a partial <a href="http://www.cakephp.org">link</a> link';
  353. $expected = 'Text with a partial <a href="http://www.cakephp.org">link</a> link';
  354. $result = $this->Text->autoLinkUrls($text, ['escape' => false]);
  355. $this->assertEquals($expected, $result);
  356. $text = 'Text with a partial <iframe src="http://www.cakephp.org" /> link';
  357. $expected = 'Text with a partial <iframe src="http://www.cakephp.org" /> link';
  358. $result = $this->Text->autoLinkUrls($text, ['escape' => false]);
  359. $this->assertEquals($expected, $result);
  360. $text = 'Text with a partial <iframe src="http://www.cakephp.org" /> link';
  361. $expected = 'Text with a partial &lt;iframe src=&quot;http://www.cakephp.org&quot; /&gt; link';
  362. $result = $this->Text->autoLinkUrls($text, ['escape' => true]);
  363. $this->assertEquals($expected, $result);
  364. $text = 'Text with a url <a href="http://www.not-working-www.com">www.not-working-www.com</a> and more';
  365. $expected = 'Text with a url &lt;a href=&quot;http://www.not-working-www.com&quot;&gt;www.not-working-www.com&lt;/a&gt; and more';
  366. $result = $this->Text->autoLinkUrls($text, ['escape' => true]);
  367. $this->assertEquals($expected, $result);
  368. $text = 'Text with a url www.not-working-www.com and more';
  369. $expected = 'Text with a url <a href="http://www.not-working-www.com">www.not-working-www.com</a> and more';
  370. $result = $this->Text->autoLinkUrls($text, ['escape' => false]);
  371. $this->assertEquals($expected, $result);
  372. $text = 'Text with a url http://www.not-working-www.com and more';
  373. $expected = 'Text with a url <a href="http://www.not-working-www.com">http://www.not-working-www.com</a> and more';
  374. $result = $this->Text->autoLinkUrls($text, ['escape' => false]);
  375. $this->assertEquals($expected, $result);
  376. $text = 'Text with a url http://www.www.not-working-www.com and more';
  377. $expected = 'Text with a url <a href="http://www.www.not-working-www.com">http://www.www.not-working-www.com</a> and more';
  378. $result = $this->Text->autoLinkUrls($text, ['escape' => false]);
  379. $this->assertEquals($expected, $result);
  380. }
  381. /**
  382. * Test autoLinkUrls with query strings.
  383. *
  384. * @return void
  385. */
  386. public function testAutoLinkUrlsQueryString()
  387. {
  388. $text = 'Text with a partial http://www.cakephp.org?product_id=123&foo=bar link';
  389. $expected = 'Text with a partial <a href="http://www.cakephp.org?product_id=123&amp;foo=bar">http://www.cakephp.org?product_id=123&amp;foo=bar</a> link';
  390. $result = $this->Text->autoLinkUrls($text);
  391. $this->assertEquals($expected, $result);
  392. }
  393. /**
  394. * Data provider for autoLinkEmail.
  395. *
  396. * @return void
  397. */
  398. public function autoLinkEmailProvider()
  399. {
  400. return [
  401. [
  402. 'This is a test text',
  403. 'This is a test text',
  404. ],
  405. [
  406. 'email@example.com address',
  407. '<a href="mailto:email@example.com">email@example.com</a> address',
  408. ],
  409. [
  410. 'email@example.com address',
  411. '<a href="mailto:email@example.com">email@example.com</a> address',
  412. ],
  413. [
  414. '(email@example.com) address',
  415. '(<a href="mailto:email@example.com">email@example.com</a>) address',
  416. ],
  417. [
  418. 'Text with email@example.com address',
  419. 'Text with <a href="mailto:email@example.com">email@example.com</a> address',
  420. ],
  421. [
  422. "Text with o'hare._-bob@example.com address",
  423. 'Text with <a href="mailto:o&#039;hare._-bob@example.com">o&#039;hare._-bob@example.com</a> address',
  424. ],
  425. [
  426. 'Text with düsentrieb@küchenschöhn-not-working.de address',
  427. 'Text with <a href="mailto:düsentrieb@küchenschöhn-not-working.de">düsentrieb@küchenschöhn-not-working.de</a> address',
  428. ],
  429. [
  430. 'Text with me@subdomain.küchenschöhn.de address',
  431. 'Text with <a href="mailto:me@subdomain.küchenschöhn.de">me@subdomain.küchenschöhn.de</a> address',
  432. ],
  433. [
  434. 'Text with email@example.com address',
  435. 'Text with <a href="mailto:email@example.com" class="link">email@example.com</a> address',
  436. ['class' => 'link'],
  437. ],
  438. [
  439. '<p>mark@example.com</p>',
  440. '<p><a href="mailto:mark@example.com">mark@example.com</a></p>',
  441. ['escape' => false]
  442. ],
  443. [
  444. 'Some&nbsp;mark@example.com&nbsp;Text',
  445. 'Some&nbsp;<a href="mailto:mark@example.com">mark@example.com</a>&nbsp;Text',
  446. ['escape' => false]
  447. ],
  448. ];
  449. }
  450. /**
  451. * testAutoLinkEmails method
  452. *
  453. * @param string $text The text to link
  454. * @param string $expected The expected results.
  455. * @dataProvider autoLinkEmailProvider
  456. * @return void
  457. */
  458. public function testAutoLinkEmails($text, $expected, $attrs = [])
  459. {
  460. $result = $this->Text->autoLinkEmails($text, $attrs);
  461. $this->assertEquals($expected, $result);
  462. }
  463. /**
  464. * test invalid email addresses.
  465. *
  466. * @return void
  467. */
  468. public function testAutoLinkEmailInvalid()
  469. {
  470. $result = $this->Text->autoLinkEmails('this is a myaddress@gmx-de test');
  471. $expected = 'this is a myaddress@gmx-de test';
  472. $this->assertEquals($expected, $result);
  473. }
  474. /**
  475. * testAutoParagraph method
  476. *
  477. * @return void
  478. */
  479. public function testAutoParagraph()
  480. {
  481. $text = 'This is a test text';
  482. $expected = <<<TEXT
  483. <p>This is a test text</p>
  484. TEXT;
  485. $result = $this->Text->autoParagraph($text);
  486. $text = 'This is a <br/> <BR> test text';
  487. $expected = <<<TEXT
  488. <p>This is a </p>
  489. <p> test text</p>
  490. TEXT;
  491. $result = $this->Text->autoParagraph($text);
  492. $this->assertTextEquals($expected, $result);
  493. $result = $this->Text->autoParagraph($text);
  494. $text = 'This is a <BR id="test"/><br class="test"> test text';
  495. $expected = <<<TEXT
  496. <p>This is a </p>
  497. <p> test text</p>
  498. TEXT;
  499. $result = $this->Text->autoParagraph($text);
  500. $this->assertTextEquals($expected, $result);
  501. $text = <<<TEXT
  502. This is a test text.
  503. This is a line return.
  504. TEXT;
  505. $expected = <<<TEXT
  506. <p>This is a test text.<br />
  507. This is a line return.</p>
  508. TEXT;
  509. $result = $this->Text->autoParagraph($text);
  510. $this->assertTextEquals($expected, $result);
  511. $text = <<<TEXT
  512. This is a test text.
  513. This is a new line.
  514. TEXT;
  515. $expected = <<<TEXT
  516. <p>This is a test text.</p>
  517. <p>This is a new line.</p>
  518. TEXT;
  519. $result = $this->Text->autoParagraph($text);
  520. $this->assertTextEquals($expected, $result);
  521. }
  522. }