4
4
5
5
use Sabberworm \CSS \Value \Size ;
6
6
use Sabberworm \CSS \Property \Selector ;
7
+ use Sabberworm \CSS \RuleSet \DeclarationBlock ;
7
8
use Sabberworm \CSS \Property \AtRule ;
8
9
9
10
class ParserTest extends \PHPUnit_Framework_TestCase {
@@ -46,29 +47,35 @@ function testColorParsing() {
46
47
}
47
48
$ sSelector = $ oRuleSet ->getSelectors ();
48
49
$ sSelector = $ sSelector [0 ]->getSelector ();
49
- if ($ sSelector == '#mine ' ) {
50
+ if ($ sSelector === '#mine ' ) {
50
51
$ aColorRule = $ oRuleSet ->getRules ('color ' );
51
- $ aValues = $ aColorRule [0 ]->getValues ();
52
- $ this ->assertSame ('red ' , $ aValues [ 0 ][ 0 ] );
52
+ $ oColor = $ aColorRule [0 ]->getValue ();
53
+ $ this ->assertSame ('red ' , $ oColor );
53
54
$ aColorRule = $ oRuleSet ->getRules ('background- ' );
54
- $ aValues = $ aColorRule [0 ]->getValues ();
55
- $ this ->assertEquals (array ('r ' => new Size (35.0 , null , true ), 'g ' => new Size (35.0 , null , true ), 'b ' => new Size (35.0 , null , true )), $ aValues [ 0 ][ 0 ] ->getColor ());
55
+ $ oColor = $ aColorRule [0 ]->getValue ();
56
+ $ this ->assertEquals (array ('r ' => new Size (35.0 , null , true ), 'g ' => new Size (35.0 , null , true ), 'b ' => new Size (35.0 , null , true )), $ oColor ->getColor ());
56
57
$ aColorRule = $ oRuleSet ->getRules ('border-color ' );
57
- $ aValues = $ aColorRule [0 ]->getValues ();
58
- $ this ->assertEquals (array ('r ' => new Size (10.0 , null , true ), 'g ' => new Size (100.0 , null , true ), 'b ' => new Size (230.0 , null , true ), 'a ' => new Size ("0000.3 " , null , true )), $ aValues [0 ][0 ]->getColor ());
58
+ $ oColor = $ aColorRule [0 ]->getValue ();
59
+ $ this ->assertEquals (array ('r ' => new Size (10.0 , null , true ), 'g ' => new Size (100.0 , null , true ), 'b ' => new Size (230.0 , null , true )), $ oColor ->getColor ());
60
+ $ oColor = $ aColorRule [1 ]->getValue ();
61
+ $ this ->assertEquals (array ('r ' => new Size (10.0 , null , true ), 'g ' => new Size (100.0 , null , true ), 'b ' => new Size (231.0 , null , true ), 'a ' => new Size ("0000.3 " , null , true )), $ oColor ->getColor ());
59
62
$ aColorRule = $ oRuleSet ->getRules ('outline-color ' );
60
- $ aValues = $ aColorRule [0 ]->getValues ();
61
- $ this ->assertEquals (array ('r ' => new Size (34.0 , null , true ), 'g ' => new Size (34.0 , null , true ), 'b ' => new Size (34.0 , null , true )), $ aValues [0 ][0 ]->getColor ());
62
- }
63
- }
64
- foreach ($ oDoc ->getAllValues ('background- ' ) as $ oColor ) {
65
- if ($ oColor ->getColorDescription () === 'hsl ' ) {
66
- $ this ->assertEquals (array ('h ' => new Size (220.0 , null , true ), 's ' => new Size (10.0 , null , true ), 'l ' => new Size (220.0 , null , true )), $ oColor ->getColor ());
63
+ $ oColor = $ aColorRule [0 ]->getValue ();
64
+ $ this ->assertEquals (array ('r ' => new Size (34.0 , null , true ), 'g ' => new Size (34.0 , null , true ), 'b ' => new Size (34.0 , null , true )), $ oColor ->getColor ());
65
+ } else if ($ sSelector === '#yours ' ) {
66
+ $ aColorRule = $ oRuleSet ->getRules ('background-color ' );
67
+ $ oColor = $ aColorRule [0 ]->getValue ();
68
+ $ this ->assertEquals (array ('h ' => new Size (220.0 , null , true ), 's ' => new Size (10.0 , '% ' , true ), 'l ' => new Size (220.0 , '% ' , true )), $ oColor ->getColor ());
69
+ $ oColor = $ aColorRule [1 ]->getValue ();
70
+ $ this ->assertEquals (array ('h ' => new Size (220.0 , null , true ), 's ' => new Size (10.0 , '% ' , true ), 'l ' => new Size (220.0 , '% ' , true ), 'a ' => new Size (0000.3 , null , true )), $ oColor ->getColor ());
67
71
}
68
72
}
69
73
foreach ($ oDoc ->getAllValues ('color ' ) as $ sColor ) {
70
74
$ this ->assertSame ('red ' , $ sColor );
71
75
}
76
+ $ 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 ->__toString ());
72
79
}
73
80
74
81
function testUnicodeParsing () {
@@ -247,7 +254,7 @@ function testSlashedValues() {
247
254
248
255
function testFunctionSyntax () {
249
256
$ oDoc = $ this ->parsedStructureForFile ('functions ' );
250
- $ sExpected = 'div.main {background-image: linear-gradient(rgb(0,0,0),rgb(255,255,255) );}
257
+ $ sExpected = 'div.main {background-image: linear-gradient(#000,#fff );}
251
258
.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%;}
252
259
.collapser.expanded::before, .collapser.expanded::-moz-before, .collapser.expanded::-webkit-before {-moz-transform: rotate(90deg);}
253
260
.collapser + * {height: 0;overflow: hidden;-moz-transition-property: height;-moz-transition-duration: .3s;}
@@ -273,19 +280,19 @@ function testFunctionSyntax() {
273
280
274
281
function testExpandShorthands () {
275
282
$ oDoc = $ this ->parsedStructureForFile ('expand-shorthands ' );
276
- $ sExpected = 'body {font: italic 500 14px/1.618 "Trebuchet MS",Georgia,serif;border: 2px solid rgb(255,0,255) ;background: rgb(204,204,204) url("/images/foo.png") no-repeat left top;margin: 1em !important;padding: 2px 6px 3px;} ' . "\n" ;
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" ;
277
284
$ this ->assertSame ($ sExpected , $ oDoc ->__toString ());
278
285
$ oDoc ->expandShorthands ();
279
- $ 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: rgb(255,0,255) ;border-right-color: rgb(255,0,255) ;border-bottom-color: rgb(255,0,255) ;border-left-color: rgb(255,0,255) ;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: rgb(204,204,204) ;background-image: url("/images/foo.png");background-repeat: no-repeat;background-attachment: scroll;background-position: left top;} ' . "\n" ;
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" ;
280
287
$ this ->assertSame ($ sExpected , $ oDoc ->__toString ());
281
288
}
282
289
283
290
function testCreateShorthands () {
284
291
$ oDoc = $ this ->parsedStructureForFile ('create-shorthands ' );
285
- $ sExpected = 'body {font-size: 2em;font-family: Helvetica,Arial,sans-serif;font-weight: bold;border-width: 2px;border-color: rgb(153,153,153) ;border-style: dotted;background-color: rgb(255,255,255) ;background-image: url("foobar.png");background-repeat: repeat-y;margin-top: 2px;margin-right: 3px;margin-bottom: 4px;margin-left: 5px;} ' . "\n" ;
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" ;
286
293
$ this ->assertSame ($ sExpected , $ oDoc ->__toString ());
287
294
$ oDoc ->createShorthands ();
288
- $ sExpected = 'body {background: rgb(255,255,255) url("foobar.png") repeat-y;margin: 2px 5px 4px 3px;border: 2px dotted rgb(153,153,153) ;font: bold 2em Helvetica,Arial,sans-serif;} ' . "\n" ;
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" ;
289
296
$ this ->assertSame ($ sExpected , $ oDoc ->__toString ());
290
297
}
291
298
@@ -298,7 +305,7 @@ function testNamespaces() {
298
305
299
306
function testInnerColors () {
300
307
$ oDoc = $ this ->parsedStructureForFile ('inner-color ' );
301
- $ sExpected = 'test {background: -webkit-gradient(linear,0 0,0 bottom,from(rgb(0,108,173)) ,to(rgb(0,159,249 )));} ' . "\n" ;
308
+ $ sExpected = 'test {background: -webkit-gradient(linear,0 0,0 bottom,from(#006cad) ,to(hsl(202,100%,49% )));} ' . "\n" ;
302
309
$ this ->assertSame ($ sExpected , $ oDoc ->__toString ());
303
310
}
304
311
0 commit comments