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