TextHelperTest.php 23 KB

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