Merge pull request #7661 from agileware/crm-17848
[civicrm-core.git] / tests / phpunit / CRM / Utils / HtmlToTextTest.php
1 <?php
2
3 /**
4 * Class CRM_Utils_HtmlToTextTest
5 */
6 class CRM_Utils_HtmlToTextTest extends CiviUnitTestCase {
7
8 public function setUp() {
9 parent::setUp();
10 }
11
12 /**
13 * @return array
14 */
15 public function htmlToTextExamples() {
16 $cases = array(); // array(0 => string $html, 1 => string $text)
17
18 $cases[] = array(
19 '<br/><p>',
20 '',
21 );
22
23 $cases[] = array(
24 "\n<p>\n" .
25 "This is a paragraph with <b>Bold</b> and <i>italics</i>\n" .
26 "Also some <a href=\"http://www.example.com\">hrefs</a> and a\n" .
27 "few <mailto:\"info@example.org\">mailto</mailto> tags.\n" .
28 "This is also a really long long line\n" .
29 "\n",
30 "This is a paragraph with BOLD and _italics_ Also some hrefs [1] and a few\n" .
31 "mailto tags. This is also a really long long line\n" .
32 "\n" .
33 "Links:\n" .
34 "------\n" .
35 "[1] http://www.example.com\n" .
36 "",
37 );
38
39 $cases[] = array(
40 "<p>\nA <a href=\"{action.do_something}\">token</a>\nis not treated as a relative URL",
41 "A token [1] is not treated as a relative URL\n" .
42 "\n" .
43 "Links:\n" .
44 "------\n" .
45 "[1] {action.do_something}\n",
46 );
47
48 return $cases;
49 }
50
51 /**
52 * @param string $html
53 * Example HTML input.
54 * @param string $text
55 * Expected text output.
56 * @dataProvider htmlToTextExamples
57 */
58 public function testHtmlToText($html, $text) {
59 $output = CRM_Utils_String::htmlToText($html);
60 $this->assertEquals(
61 trim($output),
62 trim($text),
63 "Text Output did not match for $html"
64 );
65 }
66
67 }