TextHelperTest.php 23 KB

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