Fix rgb in border attribute with spaces, fixes #30.
[htmlpurifier/darkodev.git] / tests / HTMLPurifier / AttrDef / CSSTest.php
blob778a22bdeadf75176dc43632828d9847187248a2
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;');
86 $this->assertDef('border-color: rgb(0, 0, 0) rgb(10,0,10)', 'border-color:rgb(0,0,0) rgb(10,0,10);');
87 $this->assertDef('border: rgb(0, 0, 0)', 'border:rgb(0,0,0);');
89 // duplicates
90 $this->assertDef('text-align:right;text-align:left;',
91 'text-align:left;');
93 // a few composites
94 $this->assertDef('font-variant:small-caps;font-weight:900;');
95 $this->assertDef('float:right;text-align:right;');
97 // selective removal
98 $this->assertDef('text-transform:capitalize;destroy:it;',
99 'text-transform:capitalize;');
101 // inherit works for everything
102 $this->assertDef('text-align:inherit;');
104 // bad props
105 $this->assertDef('nodice:foobar;', false);
106 $this->assertDef('position:absolute;', false);
107 $this->assertDef('background-image:url(\'javascript:alert\(\)\');', false);
109 // airy input
110 $this->assertDef(' font-weight : bold; color : #ff0000',
111 'font-weight:bold;color:#ff0000;');
113 // case-insensitivity
114 $this->assertDef('FLOAT:LEFT;', 'float:left;');
116 // !important stripping
117 $this->assertDef('float:left !important;', 'float:left;');
121 public function testProprietary()
123 $this->config->set('CSS.Proprietary', true);
125 $this->assertDef('scrollbar-arrow-color:#ff0;');
126 $this->assertDef('scrollbar-base-color:#ff6347;');
127 $this->assertDef('scrollbar-darkshadow-color:#ffa500;');
128 $this->assertDef('scrollbar-face-color:#008080;');
129 $this->assertDef('scrollbar-highlight-color:#ff69b4;');
130 $this->assertDef('scrollbar-shadow-color:#f0f;');
132 $this->assertDef('-moz-opacity:.2;');
133 $this->assertDef('-khtml-opacity:.2;');
134 $this->assertDef('filter:alpha(opacity=20);');
138 public function testImportant()
140 $this->config->set('CSS.AllowImportant', true);
141 $this->assertDef('float:left !important;');
144 public function testTricky()
146 $this->config->set('CSS.AllowTricky', true);
147 $this->assertDef('display:none;');
148 $this->assertDef('visibility:visible;');
149 $this->assertDef('overflow:scroll;');
150 $this->assertDef('opacity:.2;');
153 public function testForbidden()
155 $this->config->set('CSS.ForbiddenProperties', 'float');
156 $this->assertDef('float:left;', false);
157 $this->assertDef('text-align:right;');
160 public function testTrusted()
162 $this->config->set('CSS.Trusted', true);
163 $this->assertDef('position:relative;');
164 $this->assertDef('left:2px;');
165 $this->assertDef('right:100%;');
166 $this->assertDef('top:auto;');
167 $this->assertDef('z-index:-2;');
172 // vim: et sw=4 sts=4