TextHelperTest.php 23 KB

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