Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 238 lines (220 sloc) 12.279 kb
45029b9 @quipo testsuite by Seth Price
quipo authored
1 <?php
ccfea67 @cweiske - We are not phpunit
cweiske authored
2 require_once "PHPUnit/Framework/TestCase.php";
45029b9 @quipo testsuite by Seth Price
quipo authored
3 require_once 'HTML/BBCodeParser.php';
4
babf153 @cweiske - Add AllTests.php so that pear run-tests can be used with phpunit
cweiske authored
5 class HTML_BBCodeParserTest extends PHPUnit_Framework_TestCase
45029b9 @quipo testsuite by Seth Price
quipo authored
6 {
3f81e9d @cweiske Make HTML_BBCodeParser tests nearly work from cvs
cweiske authored
7
9d0007c @helgi Add alt= into the Images attributes supported list.
helgi authored
8 function testFilters()
9 {
45029b9 @quipo testsuite by Seth Price
quipo authored
10 $bbc = new HTML_BBCodeParser(array('filters' => ''));
11 $bbc->addFilter('Basic');
12 $this->basicBBCode($bbc, 'qparse');
13 $bbc->removeFilter('Basic');
14 $this->assertEquals('[b]txt[/b]', $bbc->qparse('[b]txt[/b]'), 'Basic filters have been removed.');
15 $bbc->addFilters('Basic,Email');
16 $this->basicBBCode($bbc, 'qparse');
17 $this->emailBBCode($bbc, 'qparse');
18 }
19
9d0007c @helgi Add alt= into the Images attributes supported list.
helgi authored
20 function testQparse()
21 {
45029b9 @quipo testsuite by Seth Price
quipo authored
22 $bbc = new HTML_BBCodeParser(array('filters' => 'Basic,Email,Extended,Images,Links,Lists'));
ecac089 @helgi fix the author tag
helgi authored
23 $this->basicBBCode($bbc, 'qparse');
45029b9 @quipo testsuite by Seth Price
quipo authored
24 $this->listBBCode($bbc, 'qparse');
25 $this->linkBBCode($bbc, 'qparse');
26 $this->extBBCode($bbc, 'qparse');
27 $this->imgBBCode($bbc, 'qparse');
28 $this->emailBBCode($bbc, 'qparse');
29 }
30
9d0007c @helgi Add alt= into the Images attributes supported list.
helgi authored
31 function emailBBCode($bbc, $funcNam)
32 {
45029b9 @quipo testsuite by Seth Price
quipo authored
33 $this->assertEquals('<a href="mailto:guest@anonymous.org">guest@anonymous.org</a>', $bbc->$funcNam('guest@anonymous.org'));
34 $this->assertEquals('<a href="mailto:guest@anonymous.org">mail me</a>', $bbc->$funcNam('[email=guest@anonymous.org]mail me[/email]'));
35 $this->assertEquals('<a href="mailto:guest@anonymous.org">guest@anonymous.org</a>', $bbc->$funcNam('[email]guest@anonymous.org[/email]'));
36 }
37
9d0007c @helgi Add alt= into the Images attributes supported list.
helgi authored
38 function imgBBCode($bbc, $funcNam)
39 {
d83637c @CloCkWeRX Fix misc regression, test expectations
CloCkWeRX authored
40 $this->assertEquals('<img src="/images/Enthalpy Wheel.png" alt="Enthalpy Wheel" width="100" height="99" />', $bbc->$funcNam('[img w=100 h=99 alt=Enthalpy Wheel]/images/Enthalpy Wheel.png[/img]'));
41 $this->assertEquals('<img src="img.jpg" alt="" />', $bbc->$funcNam('[img]img.jpg[/img]'));
42 $this->assertEquals('<img src="http://www.server.org/image.jpg" alt="" width="100" height="200" />', $bbc->$funcNam('[img w=100 h=200]http://www.server.org/image.jpg[/img]'));
45029b9 @quipo testsuite by Seth Price
quipo authored
43 }
44
9d0007c @helgi Add alt= into the Images attributes supported list.
helgi authored
45 function basicBBCode($bbc, $funcNam)
46 {
45029b9 @quipo testsuite by Seth Price
quipo authored
47 $this->assertEquals('<strong>txt</strong>', $bbc->$funcNam('[b]txt[/b]'));
48 $this->assertEquals('<strong>txt</strong>', $bbc->$funcNam('[b]txt'));
49 $this->assertEquals('<em>txt</em>', $bbc->$funcNam('[i]txt[/i]'));
50 $this->assertEquals('<em>txt</em>', $bbc->$funcNam('[i]txt[/I]'));
51 $this->assertEquals('<em>txt</em>', $bbc->$funcNam('[I]txt[/i]'));
52 $this->assertEquals('<em>txt</em>', $bbc->$funcNam('[I]txt[/I]'));
53 $this->assertEquals('<del>txt</del>', $bbc->$funcNam('[s]txt[/s]'));
54 $this->assertEquals('<span style="text-decoration:underline;">txt</span>', $bbc->$funcNam('[u]txt[/u]'));
55 $this->assertEquals('<sub>txt</sub>', $bbc->$funcNam('[sub]txt[/sub]'));
56 $this->assertEquals('<sup>txt</sup>', $bbc->$funcNam('[sup]txt[/sup]'));
57 $this->assertEquals('<sup><sub>txt</sub></sup>', $bbc->$funcNam('[sup][sub]txt[/sup][/sub]'));
58 $this->assertEquals('<em><strong>txt</strong></em>', $bbc->$funcNam('[i][b]txt[/i][/b]'));
59 }
60
9d0007c @helgi Add alt= into the Images attributes supported list.
helgi authored
61 function listBBCode($bbc, $funcNam)
62 {
45029b9 @quipo testsuite by Seth Price
quipo authored
63 $this->assertEquals('<ul><li>txt</li></ul>', $bbc->$funcNam('[*]txt'));
64 $this->assertEquals("<ul><li>txt\n</li></ul>", $bbc->$funcNam("[ulist][*]txt\n[/ulist]"));
65 $this->assertEquals('<ul><li>txt</li></ul>', $bbc->$funcNam('[ulist]txt[/ulist]'));
66 $this->assertEquals('<ul><li><ul><li><ul><li>txt</li></ul></li></ul></li></ul>', $bbc->$funcNam('[ulist][ulist][ulist]txt'));
67 $this->assertEquals('<ul><li>[xxx]txt[/xxx]</li></ul>', $bbc->$funcNam('[ulist][xxx]txt[/xxx][/ulist]'));
68 $this->assertEquals('<ul><li>txt</li></ul>', $bbc->$funcNam('[ulist][li]txt[/li][/ulist]'));
69 $this->assertEquals('<ul><li>txt</li><li>txt</li></ul>', $bbc->$funcNam('[ulist][li]txt[li]txt[/ulist]'));
70 $this->assertEquals('<ul><li>txt</li></ul>', $bbc->$funcNam('[ulist][*]txt[/ulist]'));
71 $this->assertEquals('<ul><li><ol><li>txt</li></ol></li></ul>', $bbc->$funcNam('[ulist][*][list][*]txt[/ulist]'));
72 $this->assertEquals('<ol><li>txt</li></ol>', $bbc->$funcNam('[list][li]txt[/li][/list]'));
73 $this->assertEquals('<ul><li><ol><li>txt</li></ol></li></ul>', $bbc->$funcNam('[li][list][li]txt[/li][/list]'));
74 $this->assertEquals('<ul><li>txt<ul><li>txt</li></ul></li></ul>', $bbc->$funcNam('[*]txt[ulist]txt[/ulist]'));
75 $this->assertEquals('<ul><li><ul><li><ul><li><ul><li>txt</li></ul></li></ul></li></ul></li></ul>', $bbc->$funcNam('[li][ulist][ulist][ulist]txt'));
76 $this->assertEquals(
77 '<ol style="list-style-type:upper-alpha;"><li>ordered item 1, nested list:<ol style="list-style-type:upper-roman;"><li>nested item 1</li><li>nested item 2</li></ol></li><li>ordered item 2</li></ol>',
78 $bbc->$funcNam('[list=A s=3][li]ordered item 1, nested list:[list=I][li]nested item 1[/li][li]nested item 2[/li][/list][/li][li]ordered item 2[/li][/list]'));
79 $this->assertEquals(
80 '<ol style="list-style-type:upper-alpha;"><li>ordered item 1 type A</li><li>ordered item 12 type A</li></ol>',
81 $bbc->$funcNam('[list=A][li]ordered item 1 type A[/li][li=12]ordered item 12 type A[/li][/list]'));
82 $this->assertEquals(
83 '<ol style="list-style-type:lower-alpha;"><li>ordered item 5 type a</li><li>ordered item 6 type a</li></ol>',
84 $bbc->$funcNam('[list=a s=5][li]ordered item 5 type a[/li][*]ordered item 6 type a[/list]'));
85 $this->assertEquals(
86 '<ol style="list-style-type:upper-roman;"><li>ordered item 1 type I</li></ol>',
87 $bbc->$funcNam('[list=I][*]ordered item 1 type I[/list]'));
88 $this->assertEquals(
89 '<ol style="list-style-type:lower-roman;"><li>ordered item 1 type i</li><li>ordered item 4 type i</li></ol>',
90 $bbc->$funcNam('[list=i][*]ordered item 1 type i[li=4]ordered item 4 type i[/li][/list]'));
91 $this->assertEquals(
92 '<ol style="list-style-type:decimal;"><li>ordered item 1</li><li>ordered item 2</li></ol>',
93 $bbc->$funcNam('[list=1][*]ordered item 1[*]ordered item 2[/list]'));
ff8ecd1 @quipo added more tests
quipo authored
94 //Bug #512: [list] in a [list] breaks the first [list]
95 $this->assertEquals(
96 '<ol><li> Subject 1<ol><li> First</li><li> Second</li></ol></li><li> Subject 2</li></ol>',
97 $bbc->$funcNam('[list][*] Subject 1[list][*] First[*] Second[/list][*] Subject 2[/list]')
98 );
99 //Bug #1201: [list] output adding extra <li></li>
100 $this->assertEquals(
101 '<ol><li>txt</li></ol>',
102 $bbc->$funcNam('[list][*]txt[/list]')
103 );
9d0007c @helgi Add alt= into the Images attributes supported list.
helgi authored
104 //Bug#6335 Empty item displayed
105 $this->assertEquals(
106 '<ol style="list-style-type:decimal;"><li> Item one</li><li> Item two</li><li> Item three</li></ol>',
107 $bbc->$funcNam('[list=1][*] Item one[*] Item two[*] Item three[/list]'));
45029b9 @quipo testsuite by Seth Price
quipo authored
108 }
109
9d0007c @helgi Add alt= into the Images attributes supported list.
helgi authored
110 function linkBBCode($bbc, $funcNam)
111 {
45029b9 @quipo testsuite by Seth Price
quipo authored
112 $this->assertEquals(
113 '<a href="http://www.test.com/">http://www.test.com/</a>',
114 $bbc->$funcNam('http://www.test.com/'));
115 $this->assertEquals(
116 '<a href="http://www.test.com/">www.test.com</a>',
117 $bbc->$funcNam('[url]www.test.com[/url]'));
118 $this->assertEquals(
119 '<a href="http://www.test.com/testurl">http://www.test.com/testurl</a>',
120 $bbc->$funcNam('[url]http://www.test.com/testurl[/url]'));
121 $this->assertEquals(
122 '<a href="http://www.test.com/">testurl</a>',
123 $bbc->$funcNam('[url=www.test.com/]testurl[/url]'));
124 $this->assertEquals(
aea5815 @CloCkWeRX Bug #12644
CloCkWeRX authored
125 '<a href="http://www.server.org" target="new">server</a>',
45029b9 @quipo testsuite by Seth Price
quipo authored
126 $bbc->$funcNam('[url=http://www.server.org t=new]server[/url]'));
127 $this->assertEquals(
128 'txt <a href="http://www.test.com/">www.test.com</a> txt',
129 $bbc->$funcNam('txt www.test.com txt'));
130 $this->assertEquals(
ff8ecd1 @quipo added more tests
quipo authored
131 'txt (<a href="http://www.test.com/">www.test.com</a>) txt',
132 $bbc->$funcNam('txt (www.test.com) txt'));
133 $this->assertEquals(
134 'txt <a href="http://www.test.com/test.php?a=1,2">www.test.com/test.php?a=1,2</a>, txt',
135 $bbc->$funcNam('txt www.test.com/test.php?a=1,2, txt'));
136 $this->assertEquals(
137 'txt <a href="http://www.test.com/">www.test.com</a>, txt',
138 $bbc->$funcNam('txt www.test.com, txt'));
139 $this->assertEquals(
140 'txt <a href="http://www.test.com/">http://www.test.com</a>: txt',
141 $bbc->$funcNam('txt http://www.test.com: txt'));
142 $this->assertEquals(
143 'txt <a href="http://www.test.com/">www.test.com</a>; txt',
144 $bbc->$funcNam('txt www.test.com; txt'));
145 //Bug #1755: tags around an url -> mess
146 $this->assertEquals(
45029b9 @quipo testsuite by Seth Price
quipo authored
147 'txt <em><a href="http://www.test.com/">www.test.com</a></em> txt',
148 $bbc->$funcNam('txt [i]www.test.com[/i] txt'));
ff8ecd1 @quipo added more tests
quipo authored
149 //Bug #1512: URL Tags Allow Javascript injection
45029b9 @quipo testsuite by Seth Price
quipo authored
150 $this->assertEquals(
151 'Click here',
152 $bbc->$funcNam('[url=javascript:location.replace("bad_link");]Click here[/url]'));
153 $this->assertEquals(
ff8ecd1 @quipo added more tests
quipo authored
154 '<a href="http://domain.com/index.php?i=1&amp;j=2">linked text</a>',
155 $bbc->$funcNam('[url=http://domain.com/index.php?i=1&j=2]linked text[/URL]'));
f9c7a3d @cweiske Replace & with &amp; to make valid html, fixing another unit test fai…
cweiske authored
156 $this->assertEquals(
157 '<a href="http://domain.com/index.php?i=1&amp;j=2">linked text</a>',
158 $bbc->$funcNam('[url=http://domain.com/index.php?i=1&amp;j=2]linked text[/URL]'));
ff8ecd1 @quipo added more tests
quipo authored
159 //Bug #5609: BBCodeParser allows XSS
160 $this->assertEquals(
a0243c7 @cweiske Fix all those nasty xss and javascript injection by htmlspecialchar()ing
cweiske authored
161 '<a href="javascript&amp;#058;//%0ASh=alert(%22CouCou%22);window.close();">Alert box with "CouCou"</a>',
ff8ecd1 @quipo added more tests
quipo authored
162 $bbc->$funcNam('[url=javascript://%0ASh=alert(%22CouCou%22);window.close();]Alert box with "CouCou"[/url]')
163 );
164 /*
165 //Request #4936: Nested URLs in quotes not handled
166 $this->assertEquals(
167 '<q>Quoted text</q>', //?!?!?
168 $bbc->$funcNam('[quote="[url=http://somewhere.com]URL-Title[/url]"]Quoted text[/quote]')
169 );
170 */
45029b9 @quipo testsuite by Seth Price
quipo authored
171 }
172
9d0007c @helgi Add alt= into the Images attributes supported list.
helgi authored
173 function extBBCode($bbc, $funcNam)
174 {
45029b9 @quipo testsuite by Seth Price
quipo authored
175 $this->assertEquals('<h2>txt</h2>', $bbc->$funcNam('[h2]txt[/h2]'));
176 $this->assertEquals('<span style="color:blue">blue text</span>', $bbc->$funcNam('[color=blue]blue text[/color]'));
177 $this->assertEquals('<span style="font-size:18pt">the size of this text is 18pt</span>', $bbc->$funcNam('[size=18]the size of this text is 18pt[/size]'));
178 $this->assertEquals('<span style="font-family:arial">different font type</span>', $bbc->$funcNam('[font=arial]different font type[/font]'));
179 $this->assertEquals('<div style="text-align:right">yes, you\'re right, this isn\'t on the left</div>', $bbc->$funcNam('[align=right]yes, you\'re right, this isn\'t on the left[/align]'));
180 $this->assertEquals('he said: <q cite="http://www.server.org/quote.html">i\'m tony montana</q>', $bbc->$funcNam('he said: [quote=http://www.server.org/quote.html]i\'m tony montana[/quote]'));
181 $this->assertEquals('<code>x + y = 6;</code>', $bbc->$funcNam('[code]x + y = 6;[/code]'));
ff8ecd1 @quipo added more tests
quipo authored
182 //Bug #1258: Extra tags rendered with faulty BBCode
183 $this->assertEquals(
184 '<span style="font-family:Verdana"><span style="color:red">my name NeverMind!</span></span>',
185 $bbc->$funcNam('[font=Verdana][color=red]my name NeverMind![/font][/color]')
186 );
187 //Bug #1979: Whitespaces in attribute are breaking it
188 $this->assertEquals(
189 '<span style="font-family:Comic Sans MS">txt</span>',
190 $bbc->$funcNam('[font=Comic Sans MS]txt[/font]')
191 );
192 //Bug #4844: Arbitrary HTML injection
193 $this->assertEquals(
a0243c7 @cweiske Fix all those nasty xss and javascript injection by htmlspecialchar()ing
cweiske authored
194 '<div style="text-align:foo&quot;&gt;&lt;script&gt;alert(\'JavaScript_Enabled\');&lt;/script&gt;"></div>',
ff8ecd1 @quipo added more tests
quipo authored
195 $bbc->$funcNam('[align=foo"><script>alert(\'JavaScript_Enabled\');</script>][/align]')
196 );
45029b9 @quipo testsuite by Seth Price
quipo authored
197 }
50a7336 @cweiske Verifying Bug #11400: Lists start with an empty listitem
cweiske authored
198
199
200
f9c7a3d @cweiske Replace & with &amp; to make valid html, fixing another unit test fai…
cweiske authored
201 /**
202 * An empty <li> had been included for the first space
203 */
50a7336 @cweiske Verifying Bug #11400: Lists start with an empty listitem
cweiske authored
204 function testBug11400()
205 {
206 $bbc = new HTML_BBCodeParser(array('filters' => ''));
207 $bbc->addFilter('Lists');
208
209 //this works
210 $this->assertEquals('<ul><li>one</li><li>two</li></ul>',
211 $bbc->qparse("[ulist][*]one[*]two[/ulist]")
212 );
213 //this not
214 $this->assertEquals('<ul><li>one</li><li>two</li></ul>',
215 $bbc->qparse("[ulist] [*]one[*]two[/ulist]")
216 );
217 //this not
218 $this->assertEquals('<ol><li>one</li><li>two</li></ol>',
219 $bbc->qparse("[list] [*]one[*]two[/list]")
220 );
221 }
61d3077 @cweiske Verifying Bug #11370: img don't like '='
cweiske authored
222
223
224
f9c7a3d @cweiske Replace & with &amp; to make valid html, fixing another unit test fai…
cweiske authored
225 /**
226 * img tags didn't like = in url
227 */
61d3077 @cweiske Verifying Bug #11370: img don't like '='
cweiske authored
228 function testBug11370()
229 {
230 $bbc = new HTML_BBCodeParser(array('filters' => ''));
231 $bbc->addFilter('Images');
232
e793a4a @CloCkWeRX Update test expectations
CloCkWeRX authored
233 $this->assertEquals('<img src="admin.php?fs=image" alt="" />',
61d3077 @cweiske Verifying Bug #11370: img don't like '='
cweiske authored
234 $bbc->qparse("[img]admin.php?fs=image[/img]")
235 );
236 }
45029b9 @quipo testsuite by Seth Price
quipo authored
237 }
Something went wrong with that request. Please try again.