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