Skip to content

Commit 5d5c629

Browse files
committed
Fix unit tests for changed default output.
1 parent dfcbf8c commit 5d5c629

File tree

5 files changed

+72
-52
lines changed

5 files changed

+72
-52
lines changed

lib/Sabberworm/CSS/CSSList/AtRuleBlockList.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ public function __toString() {
3131
}
3232

3333
public function render(\Sabberworm\CSS\OutputFormat $oOutputFormat) {
34-
$sResult = "@{$this->sType} {$this->sArgs}{$oOutputFormat->spaceBeforeOpeningBrace()}{";
34+
$sArgs = $this->sArgs;
35+
if($sArgs) {
36+
$sArgs = ' ' . $sArgs;
37+
}
38+
$sResult = "@{$this->sType}$sArgs{$oOutputFormat->spaceBeforeOpeningBrace()}{";
3539
$sResult .= parent::render($oOutputFormat);
3640
$sResult .= '}';
3741
return $sResult;

lib/Sabberworm/CSS/CSSList/KeyFrame.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function __toString() {
3737

3838
public function render(\Sabberworm\CSS\OutputFormat $oOutputFormat) {
3939
$sResult = "@{$this->vendorKeyFrame} {$this->animationName}{$oOutputFormat->spaceBeforeOpeningBrace()}{";
40-
$sResult .= parent::render($oOutputFormat->nextLevel());
40+
$sResult .= parent::render($oOutputFormat);
4141
$sResult .= '}';
4242
return $sResult;
4343
}

lib/Sabberworm/CSS/RuleSet/AtRuleSet.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ public function __toString() {
3131
}
3232

3333
public function render(\Sabberworm\CSS\OutputFormat $oOutputFormat) {
34-
$sResult = "@{$this->sType} {$this->sArgs}{$oOutputFormat->spaceBeforeOpeningBrace()}{";
34+
$sArgs = $this->sArgs;
35+
if($sArgs) {
36+
$sArgs = ' ' . $sArgs;
37+
}
38+
$sResult = "@{$this->sType}$sArgs{$oOutputFormat->spaceBeforeOpeningBrace()}{";
3539
$sResult .= parent::render($oOutputFormat);
3640
$sResult .= '}';
3741
return $sResult;

tests/Sabberworm/CSS/ParserTest.php

Lines changed: 54 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
class ParserTest extends \PHPUnit_Framework_TestCase {
1111

1212
function testFiles() {
13-
1413
$sDirectory = dirname(__FILE__) . '/../../files';
1514
if ($rHandle = opendir($sDirectory)) {
1615
/* This is the correct way to loop over the directory. */
@@ -74,8 +73,7 @@ function testColorParsing() {
7473
$this->assertSame('red', $sColor);
7574
}
7675
$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());
7977
}
8078

8179
function testUnicodeParsing() {
@@ -156,50 +154,56 @@ function testSpecificity() {
156154

157155
function testManipulation() {
158156
$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;}
160160
@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/),
166167
url-prefix(http://www.w3.org/Style/),
167168
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());
171172
foreach ($oDoc->getAllDeclarationBlocks() as $oBlock) {
172173
foreach ($oBlock->getSelectors() as $oSelector) {
173174
//Loop over all selector parts (the comma-separated strings in a selector) and prepend the id
174175
$oSelector->setSelector('#my_id ' . $oSelector->getSelector());
175176
}
176177
}
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;}
178181
@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/),
184188
url-prefix(http://www.w3.org/Style/),
185189
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());
189193

190194
$oDoc = $this->parsedStructureForFile('values');
191195
$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());
193197
foreach ($oDoc->getAllRuleSets() as $oRuleSet) {
194198
$oRuleSet->removeRule('font-');
195199
}
196200
$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());
198202
foreach ($oDoc->getAllRuleSets() as $oRuleSet) {
199203
$oRuleSet->removeRule('background-');
200204
}
201205
$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());
203207
}
204208

205209
function testRuleGetters() {
@@ -223,7 +227,7 @@ function testRuleGetters() {
223227

224228
function testSlashedValues() {
225229
$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());
227231
foreach ($oDoc->getAllValues(null) as $mValue) {
228232
if ($mValue instanceof Size && $mValue->isSize() && !$mValue->isRelative()) {
229233
$mValue->setSize($mValue->getSize() * 3);
@@ -249,7 +253,7 @@ function testSlashedValues() {
249253
$this->assertEquals(' ', $oSpaceList1->getListSeparator());
250254
$this->assertEquals(' ', $oSpaceList2->getListSeparator());
251255
}
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());
253257
}
254258

255259
function testFunctionSyntax() {
@@ -258,7 +262,7 @@ function testFunctionSyntax() {
258262
.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%;}
259263
.collapser.expanded::before, .collapser.expanded::-moz-before, .collapser.expanded::-webkit-before {-moz-transform: rotate(90deg);}
260264
.collapser + * {height: 0;overflow: hidden;-moz-transition-property: height;-moz-transition-duration: .3s;}
261-
.collapser.expanded + * {height: auto;}' . "\n";
265+
.collapser.expanded + * {height: auto;}';
262266
$this->assertSame($sExpected, $oDoc->render());
263267

264268
foreach ($oDoc->getAllValues(null, true) as $mValue) {
@@ -280,38 +284,42 @@ function testFunctionSyntax() {
280284

281285
function testExpandShorthands() {
282286
$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;}';
284288
$this->assertSame($sExpected, $oDoc->render());
285289
$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;}';
287291
$this->assertSame($sExpected, $oDoc->render());
288292
}
289293

290294
function testCreateShorthands() {
291295
$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;}';
293297
$this->assertSame($sExpected, $oDoc->render());
294298
$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;}';
296300
$this->assertSame($sExpected, $oDoc->render());
297301
}
298302

299303
function testNamespaces() {
300304
$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;}';
303311
$this->assertSame($sExpected, $oDoc->render());
304312
}
305313

