Fix newline issues in tests.
[htmlpurifier/darkodev.git] / tests / HTMLPurifier / Strategy / ValidateAttributesTest.php
blob5671af22222c0bd2f4bc697d2780ce6e12f3020a
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->assertResult(
36 '<div class="valid 0invalid">Keep valid.</div>',
37 '<div class="valid">Keep valid.</div>'
41 function testPreserveTitle() {
42 $this->assertResult(
43 '<acronym title="PHP: Hypertext Preprocessor">PHP</acronym>'
47 function testAddXMLLang() {
48 $this->assertResult(
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');
56 $this->assertResult(
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() {
67 $this->assertResult(
68 '<a href="javascript:badstuff();">Google</a>',
69 '<a>Google</a>'
73 function testBdoAddMissingDir() {
74 $this->assertResult(
75 '<bdo>Go left.</bdo>',
76 '<bdo dir="ltr">Go left.</bdo>'
80 function testBdoReplaceInvalidDirWithDefault() {
81 $this->assertResult(
82 '<bdo dir="blahblah">Invalid value!</bdo>',
83 '<bdo dir="ltr">Invalid value!</bdo>'
87 function testBdoAlternateDefaultDir() {
88 $this->config->set('Attr', 'DefaultTextDir', 'rtl');
89 $this->assertResult(
90 '<bdo>Go right.</bdo>',
91 '<bdo dir="rtl">Go right.</bdo>'
95 function testRemoveDirWhenNotRequired() {
96 $this->assertResult(
97 '<span dir="blahblah">Invalid value!</span>',
98 '<span>Invalid value!</span>'
102 function testTableAttributes() {
103 $this->assertResult(
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="*" />
107 <tr valign="top">
108 <th abbr="name">Fiddly name</th>
109 <th abbr="price">Super-duper-price</th>
110 </tr>
111 <tr>
112 <td abbr="carrot">Carrot Humungous</td>
113 <td>$500.23</td>
114 </tr>
115 <tr>
116 <td colspan="2">Taken off the market</td>
117 </tr>
118 </table>'
122 function testColSpanIsNonZero() {
123 $this->assertResult(
124 '<col span="0" />',
125 '<col />'
129 function testImgAddDefaults() {
130 $this->config->set('Core', 'RemoveInvalidImg', false);
131 $this->assertResult(
132 '<img />',
133 '<img src="" alt="Invalid image" />'
137 function testImgGenerateAlt() {
138 $this->assertResult(
139 '<img src="foobar.jpg" />',
140 '<img src="foobar.jpg" alt="foobar.jpg" />'
144 function testImgAddDefaultSrc() {
145 $this->config->set('Core', 'RemoveInvalidImg', false);
146 $this->assertResult(
147 '<img alt="pretty picture" />',
148 '<img alt="pretty picture" src="" />'
152 function testImgRemoveNonRetrievableProtocol() {
153 $this->config->set('Core', 'RemoveInvalidImg', false);
154 $this->assertResult(
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');
174 $this->assertResult(
175 '<a href="foo" target="_top" />',
176 '<a href="foo" />'
180 function testKeepAbsoluteCSSWidthAndHeightOnImg() {
181 $this->assertResult(
182 '<img src="" alt="" style="width:10px;height:10px;border:1px solid #000;" />'
186 function testRemoveLargeCSSWidthAndHeightOnImg() {
187 $this->assertResult(
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');
195 $this->assertResult(
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);
203 $this->assertResult(
204 '<img src="" alt="" style="width:10000000px;height:10000000px;border:1px solid #000;" />'
208 function testKeepPercentCSSWidthAndHeightOnImgWhenToldTo() {
209 $this->config->set('CSS', 'MaxImgLength', null);
210 $this->assertResult(
211 '<img src="" alt="" style="width:100%;height:100%;border:1px solid #000;" />'
215 function testRemoveRelativeCSSWidthAndHeightOnImg() {
216 $this->assertResult(
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() {
223 $this->assertResult(
224 '<img src="" alt="" style="width:100%;height:100%;border:1px solid #000;" />',
225 '<img src="" alt="" style="border:1px solid #000;" />'