44
55use Sabberworm \CSS \Value \Size ;
66use Sabberworm \CSS \Property \Selector ;
7+ use Sabberworm \CSS \RuleSet \DeclarationBlock ;
78use Sabberworm \CSS \Property \AtRule ;
89
910class ParserTest extends \PHPUnit_Framework_TestCase {
@@ -46,29 +47,35 @@ function testColorParsing() {
4647 }
4748 $ sSelector = $ oRuleSet ->getSelectors ();
4849 $ sSelector = $ sSelector [0 ]->getSelector ();
49- if ($ sSelector == '#mine ' ) {
50+ if ($ sSelector === '#mine ' ) {
5051 $ 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 );
5354 $ 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 ());
5657 $ 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 ());
5962 $ 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 ());
6771 }
6872 }
6973 foreach ($ oDoc ->getAllValues ('color ' ) as $ sColor ) {
7074 $ this ->assertSame ('red ' , $ sColor );
7175 }
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 ());
7279 }
7380
7481 function testUnicodeParsing () {
@@ -247,7 +254,7 @@ function testSlashedValues() {
247254
248255 function testFunctionSyntax () {
249256 $ 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 );}
251258.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%;}
252259.collapser.expanded::before, .collapser.expanded::-moz-before, .collapser.expanded::-webkit-before {-moz-transform: rotate(90deg);}
253260.collapser + * {height: 0;overflow: hidden;-moz-transition-property: height;-moz-transition-duration: .3s;}
@@ -273,19 +280,19 @@ function testFunctionSyntax() {
273280
274281 function testExpandShorthands () {
275282 $ 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" ;
277284 $ this ->assertSame ($ sExpected , $ oDoc ->__toString ());
278285 $ 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" ;
280287 $ this ->assertSame ($ sExpected , $ oDoc ->__toString ());
281288 }
282289
283290 function testCreateShorthands () {
284291 $ 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" ;
286293 $ this ->assertSame ($ sExpected , $ oDoc ->__toString ());
287294 $ 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" ;
289296 $ this ->assertSame ($ sExpected , $ oDoc ->__toString ());
290297 }
291298
@@ -298,7 +305,7 @@ function testNamespaces() {
298305
299306 function testInnerColors () {
300307 $ 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" ;
302309 $ this ->assertSame ($ sExpected , $ oDoc ->__toString ());
303310 }
304311
0 commit comments