commit | author | age
|
6084d7
|
1 |
<?php |
A |
2 |
|
|
3 |
/** |
66afd7
|
4 |
* Test class to test rcube_html2text class |
6084d7
|
5 |
* |
A |
6 |
* @package Tests |
|
7 |
*/ |
66afd7
|
8 |
class rc_html2text extends PHPUnit_Framework_TestCase |
6084d7
|
9 |
{ |
A |
10 |
|
4bb0bf
|
11 |
function data_html2text() |
6084d7
|
12 |
{ |
e82492
|
13 |
return array( |
6084d7
|
14 |
0 => array( |
A |
15 |
'title' => 'Test entry', |
|
16 |
'in' => '', |
|
17 |
'out' => '', |
|
18 |
), |
|
19 |
1 => array( |
|
20 |
'title' => 'Basic HTML entities', |
|
21 |
'in' => '"&', |
|
22 |
'out' => '"&', |
|
23 |
), |
|
24 |
2 => array( |
|
25 |
'title' => 'HTML entity string', |
|
26 |
'in' => '&quot;', |
|
27 |
'out' => '"', |
|
28 |
), |
b138a9
|
29 |
3 => array( |
A |
30 |
'title' => 'HTML entity in STRONG tag', |
|
31 |
'in' => '<strong>ś</strong>', // ś |
|
32 |
'out' => 'Ś', // upper ś |
|
33 |
), |
|
34 |
4 => array( |
|
35 |
'title' => 'STRONG tag to upper-case conversion', |
|
36 |
'in' => '<strong>ś</strong>', |
|
37 |
'out' => 'Ś', |
|
38 |
), |
63f23f
|
39 |
5 => array( |
A |
40 |
'title' => 'STRONG inside B tag', |
|
41 |
'in' => '<b><strong>ś</strong></b>', |
|
42 |
'out' => 'Ś', |
|
43 |
), |
59b765
|
44 |
6 => array( |
AM |
45 |
'title' => 'Don\'t remove non-printable chars', |
|
46 |
'in' => chr(0x002).chr(0x003), |
|
47 |
'out' => chr(0x002).chr(0x003), |
|
48 |
), |
53cbeb
|
49 |
7 => array( |
AM |
50 |
'title' => 'Remove spaces after <br>', |
|
51 |
'in' => 'test<br> test', |
|
52 |
'out' => "test\ntest", |
|
53 |
), |
25c8fe
|
54 |
8 => array( |
AM |
55 |
'title' => ' handling test', |
|
56 |
'in' => '<div>eye: test<br /> tes: test</div>', |
|
57 |
'out' => "eye: test\ntes: test", |
|
58 |
), |
6084d7
|
59 |
); |
A |
60 |
} |
|
61 |
|
e82492
|
62 |
/** |
4bb0bf
|
63 |
* @dataProvider data_html2text |
e82492
|
64 |
*/ |
AM |
65 |
function test_html2text($title, $in, $out) |
|
66 |
{ |
66afd7
|
67 |
$ht = new rcube_html2text(null, false, false); |
e82492
|
68 |
|
AM |
69 |
$ht->set_html($in); |
|
70 |
$res = $ht->get_text(); |
|
71 |
|
|
72 |
$this->assertEquals($out, $res, $title); |
|
73 |
} |
bb6f4b
|
74 |
|
TB |
75 |
/** |
|
76 |
* |
|
77 |
*/ |
|
78 |
function test_multiple_blockquotes() |
|
79 |
{ |
|
80 |
$html = <<<EOF |
|
81 |
<br>Begin<br><blockquote>OUTER BEGIN<blockquote>INNER 1<br></blockquote><div><br></div><div>Par 1</div> |
|
82 |
<blockquote>INNER 2</blockquote><div><br></div><div>Par 2</div> |
|
83 |
<div><br></div><div>Par 3</div><div><br></div> |
|
84 |
<blockquote>INNER 3</blockquote>OUTER END</blockquote> |
|
85 |
EOF; |
|
86 |
$ht = new rcube_html2text($html, false, false); |
|
87 |
$res = $ht->get_text(); |
|
88 |
|
|
89 |
$this->assertContains('>> INNER 1', $res, 'Quote inner'); |
|
90 |
$this->assertContains('>> INNER 3', $res, 'Quote inner'); |
|
91 |
$this->assertContains('> OUTER END', $res, 'Quote outer'); |
|
92 |
} |
eecd9c
|
93 |
|
TB |
94 |
function test_broken_blockquotes() |
|
95 |
{ |
|
96 |
// no end tag |
|
97 |
$html = <<<EOF |
|
98 |
Begin<br> |
|
99 |
<blockquote>QUOTED TEXT |
|
100 |
<blockquote> |
|
101 |
NO END TAG FOUND |
|
102 |
EOF; |
|
103 |
$ht = new rcube_html2text($html, false, false); |
|
104 |
$res = $ht->get_text(); |
|
105 |
|
|
106 |
$this->assertContains('QUOTED TEXT NO END TAG FOUND', $res, 'No quoating on invalid html'); |
|
107 |
|
|
108 |
// with some (nested) end tags |
|
109 |
$html = <<<EOF |
|
110 |
Begin<br> |
|
111 |
<blockquote>QUOTED TEXT |
|
112 |
<blockquote>INNER 1</blockquote> |
|
113 |
<blockquote>INNER 2</blockquote> |
|
114 |
NO END TAG FOUND |
|
115 |
EOF; |
|
116 |
$ht = new rcube_html2text($html, false, false); |
|
117 |
$res = $ht->get_text(); |
|
118 |
|
|
119 |
$this->assertContains('QUOTED TEXT INNER 1 INNER 2 NO END', $res, 'No quoating on invalid html'); |
|
120 |
} |
ff4068
|
121 |
|
AM |
122 |
function test_links() |
|
123 |
{ |
|
124 |
$html = '<a href="http://test.com">content</a>'; |
|
125 |
$expected = 'content [1] |
|
126 |
|
|
127 |
Links: |
|
128 |
------ |
|
129 |
[1] http://test.com |
|
130 |
'; |
|
131 |
|
|
132 |
$ht = new rcube_html2text($html, false, true); |
|
133 |
$res = $ht->get_text(); |
|
134 |
|
|
135 |
$this->assertSame($expected, $res, 'Links list'); |
|
136 |
|
|
137 |
// href == content (#1490434) |
|
138 |
$html = '<a href="http://test.com">http://test.com</a>'; |
|
139 |
$expected = 'http://test.com'; |
|
140 |
|
|
141 |
$ht = new rcube_html2text($html, false, true); |
|
142 |
$res = $ht->get_text(); |
|
143 |
|
|
144 |
$this->assertSame($expected, $res, 'Skip link with href == content'); |
|
145 |
} |
6084d7
|
146 |
} |