@@ -25,4 +25,45 @@ function testCssFiles() {
25
25
closedir ($ rHandle );
26
26
}
27
27
}
28
+
29
+ /**
30
+ * @depends testCssFiles
31
+ */
32
+ function testColorParsing () {
33
+ $ oDoc = $ this ->parsedStructureForFile ('colortest ' );
34
+ foreach ($ oDoc ->getAllRuleSets () as $ oRuleSet ) {
35
+ if (!$ oRuleSet instanceof CSSSelector) {
36
+ continue ;
37
+ }
38
+ $ aSelector = $ oRuleSet ->getSelector ();
39
+ if ($ aSelector [0 ] === '#mine ' ) {
40
+ $ aColorRule = $ oRuleSet ->getRules ('color ' );
41
+ $ aValues = $ aColorRule ['color ' ]->getValues ();
42
+ $ this ->assertSame ('red ' , $ aValues [0 ][0 ]);
43
+ $ aColorRule = $ oRuleSet ->getRules ('background- ' );
44
+ $ aValues = $ aColorRule ['background-color ' ]->getValues ();
45
+ $ this ->assertEquals (array ('r ' => new CSSSize (35.0 ), 'g ' => new CSSSize (35.0 ), 'b ' => new CSSSize (35.0 )), $ aValues [0 ][0 ]->getColor ());
46
+ $ aColorRule = $ oRuleSet ->getRules ('border-color ' );
47
+ $ aValues = $ aColorRule ['border-color ' ]->getValues ();
48
+ $ this ->assertEquals (array ('r ' => new CSSSize (10.0 ), 'g ' => new CSSSize (100.0 ), 'b ' => new CSSSize (230.0 ), 'a ' => new CSSSize (0.3 )), $ aValues [0 ][0 ]->getColor ());
49
+ $ aColorRule = $ oRuleSet ->getRules ('outline-color ' );
50
+ $ aValues = $ aColorRule ['outline-color ' ]->getValues ();
51
+ $ this ->assertEquals (array ('r ' => new CSSSize (34.0 ), 'g ' => new CSSSize (34.0 ), 'b ' => new CSSSize (34.0 )), $ aValues [0 ][0 ]->getColor ());
52
+ }
53
+ }
54
+ foreach ($ oDoc ->getAllValues ('background- ' ) as $ oColor ) {
55
+ if ($ oColor ->getColorDescription () === 'hsl ' ) {
56
+ $ this ->assertEquals (array ('h ' => new CSSSize (220.0 ), 's ' => new CSSSize (10.0 ), 'l ' => new CSSSize (220.0 )), $ oColor ->getColor ());
57
+ }
58
+ }
59
+ foreach ($ oDoc ->getAllValues ('color ' ) as $ sColor ) {
60
+ $ this ->assertSame ('red ' , $ sColor );
61
+ }
62
+ }
63
+
64
+ function parsedStructureForFile ($ sFileName ) {
65
+ $ sFile = dirname (__FILE__ ).DIRECTORY_SEPARATOR .'files ' .DIRECTORY_SEPARATOR ."$ sFileName.css " ;
66
+ $ oParser = new CSSParser (file_get_contents ($ sFile ));
67
+ return $ oParser ->parse ();
68
+ }
28
69
}
0 commit comments