Merge remote-tracking branch 'upstream/4.5' into 4.5-master-2015-01-26-14-28-00
[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
10 public function setUp() {
11 parent::setUp();
12 }
13
14 public function htmlToTextExamples() {
15 $cases = array(); // array(0 => string $html, 1 => string $text)
16
17 $cases[] = array(
18 '<br/><p>',
19 '',
20 );
21
22 $cases[] = array(
23 "\n<p>\n" .
24 "This is a paragraph with <b>Bold</b> and <i>italics</i>\n" .
25 "Also some <a href=\"http://www.example.com\">hrefs</a> and a\n" .
26 "few <mailto:\"info@example.org\">mailto</mailto> tags.\n" .
27 "This is also a really long long line\n" .
28 "\n",
29 "This is a paragraph with BOLD and _italics_ Also some hrefs [1] and a few\n" .
30 "mailto tags. This is also a really long long line\n" .
31 "\n" .
32 "Links:\n" .
33 "------\n" .
34 "[1] http://www.example.com\n" .
35 "",
36 );
37
38 $cases[] = array(
39 "<p>\nA <a href=\"{action.do_something}\">token</a>\nis not treated as a relative URL",
40 "A token [1] is not treated as a relative URL\n" .
41 "\n" .
42 "Links:\n" .
43 "------\n" .
44 "[1] {action.do_something}\n",
45 );
46
47 return $cases;
48 }
49
50 /**
51 * @param string $html
52 * Example HTML input.
53 * @param string $text
54 * Expected text output.
55 * @dataProvider htmlToTextExamples
56 */
57 public function testHtmlToText($html, $text) {
58 $output = CRM_Utils_String::htmlToText($html);
59 $this->assertEquals(
60 trim($output),
61 trim($text),
62 "Text Output did not match for $html"
63 );
64 }
65
66 }