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() {
36 '<div class="valid 0invalid">Keep valid.</div>',
37 '<div class="valid">Keep valid.</div>'
41 function testPreserveTitle() {
43 '<acronym title="PHP: Hypertext Preprocessor">PHP</acronym>'
47 function testAddXMLLang() {
49 '<span lang="fr">La soupe.</span>',
50 '<span lang="fr" xml:lang="fr">La soupe.</span>'
54 function testOnlyXMLLangInXHTML11() {
55 $this->config
->set('HTML', 'Doctype', 'XHTML 1.1');
57 '<b lang="en">asdf</b>',
58 '<b xml:lang="en">asdf</b>'
62 function testBasicURI() {
63 $this->assertResult('<a href="http://www.google.com/">Google</a>');
66 function testInvalidURI() {
68 '<a href="javascript:badstuff();">Google</a>',
73 function testBdoAddMissingDir() {
75 '<bdo>Go left.</bdo>',
76 '<bdo dir="ltr">Go left.</bdo>'
80 function testBdoReplaceInvalidDirWithDefault() {
82 '<bdo dir="blahblah">Invalid value!</bdo>',
83 '<bdo dir="ltr">Invalid value!</bdo>'
87 function testBdoAlternateDefaultDir() {
88 $this->config
->set('Attr', 'DefaultTextDir', 'rtl');
90 '<bdo>Go right.</bdo>',
91 '<bdo dir="rtl">Go right.</bdo>'
95 function testRemoveDirWhenNotRequired() {
97 '<span dir="blahblah">Invalid value!</span>',
98 '<span>Invalid value!</span>'
102 function testTableAttributes() {
104 '<table frame="above" rules="rows" summary="A test table" border="2" cellpadding="5%" cellspacing="3" width="100%">
105 <col align="right" width="4*" />
106 <col charoff="5" align="char" width="*" />
108 <th abbr="name">Fiddly name</th>
109 <th abbr="price">Super-duper-price</th>
112 <td abbr="carrot">Carrot Humungous</td>
116 <td colspan="2">Taken off the market</td>
122 function testColSpanIsNonZero() {
129 function testImgAddDefaults() {
130 $this->config
->set('Core', 'RemoveInvalidImg', false);
133 '<img src="" alt="Invalid image" />'
137 function testImgGenerateAlt() {
139 '<img src="foobar.jpg" />',
140 '<img src="foobar.jpg" alt="foobar.jpg" />'
144 function testImgAddDefaultSrc() {
145 $this->config
->set('Core', 'RemoveInvalidImg', false);
147 '<img alt="pretty picture" />',
148 '<img alt="pretty picture" src="" />'
152 function testImgRemoveNonRetrievableProtocol() {
153 $this->config
->set('Core', 'RemoveInvalidImg', false);
155 '<img src="mailto:foo@example.com" />',
156 '<img alt="mailto:foo@example.com" src="" />'
160 function testPreserveRel() {
161 $this->config
->set('Attr', 'AllowedRel', 'nofollow');
162 $this->assertResult('<a href="foo" rel="nofollow" />');
165 function testPreserveTarget() {
166 $this->config
->set('Attr', 'AllowedFrameTargets', '_top');
167 $this->config
->set('HTML', 'Doctype', 'XHTML 1.0 Transitional');
168 $this->assertResult('<a href="foo" target="_top" />');
171 function testRemoveTargetWhenNotSupported() {
172 $this->config
->set('HTML', 'Doctype', 'XHTML 1.0 Strict');
173 $this->config
->set('Attr', 'AllowedFrameTargets', '_top');
175 '<a href="foo" target="_top" />',
180 function testKeepAbsoluteCSSWidthAndHeightOnImg() {
182 '<img src="" alt="" style="width:10px;height:10px;border:1px solid #000;" />'
186 function testRemoveLargeCSSWidthAndHeightOnImg() {
188 '<img src="" alt="" style="width:10000000px;height:10000000px;border:1px solid #000;" />',
189 '<img src="" alt="" style="border:1px solid #000;" />'
193 function testRemoveLargeCSSWidthAndHeightOnImgWithUserConf() {
194 $this->config
->set('CSS', 'MaxImgLength', '1px');
196 '<img src="" alt="" style="width:1mm;height:1mm;border:1px solid #000;" />',
197 '<img src="" alt="" style="border:1px solid #000;" />'
201 function testKeepLargeCSSWidthAndHeightOnImgWhenToldTo() {
202 $this->config
->set('CSS', 'MaxImgLength', null);
204 '<img src="" alt="" style="width:10000000px;height:10000000px;border:1px solid #000;" />'
208 function testKeepPercentCSSWidthAndHeightOnImgWhenToldTo() {
209 $this->config
->set('CSS', 'MaxImgLength', null);
211 '<img src="" alt="" style="width:100%;height:100%;border:1px solid #000;" />'
215 function testRemoveRelativeCSSWidthAndHeightOnImg() {
217 '<img src="" alt="" style="width:10em;height:10em;border:1px solid #000;" />',
218 '<img src="" alt="" style="border:1px solid #000;" />'
222 function testRemovePercentCSSWidthAndHeightOnImg() {
224 '<img src="" alt="" style="width:100%;height:100%;border:1px solid #000;" />',
225 '<img src="" alt="" style="border:1px solid #000;" />'