Merge pull request #4818 from pratikshad/CRM-15770
[civicrm-core.git] / tests / phpunit / CRM / Utils / HtmlToTextTest.php
1 <?php
2
3 require_once 'CiviTest/CiviUnitTestCase.php';
4
5 /**
6 * Class CRM_Utils_HtmlToTextTest
7 */
8 class CRM_Utils_HtmlToTextTest extends CiviUnitTestCase {
9 protected $_testInput = array(
10 '<br><p>' => '', // empty test
11 '
12 <p>
13 This is a paragraph with <b>Bold</b> and <i>italics</i>
14 Also some <a href="http://www.example.com">hrefs</a> and a
15 few <mailto:"info@example.org">mailto</mailto> tags.
16 This is also a really long long line' => '
17 This is a paragraph with BOLD and _italics_ Also some hrefs [1] and a few
18 mailto tags. This is also a really long long line
19
20 Links:
21 ------
22 [1] http://www.example.com
23 ',
24 '
25 <p>
26 A <a href="{action.do_something}">token</a>
27 is not treated as a relative URL' => '
28 A token [1] is not treated as a relative URL
29
30 Links:
31 ------
32 [1] {action.do_something}
33 ',
34 );
35
36 public function setUp() {
37 parent::setUp();
38 }
39
40 public function testHtmlToText() {
41 foreach ($this->_testInput as $html => $text) {
42 $output = CRM_Utils_String::htmlToText($html);
43 $this->assertEquals(
44 trim($output),
45 trim($text),
46 "Text Output did not match for $html"
47 );
48 }
49 }
50 }