Rewrite CSS url() and font-family output logic.
[htmlpurifier.git] / tests / HTMLPurifier / AttrDef / CSSTest.php
blob27e5c432ee1cef8546add53509433dc1bdfc518b
1 <?php
3 class HTMLPurifier_AttrDef_CSSTest extends HTMLPurifier_AttrDefHarness
6 function setup() {
7 parent::setup();
8 $this->def = new HTMLPurifier_AttrDef_CSS();
11 function test() {
13 // regular cases, singular
14 $this->assertDef('text-align:right;');
15 $this->assertDef('border-left-style:solid;');
16 $this->assertDef('border-style:solid dotted;');
17 $this->assertDef('clear:right;');
18 $this->assertDef('float:left;');
19 $this->assertDef('font-style:italic;');
20 $this->assertDef('font-variant:small-caps;');
21 $this->assertDef('font-weight:bold;');
22 $this->assertDef('list-style-position:outside;');
23 $this->assertDef('list-style-type:upper-roman;');
24 $this->assertDef('list-style:upper-roman inside;');
25 $this->assertDef('text-transform:capitalize;');
26 $this->assertDef('background-color:rgb(0,0,255);');
27 $this->assertDef('background-color:transparent;');
28 $this->assertDef('background:#333 url("chess.png") repeat fixed 50% top;');
29 $this->assertDef('color:#F00;');
30 $this->assertDef('border-top-color:#F00;');
31 $this->assertDef('border-color:#F00 #FF0;');
32 $this->assertDef('border-top-width:thin;');
33 $this->assertDef('border-top-width:12px;');
34 $this->assertDef('border-width:5px 1px 4px 2px;');
35 $this->assertDef('border-top-width:-12px;', false);
36 $this->assertDef('letter-spacing:normal;');
37 $this->assertDef('letter-spacing:2px;');
38 $this->assertDef('word-spacing:normal;');
39 $this->assertDef('word-spacing:3em;');
40 $this->assertDef('font-size:200%;');
41 $this->assertDef('font-size:larger;');
42 $this->assertDef('font-size:12pt;');
43 $this->assertDef('line-height:2;');
44 $this->assertDef('line-height:2em;');
45 $this->assertDef('line-height:20%;');
46 $this->assertDef('line-height:normal;');
47 $this->assertDef('line-height:-20%;', false);
48 $this->assertDef('margin-left:5px;');
49 $this->assertDef('margin-right:20%;');
50 $this->assertDef('margin-top:auto;');
51 $this->assertDef('margin:auto 5%;');
52 $this->assertDef('padding-bottom:5px;');
53 $this->assertDef('padding-top:20%;');
54 $this->assertDef('padding:20% 10%;');
55 $this->assertDef('padding-top:-20%;', false);
56 $this->assertDef('text-indent:3em;');
57 $this->assertDef('text-indent:5%;');
58 $this->assertDef('text-indent:-3em;');
59 $this->assertDef('width:50%;');
60 $this->assertDef('width:50px;');
61 $this->assertDef('width:auto;');
62 $this->assertDef('width:-50px;', false);
63 $this->assertDef('text-decoration:underline;');
64 $this->assertDef('font-family:sans-serif;');
65 $this->assertDef('font-family:Gill, "Times New Roman", sans-serif;');
66 $this->assertDef('font:12px serif;');
67 $this->assertDef('border:1px solid #000;');
68 $this->assertDef('border-bottom:2em double #FF00FA;');
69 $this->assertDef('border-collapse:collapse;');
70 $this->assertDef('border-collapse:separate;');
71 $this->assertDef('caption-side:top;');
72 $this->assertDef('vertical-align:middle;');
73 $this->assertDef('vertical-align:12px;');
74 $this->assertDef('vertical-align:50%;');
75 $this->assertDef('table-layout:fixed;');
76 $this->assertDef('list-style-image:url("nice.jpg");');
77 $this->assertDef('list-style:disc url("nice.jpg") inside;');
78 $this->assertDef('background-image:url("foo.jpg");');
79 $this->assertDef('background-image:none;');
80 $this->assertDef('background-repeat:repeat-y;');
81 $this->assertDef('background-attachment:fixed;');
82 $this->assertDef('background-position:left 90%;');
83 $this->assertDef('border-spacing:1em;');
84 $this->assertDef('border-spacing:1em 2em;');
86 // duplicates
87 $this->assertDef('text-align:right;text-align:left;',
88 'text-align:left;');
90 // a few composites
91 $this->assertDef('font-variant:small-caps;font-weight:900;');
92 $this->assertDef('float:right;text-align:right;');
94 // selective removal
95 $this->assertDef('text-transform:capitalize;destroy:it;',
96 'text-transform:capitalize;');
98 // inherit works for everything
99 $this->assertDef('text-align:inherit;');
101 // bad props
102 $this->assertDef('nodice:foobar;', false);
103 $this->assertDef('position:absolute;', false);
104 $this->assertDef('background-image:url(\'javascript:alert\(\)\');', false);
106 // airy input
107 $this->assertDef(' font-weight : bold; color : #ff0000',
108 'font-weight:bold;color:#ff0000;');
110 // case-insensitivity
111 $this->assertDef('FLOAT:LEFT;', 'float:left;');
113 // !important stripping
114 $this->assertDef('float:left !important;', 'float:left;');
118 function testProprietary() {
119 $this->config->set('CSS.Proprietary', true);
121 $this->assertDef('scrollbar-arrow-color:#ff0;');
122 $this->assertDef('scrollbar-base-color:#ff6347;');
123 $this->assertDef('scrollbar-darkshadow-color:#ffa500;');
124 $this->assertDef('scrollbar-face-color:#008080;');
125 $this->assertDef('scrollbar-highlight-color:#ff69b4;');
126 $this->assertDef('scrollbar-shadow-color:#f0f;');
128 $this->assertDef('opacity:.2;');
129 $this->assertDef('-moz-opacity:.2;');
130 $this->assertDef('-khtml-opacity:.2;');
131 $this->assertDef('filter:alpha(opacity=20);');
135 function testImportant() {
136 $this->config->set('CSS.AllowImportant', true);
137 $this->assertDef('float:left !important;');
140 function testTricky() {
141 $this->config->set('CSS.AllowTricky', true);
142 $this->assertDef('display:none;');
143 $this->assertDef('visibility:visible;');
144 $this->assertDef('overflow:scroll;');
149 // vim: et sw=4 sts=4