3 class HTMLPurifier_Strategy_ValidateAttributesTest
extends
4 HTMLPurifier_StrategyHarness
9 $this->obj
= new HTMLPurifier_Strategy_ValidateAttributes();
12 function testEmptyInput() {
13 $this->assertResult('');
16 function testRemoveIDByDefault() {
18 '<div id="valid">Kill the ID.</div>',
19 '<div>Kill the ID.</div>'
23 function testRemoveInvalidDir() {
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');
37 '<div class="valid 0invalid">Keep valid.</div>',
38 '<div class="valid">Keep valid.</div>'
42 function testPreserveTitle() {
44 '<acronym title="PHP: Hypertext Preprocessor">PHP</acronym>'
48 function testAddXMLLang() {
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');
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() {
69 '<a href="javascript:badstuff();">Google</a>',
74 function testBdoAddMissingDir() {
76 '<bdo>Go left.</bdo>',
77 '<bdo dir="ltr">Go left.</bdo>'
81 function testBdoReplaceInvalidDirWithDefault() {
83 '<bdo dir="blahblah">Invalid value!</bdo>',
84 '<bdo dir="ltr">Invalid value!</bdo>'
88 function testBdoAlternateDefaultDir() {
89 $this->config
->set('Attr.DefaultTextDir', 'rtl');
91 '<bdo>Go right.</bdo>',
92 '<bdo dir="rtl">Go right.</bdo>'
96 function testRemoveDirWhenNotRequired() {
98 '<span dir="blahblah">Invalid value!</span>',
99 '<span>Invalid value!</span>'
103 function testTableAttributes() {
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="*" />
109 <th abbr="name">Fiddly name</th>
110 <th abbr="price">Super-duper-price</th>
113 <td abbr="carrot">Carrot Humungous</td>
117 <td colspan="2">Taken off the market</td>
123 function testColSpanIsNonZero() {
130 function testImgAddDefaults() {
131 $this->config
->set('Core.RemoveInvalidImg', false);
134 '<img src="" alt="Invalid image" />'
138 function testImgGenerateAlt() {
140 '<img src="foobar.jpg" />',
141 '<img src="foobar.jpg" alt="foobar.jpg" />'
145 function testImgAddDefaultSrc() {
146 $this->config
->set('Core.RemoveInvalidImg', false);
148 '<img alt="pretty picture" />',
149 '<img alt="pretty picture" src="" />'
153 function testImgRemoveNonRetrievableProtocol() {
154 $this->config
->set('Core.RemoveInvalidImg', false);
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');
176 '<a href="foo" target="_top" />',
181 function testKeepAbsoluteCSSWidthAndHeightOnImg() {
183 '<img src="" alt="" style="width:10px;height:10px;border:1px solid #000;" />'
187 function testRemoveLargeCSSWidthAndHeightOnImg() {
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');
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);
205 '<img src="" alt="" style="width:10000000px;height:10000000px;border:1px solid #000;" />'
209 function testKeepPercentCSSWidthAndHeightOnImgWhenToldTo() {
210 $this->config
->set('CSS.MaxImgLength', null);
212 '<img src="" alt="" style="width:100%;height:100%;border:1px solid #000;" />'
216 function testRemoveRelativeCSSWidthAndHeightOnImg() {
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() {
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