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