306314
function testInnerColors() {
307315
$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%)));}';
309317
$this->assertSame($sExpected, $oDoc->render());
310318
}
311319

312320
function testPrefixedGradient() {
313321
$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);}';
315323
$this->assertSame($sExpected, $oDoc->render());
316324
}
317325

@@ -323,24 +331,24 @@ function testListValueRemoval() {
323331
continue;
324332
}
325333
}
326-
$this->assertSame('html, body {font-size: -.6em;}' . "\n", $oDoc->render());
334+
$this->assertSame('html, body {font-size: -.6em;}', $oDoc->render());
327335

328336
$oDoc = $this->parsedStructureForFile('nested');
329337
foreach ($oDoc->getAllDeclarationBlocks() as $oBlock) {
330338
$oDoc->removeDeclarationBlockBySelector($oBlock, false);
331339
break;
332340
}
333341
$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());
336344

337345
$oDoc = $this->parsedStructureForFile('nested');
338346
foreach ($oDoc->getAllDeclarationBlocks() as $oBlock) {
339347
$oDoc->removeDeclarationBlockBySelector($oBlock, true);
340348
break;
341349
}
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());
344352
}
345353

346354
/**
@@ -351,8 +359,9 @@ function testSelectorRemoval() {
351359
$aBlocks = $oDoc->getAllDeclarationBlocks();
352360
$oBlock1 = $aBlocks[0];
353361
$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;}';
356365
$this->assertSame($sExpected, $oDoc->render());
357366
$this->assertSame(false, $oBlock1->removeSelector('html'));
358367
$this->assertSame(true, $oBlock1->removeSelector('body'));
@@ -362,9 +371,9 @@ function testSelectorRemoval() {
362371

363372
function testComments() {
364373
$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;}}';
368377
$this->assertSame($sExpected, $oDoc->render());
369378
}
370379

tests/Sabberworm/CSS/RuleSet/LenientParsingTest.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function testFaultToleranceOn() {
2020
$sFile = dirname(__FILE__) . '/../../../files' . DIRECTORY_SEPARATOR . "-fault-tolerance.css";
2121
$oParser = new Parser(file_get_contents($sFile), Settings::create()->withLenientParsing(true));
2222
$oResult = $oParser->parse();
23-
$this->assertSame('.test1 {}'."\n".'.test2 {hello: 2.2;hello: 2000000000000.2;}'."\n".'#test {}'."\n".'#test2 {help: none;}'."\n", $oResult->render());
23+
$this->assertSame('.test1 {}'."\n".'.test2 {hello: 2.2;hello: 2000000000000.2;}'."\n".'#test {}'."\n".'#test2 {help: none;}', $oResult->render());
2424
}
2525

2626
/**
@@ -52,22 +52,25 @@ public function testEndToken2Positive() {
5252
$sFile = dirname(__FILE__) . '/../../../files' . DIRECTORY_SEPARATOR . "-end-token-2.css";
5353
$oParser = new Parser(file_get_contents($sFile), Settings::create()->withLenientParsing(true));
5454
$oResult = $oParser->parse();
55-
$this->assertSame('#home .bg-layout {background-image: url("/bundles/main/img/bg1.png?5");}'."\n", $oResult->render());
55+
$this->assertSame('#home .bg-layout {background-image: url("/bundles/main/img/bg1.png?5");}', $oResult->render());
5656
}
5757

5858
public function testLocaleTrap() {
5959
setlocale(LC_ALL, "pt_PT", "no");
6060
$sFile = dirname(__FILE__) . '/../../../files' . DIRECTORY_SEPARATOR . "-fault-tolerance.css";
6161
$oParser = new Parser(file_get_contents($sFile), Settings::create()->withLenientParsing(true));
6262
$oResult = $oParser->parse();
63-
$this->assertSame('.test1 {}'."\n".'.test2 {hello: 2.2;hello: 2000000000000.2;}'."\n".'#test {}'."\n".'#test2 {help: none;}'."\n", $oResult->render());
63+
$this->assertSame('.test1 {}'."\n".'.test2 {hello: 2.2;hello: 2000000000000.2;}'."\n".'#test {}'."\n".'#test2 {help: none;}', $oResult->render());
6464
}
6565

6666
public function testCaseInsensitivity() {
6767
$sFile = dirname(__FILE__) . '/../../../files' . DIRECTORY_SEPARATOR . "case-insensitivity.css";
6868
$oParser = new Parser(file_get_contents($sFile));
6969
$oResult = $oParser->parse();
70-
$this->assertSame('@charset "utf-8";@import url("test.css");@media screen {}#myid {case: insensitive !important;frequency: 30Hz;font-size: 1em;color: #ff0;color: hsl(40,40%,30%);font-family: Arial;}'."\n", $oResult->render());
70+
$this->assertSame('@charset "utf-8";
71+
@import url("test.css");
72+
@media screen {}
73+
#myid {case: insensitive !important;frequency: 30Hz;font-size: 1em;color: #ff0;color: hsl(40,40%,30%);font-family: Arial;}', $oResult->render());
7174
}
7275

7376
}

0 commit comments

Comments
 (0)