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