Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 11 additions & 14 deletions tests/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,25 +91,22 @@ public function files(): void
public function colorParsing(): void
{
$document = self::parsedStructureForFile('colortest');
foreach ($document->getAllRuleSets() as $ruleSet) {
if (!($ruleSet instanceof DeclarationBlock)) {
continue;
}
$selectors = $ruleSet->getSelectors();
foreach ($document->getAllDeclarationBlocks() as $declarationBlock) {
$selectors = $declarationBlock->getSelectors();
$selector = $selectors[0]->getSelector();
if ($selector === '#mine') {
$colorRules = $ruleSet->getRules('color');
$colorRules = $declarationBlock->getRules('color');
$colorRuleValue = $colorRules[0]->getValue();
self::assertSame('red', $colorRuleValue);
$colorRules = $ruleSet->getRules('background-');
$colorRules = $declarationBlock->getRules('background-');
$colorRuleValue = $colorRules[0]->getValue();
self::assertInstanceOf(Color::class, $colorRuleValue);
self::assertEquals([
'r' => new Size(35.0, null, true, $colorRuleValue->getLineNumber()),
'g' => new Size(35.0, null, true, $colorRuleValue->getLineNumber()),
'b' => new Size(35.0, null, true, $colorRuleValue->getLineNumber()),
], $colorRuleValue->getColor());
$colorRules = $ruleSet->getRules('border-color');
$colorRules = $declarationBlock->getRules('border-color');
$colorRuleValue = $colorRules[0]->getValue();
self::assertInstanceOf(Color::class, $colorRuleValue);
self::assertEquals([
Expand All @@ -125,7 +122,7 @@ public function colorParsing(): void
'b' => new Size(231.0, null, true, $colorRuleValue->getLineNumber()),
'a' => new Size('0000.3', null, true, $colorRuleValue->getLineNumber()),
], $colorRuleValue->getColor());
$colorRules = $ruleSet->getRules('outline-color');
$colorRules = $declarationBlock->getRules('outline-color');
$colorRuleValue = $colorRules[0]->getValue();
self::assertInstanceOf(Color::class, $colorRuleValue);
self::assertEquals([
Expand All @@ -134,7 +131,7 @@ public function colorParsing(): void
'b' => new Size(34.0, null, true, $colorRuleValue->getLineNumber()),
], $colorRuleValue->getColor());
} elseif ($selector === '#yours') {
$colorRules = $ruleSet->getRules('background-color');
$colorRules = $declarationBlock->getRules('background-color');
$colorRuleValue = $colorRules[0]->getValue();
self::assertInstanceOf(Color::class, $colorRuleValue);
self::assertEquals([
Expand All @@ -150,7 +147,7 @@ public function colorParsing(): void
'l' => new Size(220.0, '%', true, $colorRuleValue->getLineNumber()),
'a' => new Size(0000.3, null, true, $colorRuleValue->getLineNumber()),
], $colorRuleValue->getColor());
$colorRules = $ruleSet->getRules('outline-color');
$colorRules = $declarationBlock->getRules('outline-color');
self::assertEmpty($colorRules);
}
}
Expand Down Expand Up @@ -179,13 +176,13 @@ public function colorParsing(): void
public function unicodeParsing(): void
{
$document = self::parsedStructureForFile('unicode');
foreach ($document->getAllDeclarationBlocks() as $ruleSet) {
$selectors = $ruleSet->getSelectors();
foreach ($document->getAllDeclarationBlocks() as $declarationBlock) {
$selectors = $declarationBlock->getSelectors();
$selector = $selectors[0]->getSelector();
if (\substr($selector, 0, \strlen('.test-')) !== '.test-') {
continue;
}
$contentRules = $ruleSet->getRules('content');
$contentRules = $declarationBlock->getRules('content');
$firstContentRuleAsString = $contentRules[0]->getValue()->render(OutputFormat::create());
if ($selector === '.test-1') {
self::assertSame('" "', $firstContentRuleAsString);
Expand Down