10
10
class ParserTest extends \PHPUnit_Framework_TestCase {
11
11
12
12
function testFiles () {
13
-
14
13
$ sDirectory = dirname (__FILE__ ) . '/../../files ' ;
15
14
if ($ rHandle = opendir ($ sDirectory )) {
16
15
/* This is the correct way to loop over the directory. */
@@ -74,8 +73,7 @@ function testColorParsing() {
74
73
$ this ->assertSame ('red ' , $ sColor );
75
74
}
76
75
$ this ->assertSame ('#mine {color: red;border-color: #0a64e6;border-color: rgba(10,100,231,.3);outline-color: #222;background-color: #232323;}
77
- #yours {background-color: hsl(220,10%,220%);background-color: hsla(220,10%,220%,.3);}
78
- ' , $ oDoc ->render ());
76
+ #yours {background-color: hsl(220,10%,220%);background-color: hsla(220,10%,220%,.3);} ' , $ oDoc ->render ());
79
77
}
80
78
81
79
function testUnicodeParsing () {
@@ -156,50 +154,56 @@ function testSpecificity() {
156
154
157
155
function testManipulation () {
158
156
$ oDoc = $ this ->parsedStructureForFile ('atrules ' );
159
- $ this ->assertSame ('@charset "utf-8";@font-face {font-family: "CrassRoots";src: url("../media/cr.ttf");}html, body {font-size: -.6em;}
157
+ $ this ->assertSame ('@charset "utf-8";
158
+ @font-face {font-family: "CrassRoots";src: url("../media/cr.ttf");}
159
+ html, body {font-size: -.6em;}
160
160
@keyframes mymove {from {top: 0px;}
161
- to {top: 200px;}
162
- }@-moz-keyframes some-move {from {top: 0px;}
163
- to {top: 200px;}
164
- }@supports ( (perspective: 10px) or (-moz-perspective: 10px) or (-webkit-perspective: 10px) or (-ms-perspective: 10px) or (-o-perspective: 10px) ) {body {font-family: "Helvetica";}
165
- }@page :pseudo-class {margin: 2in;}@-moz-document url(http://www.w3.org/),
161
+ to {top: 200px;}}
162
+ @-moz-keyframes some-move {from {top: 0px;}
163
+ to {top: 200px;}}
164
+ @supports ( (perspective: 10px) or (-moz-perspective: 10px) or (-webkit-perspective: 10px) or (-ms-perspective: 10px) or (-o-perspective: 10px) ) {body {font-family: "Helvetica";}}
165
+ @page :pseudo-class {margin: 2in;}
166
+ @-moz-document url(http://www.w3.org/),
166
167
url-prefix(http://www.w3.org/Style/),
167
168
domain(mozilla.org),
168
- regexp("https:.*") {body {color: purple;background: yellow;}
169
- } @media screen and (orientation: landscape) {@-ms-viewport {width: 1024px;height: 768px;}}@region-style #intro {p {color: blue; }
170
- } ' , $ oDoc ->render ());
169
+ regexp("https:.*") {body {color: purple;background: yellow;}}
170
+ @media screen and (orientation: landscape) {@-ms-viewport {width: 1024px;height: 768px;}}
171
+ @region-style #intro {p {color: blue;} } ' , $ oDoc ->render ());
171
172
foreach ($ oDoc ->getAllDeclarationBlocks () as $ oBlock ) {
172
173
foreach ($ oBlock ->getSelectors () as $ oSelector ) {
173
174
//Loop over all selector parts (the comma-separated strings in a selector) and prepend the id
174
175
$ oSelector ->setSelector ('#my_id ' . $ oSelector ->getSelector ());
175
176
}
176
177
}
177
- $ this ->assertSame ('@charset "utf-8";@font-face {font-family: "CrassRoots";src: url("../media/cr.ttf");}#my_id html, #my_id body {font-size: -.6em;}
178
+ $ this ->assertSame ('@charset "utf-8";
179
+ @font-face {font-family: "CrassRoots";src: url("../media/cr.ttf");}
180
+ #my_id html, #my_id body {font-size: -.6em;}
178
181
@keyframes mymove {from {top: 0px;}
179
- to {top: 200px;}
180
- }@-moz-keyframes some-move {from {top: 0px;}
181
- to {top: 200px;}
182
- }@supports ( (perspective: 10px) or (-moz-perspective: 10px) or (-webkit-perspective: 10px) or (-ms-perspective: 10px) or (-o-perspective: 10px) ) {#my_id body {font-family: "Helvetica";}
183
- }@page :pseudo-class {margin: 2in;}@-moz-document url(http://www.w3.org/),
182
+ to {top: 200px;}}
183
+ @-moz-keyframes some-move {from {top: 0px;}
184
+ to {top: 200px;}}
185
+ @supports ( (perspective: 10px) or (-moz-perspective: 10px) or (-webkit-perspective: 10px) or (-ms-perspective: 10px) or (-o-perspective: 10px) ) {#my_id body {font-family: "Helvetica";}}
186
+ @page :pseudo-class {margin: 2in;}
187
+ @-moz-document url(http://www.w3.org/),
184
188
url-prefix(http://www.w3.org/Style/),
185
189
domain(mozilla.org),
186
- regexp("https:.*") {#my_id body {color: purple;background: yellow;}
187
- } @media screen and (orientation: landscape) {@-ms-viewport {width: 1024px;height: 768px;}}@region-style #intro {#my_id p {color: blue; }
188
- } ' , $ oDoc ->render ());
190
+ regexp("https:.*") {#my_id body {color: purple;background: yellow;}}
191
+ @media screen and (orientation: landscape) {@-ms-viewport {width: 1024px;height: 768px;}}
192
+ @region-style #intro {#my_id p {color: blue;} } ' , $ oDoc ->render ());
189
193
190
194
$ oDoc = $ this ->parsedStructureForFile ('values ' );
191
195
$ this ->assertSame ('#header {margin: 10px 2em 1cm 2%;font-family: Verdana,Helvetica,"Gill Sans",sans-serif;font-size: 10px;color: red !important;background-color: green;background-color: rgba(0,128,0,.7);frequency: 30Hz;}
192
- body {color: green;font: 75% "Lucida Grande","Trebuchet MS",Verdana,sans-serif;} ' . "\n" , $ oDoc ->render ());
196
+ body {color: green;font: 75% "Lucida Grande","Trebuchet MS",Verdana,sans-serif;} ' , $ oDoc ->render ());
193
197
foreach ($ oDoc ->getAllRuleSets () as $ oRuleSet ) {
194
198
$ oRuleSet ->removeRule ('font- ' );
195
199
}
196
200
$ this ->assertSame ('#header {margin: 10px 2em 1cm 2%;color: red !important;background-color: green;background-color: rgba(0,128,0,.7);frequency: 30Hz;}
197
- body {color: green;} ' . "\n" , $ oDoc ->render ());
201
+ body {color: green;} ' , $ oDoc ->render ());
198
202
foreach ($ oDoc ->getAllRuleSets () as $ oRuleSet ) {
199
203
$ oRuleSet ->removeRule ('background- ' );
200
204
}
201
205
$ this ->assertSame ('#header {margin: 10px 2em 1cm 2%;color: red !important;frequency: 30Hz;}
202
- body {color: green;} ' . "\n" , $ oDoc ->render ());
206
+ body {color: green;} ' , $ oDoc ->render ());
203
207
}
204
208
205
209
function testRuleGetters () {
@@ -223,7 +227,7 @@ function testRuleGetters() {
223
227
224
228
function testSlashedValues () {
225
229
$ oDoc = $ this ->parsedStructureForFile ('slashed ' );
226
- $ this ->assertSame ('.test {font: 12px/1.5 Verdana,Arial,sans-serif;border-radius: 5px 10px 5px 10px/10px 5px 10px 5px;} ' . "\n" , $ oDoc ->render ());
230
+ $ this ->assertSame ('.test {font: 12px/1.5 Verdana,Arial,sans-serif;border-radius: 5px 10px 5px 10px/10px 5px 10px 5px;} ' , $ oDoc ->render ());
227
231
foreach ($ oDoc ->getAllValues (null ) as $ mValue ) {
228
232
if ($ mValue instanceof Size && $ mValue ->isSize () && !$ mValue ->isRelative ()) {
229
233
$ mValue ->setSize ($ mValue ->getSize () * 3 );
@@ -249,7 +253,7 @@ function testSlashedValues() {
249
253
$ this ->assertEquals (' ' , $ oSpaceList1 ->getListSeparator ());
250
254
$ this ->assertEquals (' ' , $ oSpaceList2 ->getListSeparator ());
251
255
}
252
- $ this ->assertSame ('.test {font: 36px/1.5 Verdana,Arial,sans-serif;border-radius: 15px 30px 15px 30px/30px 15px 30px 15px;} ' . "\n" , $ oDoc ->render ());
256
+ $ this ->assertSame ('.test {font: 36px/1.5 Verdana,Arial,sans-serif;border-radius: 15px 30px 15px 30px/30px 15px 30px 15px;} ' , $ oDoc ->render ());
253
257
}
254
258
255
259
function testFunctionSyntax () {
@@ -258,7 +262,7 @@ function testFunctionSyntax() {
258
262
.collapser::before, .collapser::-moz-before, .collapser::-webkit-before {content: "»";font-size: 1.2em;margin-right: .2em;-moz-transition-property: -moz-transform;-moz-transition-duration: .2s;-moz-transform-origin: center 60%;}
259
263
.collapser.expanded::before, .collapser.expanded::-moz-before, .collapser.expanded::-webkit-before {-moz-transform: rotate(90deg);}
260
264
.collapser + * {height: 0;overflow: hidden;-moz-transition-property: height;-moz-transition-duration: .3s;}
261
- .collapser.expanded + * {height: auto;} ' . "\n" ;
265
+ .collapser.expanded + * {height: auto;} ' ;
262
266
$ this ->assertSame ($ sExpected , $ oDoc ->render ());
263
267
264
268
foreach ($ oDoc ->getAllValues (null , true ) as $ mValue ) {
@@ -280,38 +284,42 @@ function testFunctionSyntax() {
280
284
281
285
function testExpandShorthands () {
282
286
$ oDoc = $ this ->parsedStructureForFile ('expand-shorthands ' );
283
- $ sExpected = 'body {font: italic 500 14px/1.618 "Trebuchet MS",Georgia,serif;border: 2px solid #f0f;background: #ccc url("/images/foo.png") no-repeat left top;margin: 1em !important;padding: 2px 6px 3px;} ' . "\n" ;
287
+ $ sExpected = 'body {font: italic 500 14px/1.618 "Trebuchet MS",Georgia,serif;border: 2px solid #f0f;background: #ccc url("/images/foo.png") no-repeat left top;margin: 1em !important;padding: 2px 6px 3px;} ' ;
284
288
$ this ->assertSame ($ sExpected , $ oDoc ->render ());
285
289
$ oDoc ->expandShorthands ();
286
- $ sExpected = 'body {margin-top: 1em !important;margin-right: 1em !important;margin-bottom: 1em !important;margin-left: 1em !important;padding-top: 2px;padding-right: 6px;padding-bottom: 3px;padding-left: 6px;border-top-color: #f0f;border-right-color: #f0f;border-bottom-color: #f0f;border-left-color: #f0f;border-top-style: solid;border-right-style: solid;border-bottom-style: solid;border-left-style: solid;border-top-width: 2px;border-right-width: 2px;border-bottom-width: 2px;border-left-width: 2px;font-style: italic;font-variant: normal;font-weight: 500;font-size: 14px;line-height: 1.618;font-family: "Trebuchet MS",Georgia,serif;background-color: #ccc;background-image: url("/images/foo.png");background-repeat: no-repeat;background-attachment: scroll;background-position: left top;} ' . "\n" ;
290
+ $ sExpected = 'body {margin-top: 1em !important;margin-right: 1em !important;margin-bottom: 1em !important;margin-left: 1em !important;padding-top: 2px;padding-right: 6px;padding-bottom: 3px;padding-left: 6px;border-top-color: #f0f;border-right-color: #f0f;border-bottom-color: #f0f;border-left-color: #f0f;border-top-style: solid;border-right-style: solid;border-bottom-style: solid;border-left-style: solid;border-top-width: 2px;border-right-width: 2px;border-bottom-width: 2px;border-left-width: 2px;font-style: italic;font-variant: normal;font-weight: 500;font-size: 14px;line-height: 1.618;font-family: "Trebuchet MS",Georgia,serif;background-color: #ccc;background-image: url("/images/foo.png");background-repeat: no-repeat;background-attachment: scroll;background-position: left top;} ' ;
287
291
$ this ->assertSame ($ sExpected , $ oDoc ->render ());
288
292
}
289
293
290
294
function testCreateShorthands () {
291
295
$ oDoc = $ this ->parsedStructureForFile ('create-shorthands ' );
292
- $ sExpected = 'body {font-size: 2em;font-family: Helvetica,Arial,sans-serif;font-weight: bold;border-width: 2px;border-color: #999;border-style: dotted;background-color: #fff;background-image: url("foobar.png");background-repeat: repeat-y;margin-top: 2px;margin-right: 3px;margin-bottom: 4px;margin-left: 5px;} ' . "\n" ;
296
+ $ sExpected = 'body {font-size: 2em;font-family: Helvetica,Arial,sans-serif;font-weight: bold;border-width: 2px;border-color: #999;border-style: dotted;background-color: #fff;background-image: url("foobar.png");background-repeat: repeat-y;margin-top: 2px;margin-right: 3px;margin-bottom: 4px;margin-left: 5px;} ' ;
293
297
$ this ->assertSame ($ sExpected , $ oDoc ->render ());
294
298
$ oDoc ->createShorthands ();
295
- $ sExpected = 'body {background: #fff url("foobar.png") repeat-y;margin: 2px 5px 4px 3px;border: 2px dotted #999;font: bold 2em Helvetica,Arial,sans-serif;} ' . "\n" ;
299
+ $ sExpected = 'body {background: #fff url("foobar.png") repeat-y;margin: 2px 5px 4px 3px;border: 2px dotted #999;font: bold 2em Helvetica,Arial,sans-serif;} ' ;
296
300
$ this ->assertSame ($ sExpected , $ oDoc ->render ());
297
301
}
298
302
299
303
function testNamespaces () {
300
304
$ oDoc = $ this ->parsedStructureForFile ('namespaces ' );
301
- $ sExpected = '@namespace toto "http://toto.example.org";@namespace "http://example.com/foo";@namespace foo url("http://www.example.com/");@namespace foo url("http://www.example.com/");foo|test {gaga: 1;}
302
- |test {gaga: 2;} ' . "\n" ;
305
+ $ sExpected = '@namespace toto "http://toto.example.org";
306
+ @namespace "http://example.com/foo";
307
+ @namespace foo url("http://www.example.com/");
308
+ @namespace foo url("http://www.example.com/");
309
+ foo|test {gaga: 1;}
310
+ |test {gaga: 2;} ' ;
303
311
$ this ->assertSame ($ sExpected , $ oDoc ->render ());
304
312
}
305
313
306
314
function testInnerColors () {
307
315
$ oDoc = $ this ->parsedStructureForFile ('inner-color ' );
308
- $ sExpected = 'test {background: -webkit-gradient(linear,0 0,0 bottom,from(#006cad),to(hsl(202,100%,49%)));} ' . "\n" ;
316
+ $ sExpected = 'test {background: -webkit-gradient(linear,0 0,0 bottom,from(#006cad),to(hsl(202,100%,49%)));} ' ;
309
317
$ this ->assertSame ($ sExpected , $ oDoc ->render ());
310
318
}
311
319
312
320
function testPrefixedGradient () {
313
321
$ oDoc = $ this ->parsedStructureForFile ('webkit ' );
314
- $ sExpected = '.test {background: -webkit-linear-gradient(top right,white,black);} ' . "\n" ;
322
+ $ sExpected = '.test {background: -webkit-linear-gradient(top right,white,black);} ' ;
315
323
$ this ->assertSame ($ sExpected , $ oDoc ->render ());
316
324
}
317
325
@@ -323,24 +331,24 @@ function testListValueRemoval() {
323
331
continue ;
324
332
}
325
333
}
326
- $ this ->assertSame ('html, body {font-size: -.6em;} ' . "\n" , $ oDoc ->render ());
334
+ $ this ->assertSame ('html, body {font-size: -.6em;} ' , $ oDoc ->render ());
327
335
328
336
$ oDoc = $ this ->parsedStructureForFile ('nested ' );
329
337
foreach ($ oDoc ->getAllDeclarationBlocks () as $ oBlock ) {
330
338
$ oDoc ->removeDeclarationBlockBySelector ($ oBlock , false );
331
339
break ;
332
340
}
333
341
$ this ->assertSame ('html {some-other: -test(val1);}
334
- @media screen {html {some: -test(val2);}
335
- } #unrelated {other: yes;} ' . "\n" , $ oDoc ->render ());
342
+ @media screen {html {some: -test(val2);}}
343
+ #unrelated {other: yes;} ' , $ oDoc ->render ());
336
344
337
345
$ oDoc = $ this ->parsedStructureForFile ('nested ' );
338
346
foreach ($ oDoc ->getAllDeclarationBlocks () as $ oBlock ) {
339
347
$ oDoc ->removeDeclarationBlockBySelector ($ oBlock , true );
340
348
break ;
341
349
}
342
- $ this ->assertSame ('@media screen {html {some: -test(val2);}
343
- } #unrelated {other: yes;} ' . "\n" , $ oDoc ->render ());
350
+ $ this ->assertSame ('@media screen {html {some: -test(val2);}}
351
+ #unrelated {other: yes;} ' , $ oDoc ->render ());
344
352
}
345
353
346
354
/**
@@ -351,8 +359,9 @@ function testSelectorRemoval() {
351
359
$ aBlocks = $ oDoc ->getAllDeclarationBlocks ();
352
360
$ oBlock1 = $ aBlocks [0 ];
353
361
$ this ->assertSame (true , $ oBlock1 ->removeSelector ('html ' ));
354
- $ sExpected = '@charset "utf-8";@font-face {font-family: "CrassRoots";src: url("../media/cr.ttf");}body {font-size: 1.6em;}
355
- ' ;
362
+ $ sExpected = '@charset "utf-8";
363
+ @font-face {font-family: "CrassRoots";src: url("../media/cr.ttf");}
364
+ body {font-size: 1.6em;} ' ;
356
365
$ this ->assertSame ($ sExpected , $ oDoc ->render ());
357
366
$ this ->assertSame (false , $ oBlock1 ->removeSelector ('html ' ));
358
367
$ this ->assertSame (true , $ oBlock1 ->removeSelector ('body ' ));
@@ -362,9 +371,9 @@ function testSelectorRemoval() {
362
371
363
372
function testComments () {
364
373
$ oDoc = $ this ->parsedStructureForFile ('comments ' );
365
- $ sExpected = '@import url("some/url.css") screen;.foo, #bar {background-color: #000;}
366
- @media screen {#foo. bar {position: absolute ;}
367
- } ' ;
374
+ $ sExpected = '@import url("some/url.css") screen;
375
+ .foo, # bar {background-color: #000 ;}
376
+ @media screen {#foo.bar {position: absolute;} } ' ;
368
377
$ this ->assertSame ($ sExpected , $ oDoc ->render ());
369
378
}
370
379
0 commit comments