@@ -146,26 +146,28 @@ function testSpecificity() {
146
146
147
147
function testManipulation () {
148
148
$ oDoc = $ this ->parsedStructureForFile ('atrules ' );
149
- $ this ->assertSame ('@charset "utf-8";@font-face {font-family: "CrassRoots";src: url("../media/cr.ttf");}html, body {font-size: 1.6em;} ' , $ oDoc ->__toString ());
149
+ $ this ->assertSame ('@charset "utf-8";@font-face {font-family: "CrassRoots";src: url("../media/cr.ttf");}html, body {font-size: 1.6em;} ' . "\n" , $ oDoc ->__toString ());
150
150
foreach ($ oDoc ->getAllDeclarationBlocks () as $ oBlock ) {
151
151
foreach ($ oBlock ->getSelectors () as $ oSelector ) {
152
152
//Loop over all selector parts (the comma-separated strings in a selector) and prepend the id
153
153
$ oSelector ->setSelector ('#my_id ' .$ oSelector ->getSelector ());
154
154
}
155
155
}
156
- $ this ->assertSame ('@charset "utf-8";@font-face {font-family: "CrassRoots";src: url("../media/cr.ttf");}#my_id html, #my_id body {font-size: 1.6em;} ' , $ oDoc ->__toString ());
156
+ $ this ->assertSame ('@charset "utf-8";@font-face {font-family: "CrassRoots";src: url("../media/cr.ttf");}#my_id html, #my_id body {font-size: 1.6em;} ' . "\n" , $ oDoc ->__toString ());
157
157
158
158
$ oDoc = $ this ->parsedStructureForFile ('values ' );
159
- $ this ->assertSame ('#header {margin: 10px 2em 1cm 2%;font-family: Verdana,Helvetica,"Gill Sans",sans-serif;font-size: 10px;color: red !important;}body {color: green;font: 75% "Lucida Grande","Trebuchet MS",Verdana,sans-serif;} ' , $ oDoc ->__toString ());
159
+ $ this ->assertSame ('#header {margin: 10px 2em 1cm 2%;font-family: Verdana,Helvetica,"Gill Sans",sans-serif;font-size: 10px;color: red !important;}
160
+ body {color: green;font: 75% "Lucida Grande","Trebuchet MS",Verdana,sans-serif;} ' ."\n" , $ oDoc ->__toString ());
160
161
foreach ($ oDoc ->getAllRuleSets () as $ oRuleSet ) {
161
162
$ oRuleSet ->removeRule ('font- ' );
162
163
}
163
- $ this ->assertSame ('#header {margin: 10px 2em 1cm 2%;color: red !important;}body {color: green;} ' , $ oDoc ->__toString ());
164
+ $ this ->assertSame ('#header {margin: 10px 2em 1cm 2%;color: red !important;}
165
+ body {color: green;} ' ."\n" , $ oDoc ->__toString ());
164
166
}
165
167
166
168
function testSlashedValues () {
167
169
$ oDoc = $ this ->parsedStructureForFile ('slashed ' );
168
- $ this ->assertSame ('.test {font: 12px/1.5 Verdana,Arial,sans-serif;border-radius: 5px 10px 5px 10px/10px 5px 10px 5px;} ' , $ oDoc ->__toString ());
170
+ $ this ->assertSame ('.test {font: 12px/1.5 Verdana,Arial,sans-serif;border-radius: 5px 10px 5px 10px/10px 5px 10px 5px;} ' . "\n" , $ oDoc ->__toString ());
169
171
foreach ($ oDoc ->getAllValues (null ) as $ mValue ) {
170
172
if ($ mValue instanceof CSSSize && $ mValue ->isSize () && !$ mValue ->isRelative ()) {
171
173
$ mValue ->setSize ($ mValue ->getSize ()*3 );
@@ -191,12 +193,16 @@ function testSlashedValues() {
191
193
$ this ->assertEquals (' ' , $ oSpaceList1 ->getListSeparator ());
192
194
$ this ->assertEquals (' ' , $ oSpaceList2 ->getListSeparator ());
193
195
}
194
- $ this ->assertSame ('.test {font: 36px/1.5 Verdana,Arial,sans-serif;border-radius: 15px 30px 15px 30px/30px 15px 30px 15px;} ' , $ oDoc ->__toString ());
196
+ $ this ->assertSame ('.test {font: 36px/1.5 Verdana,Arial,sans-serif;border-radius: 15px 30px 15px 30px/30px 15px 30px 15px;} ' . "\n" , $ oDoc ->__toString ());
195
197
}
196
198
197
199
function testFunctionSyntax () {
198
200
$ oDoc = $ this ->parsedStructureForFile ('functions ' );
199
- $ sExpected = 'div.main {background-image: linear-gradient(rgb(0,0,0),rgb(255,255,255));}.collapser::before, .collapser::-moz-before, .collapser::-webkit-before {content: "»";font-size: 1.2em;margin-right: 0.2em;-moz-transition-property: -moz-transform;-moz-transition-duration: 0.2s;-moz-transform-origin: center 60%;}.collapser.expanded::before, .collapser.expanded::-moz-before, .collapser.expanded::-webkit-before {-moz-transform: rotate(90deg);}.collapser + * {height: 0;overflow: hidden;-moz-transition-property: height;-moz-transition-duration: 0.3s;}.collapser.expanded + * {height: auto;} ' ;
201
+ $ sExpected = 'div.main {background-image: linear-gradient(rgb(0,0,0),rgb(255,255,255));}
202
+ .collapser::before, .collapser::-moz-before, .collapser::-webkit-before {content: "»";font-size: 1.2em;margin-right: 0.2em;-moz-transition-property: -moz-transform;-moz-transition-duration: 0.2s;-moz-transform-origin: center 60%;}
203
+ .collapser.expanded::before, .collapser.expanded::-moz-before, .collapser.expanded::-webkit-before {-moz-transform: rotate(90deg);}
204
+ .collapser + * {height: 0;overflow: hidden;-moz-transition-property: height;-moz-transition-duration: 0.3s;}
205
+ .collapser.expanded + * {height: auto;} ' ."\n" ;
200
206
$ this ->assertSame ($ sExpected , $ oDoc ->__toString ());
201
207
202
208
foreach ($ oDoc ->getAllValues (null , true ) as $ mValue ) {
@@ -218,25 +224,54 @@ function testFunctionSyntax() {
218
224
219
225
function testExpandShorthands () {
220
226
$ oDoc = $ this ->parsedStructureForFile ('expand-shorthands ' );
221
- $ 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;} ' ;
227
+ $ 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" ;
222
228
$ this ->assertSame ($ sExpected , $ oDoc ->__toString ());
223
229
$ oDoc ->expandShorthands ();
224
- $ 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;} ' ;
230
+ $ 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" ;
225
231
$ this ->assertSame ($ sExpected , $ oDoc ->__toString ());
226
232
}
227
233
228
234
function testCreateShorthands () {
229
235
$ oDoc = $ this ->parsedStructureForFile ('create-shorthands ' );
230
- $ 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;} ' ;
236
+ $ 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" ;
231
237
$ this ->assertSame ($ sExpected , $ oDoc ->__toString ());
232
238
$ oDoc ->createShorthands ();
233
- $ 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;} ' ;
239
+ $ 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" ;
234
240
$ this ->assertSame ($ sExpected , $ oDoc ->__toString ());
235
241
}
236
242
243
+ function testListValueRemoval () {
244
+ $ oDoc = $ this ->parsedStructureForFile ('atrules ' );
245
+ foreach ($ oDoc ->getContents () as $ oItem ) {
246
+ if ($ oItem instanceof CSSAtRule) {
247
+ $ oDoc ->remove ($ oItem );
248
+ break ;
249
+ }
250
+ }
251
+ $ this ->assertSame ('@charset "utf-8";html, body {font-size: 1.6em;} ' ."\n" , $ oDoc ->__toString ());
252
+
253
+ $ oDoc = $ this ->parsedStructureForFile ('nested ' );
254
+ foreach ($ oDoc ->getAllDeclarationBlocks () as $ oBlock ) {
255
+ $ oDoc ->removeDeclarationBlockBySelector ($ oBlock , false );
256
+ break ;
257
+ }
258
+ $ this ->assertSame ('html {some-other: -test(val1);}
259
+ @media screen {html {some: -test(val2);}
260
+ }#unrelated {other: yes;} ' ."\n" , $ oDoc ->__toString ());
261
+
262
+ $ oDoc = $ this ->parsedStructureForFile ('nested ' );
263
+ foreach ($ oDoc ->getAllDeclarationBlocks () as $ oBlock ) {
264
+ $ oDoc ->removeDeclarationBlockBySelector ($ oBlock , true );
265
+ break ;
266
+ }
267
+ $ this ->assertSame ('@media screen {html {some: -test(val2);}
268
+ }#unrelated {other: yes;} ' ."\n" , $ oDoc ->__toString ());
269
+ }
270
+
237
271
function parsedStructureForFile ($ sFileName ) {
238
272
$ sFile = dirname (__FILE__ ).DIRECTORY_SEPARATOR .'files ' .DIRECTORY_SEPARATOR ."$ sFileName.css " ;
239
273
$ oParser = new CSSParser (file_get_contents ($ sFile ));
240
274
return $ oParser ->parse ();
241
275
}
276
+
242
277
}
0 commit comments