Fix autoparagraph bug with non-inline elements.
[htmlpurifier.git] / tests / HTMLPurifier / Strategy / ValidateAttributesTest.php
blob5fc86cbdab306cf614fd2a1fa6b2fd9430bbb787
1 <?php
3 class HTMLPurifier_Strategy_ValidateAttributesTest extends
4 HTMLPurifier_StrategyHarness
7 function setUp() {
8 parent::setUp();
9 $this->obj = new HTMLPurifier_Strategy_ValidateAttributes();
12 function testEmptyInput() {
13 $this->assertResult('');
16 function testRemoveIDByDefault() {
17 $this->assertResult(
18 '<div id="valid">Kill the ID.</div>',
19 '<div>Kill the ID.</div>'
23 function testRemoveInvalidDir() {
24 $this->assertResult(
25 '<span dir="up-to-down">Bad dir.</span>',
26 '<span>Bad dir.</span>'
30 function testPreserveValidClass() {
31 $this->assertResult('<div class="valid">Valid</div>');
34 function testSelectivelyRemoveInvalidClasses() {
35 $this->config->set('HTML.Doctype', 'XHTML 1.1');
36 $this->assertResult(
37 '<div class="valid 0invalid">Keep valid.</div>',
38 '<div class="valid">Keep valid.</div>'
42 function testPreserveTitle() {
43 $this->assertResult(
44 '<acronym title="PHP: Hypertext Preprocessor">PHP</acronym>'
48 function testAddXMLLang() {
49 $this->assertResult(
50 '<span lang="fr">La soupe.</span>',
51 '<span lang="fr" xml:lang="fr">La soupe.</span>'
55 function testOnlyXMLLangInXHTML11() {
56 $this->config->set('HTML.Doctype', 'XHTML 1.1');
57 $this->assertResult(
58 '<b lang="en">asdf</b>',
59 '<b xml:lang="en">asdf</b>'
63 function testBasicURI() {
64 $this->assertResult('<a href="http://www.google.com/">Google</a>');
67 function testInvalidURI() {
68 $this->assertResult(
69 '<a href="javascript:badstuff();">Google</a>',
70 '<a>Google</a>'
74 function testBdoAddMissingDir() {
75 $this->assertResult(
76 '<bdo>Go left.</bdo>',
77 '<bdo dir="ltr">Go left.</bdo>'
81 function testBdoReplaceInvalidDirWithDefault() {
82 $this->assertResult(
83 '<bdo dir="blahblah">Invalid value!</bdo>',
84 '<bdo dir="ltr">Invalid value!</bdo>'
88 function testBdoAlternateDefaultDir() {
89 $this->config->set('Attr.DefaultTextDir', 'rtl');
90 $this->assertResult(
91 '<bdo>Go right.</bdo>',
92 '<bdo dir="rtl">Go right.</bdo>'
96 function testRemoveDirWhenNotRequired() {
97 $this->assertResult(
98 '<span dir="blahblah">Invalid value!</span>',
99 '<span>Invalid value!</span>'
103 function testTableAttributes() {
104 $this->assertResult(
105 '<table frame="above" rules="rows" summary="A test table" border="2" cellpadding="5%" cellspacing="3" width="100%">
106 <col align="right" width="4*" />
107 <col charoff="5" align="char" width="*" />
108 <tr valign="top">
109 <th abbr="name">Fiddly name</th>
110 <th abbr="price">Super-duper-price</th>
111 </tr>
112 <tr>
113 <td abbr="carrot">Carrot Humungous</td>
114 <td>$500.23</td>
115 </tr>
116 <tr>
117 <td colspan="2">Taken off the market</td>
118 </tr>
119 </table>'
123 function testColSpanIsNonZero() {
124 $this->assertResult(
125 '<col span="0" />',
126 '<col />'
130 function testImgAddDefaults() {
131 $this->config->set('Core.RemoveInvalidImg', false);
132 $this->assertResult(
133 '<img />',
134 '<img src="" alt="Invalid image" />'
138 function testImgGenerateAlt() {
139 $this->assertResult(
140 '<img src="foobar.jpg" />',
141 '<img src="foobar.jpg" alt="foobar.jpg" />'
145 function testImgAddDefaultSrc() {
146 $this->config->set('Core.RemoveInvalidImg', false);
147 $this->assertResult(
148 '<img alt="pretty picture" />',
149 '<img alt="pretty picture" src="" />'
153 function testImgRemoveNonRetrievableProtocol() {
154 $this->config->set('Core.RemoveInvalidImg', false);
155 $this->assertResult(
156 '<img src="mailto:foo@example.com" />',
157 '<img alt="mailto:foo@example.com" src="" />'
161 function testPreserveRel() {
162 $this->config->set('Attr.AllowedRel', 'nofollow');
163 $this->assertResult('<a href="foo" rel="nofollow" />');
166 function testPreserveTarget() {
167 $this->config->set('Attr.AllowedFrameTargets', '_top');
168 $this->config->set('HTML.Doctype', 'XHTML 1.0 Transitional');
169 $this->assertResult('<a href="foo" target="_top" />');
172 function testRemoveTargetWhenNotSupported() {
173 $this->config->set('HTML.Doctype', 'XHTML 1.0 Strict');
174 $this->config->set('Attr.AllowedFrameTargets', '_top');
175 $this->assertResult(
176 '<a href="foo" target="_top" />',
177 '<a href="foo" />'
181 function testKeepAbsoluteCSSWidthAndHeightOnImg() {
182 $this->assertResult(
183 '<img src="" alt="" style="width:10px;height:10px;border:1px solid #000;" />'
187 function testRemoveLargeCSSWidthAndHeightOnImg() {
188 $this->assertResult(
189 '<img src="" alt="" style="width:10000000px;height:10000000px;border:1px solid #000;" />',
190 '<img src="" alt="" style="border:1px solid #000;" />'
194 function testRemoveLargeCSSWidthAndHeightOnImgWithUserConf() {
195 $this->config->set('CSS.MaxImgLength', '1px');
196 $this->assertResult(
197 '<img src="" alt="" style="width:1mm;height:1mm;border:1px solid #000;" />',
198 '<img src="" alt="" style="border:1px solid #000;" />'
202 function testKeepLargeCSSWidthAndHeightOnImgWhenToldTo() {
203 $this->config->set('CSS.MaxImgLength', null);
204 $this->assertResult(
205 '<img src="" alt="" style="width:10000000px;height:10000000px;border:1px solid #000;" />'
209 function testKeepPercentCSSWidthAndHeightOnImgWhenToldTo() {
210 $this->config->set('CSS.MaxImgLength', null);
211 $this->assertResult(
212 '<img src="" alt="" style="width:100%;height:100%;border:1px solid #000;" />'
216 function testRemoveRelativeCSSWidthAndHeightOnImg() {
217 $this->assertResult(
218 '<img src="" alt="" style="width:10em;height:10em;border:1px solid #000;" />',
219 '<img src="" alt="" style="border:1px solid #000;" />'
223 function testRemovePercentCSSWidthAndHeightOnImg() {
224 $this->assertResult(
225 '<img src="" alt="" style="width:100%;height:100%;border:1px solid #000;" />',
226 '<img src="" alt="" style="border:1px solid #000;" />'
232 // vim: et sw=4 sts=4