Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions tests/Functional/RuleSet/DeclarationBlockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ public function rendersDeclarationsInOrderProvided(): void

$declaration1 = new Declaration('background-color');
$declaration1->setValue('transparent');
$declarationBlock->addRule($declaration1);
$declarationBlock->addDeclaration($declaration1);

$declaration2 = new Declaration('background');
$declaration2->setValue('#222');
$declarationBlock->addRule($declaration2);
$declarationBlock->addDeclaration($declaration2);

$declaration3 = new Declaration('background-color');
$declaration3->setValue('#fff');
$declarationBlock->addRule($declaration3);
$declarationBlock->addDeclaration($declaration3);

$expectedRendering = 'background-color: transparent;background: #222;background-color: #fff';
self::assertStringContainsString($expectedRendering, $declarationBlock->render(new OutputFormat()));
Expand Down
2 changes: 1 addition & 1 deletion tests/Functional/RuleSet/RuleSetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,6 @@ static function (array $nameAndValue): Declaration {
},
$propertyNamesAndValues
);
$this->subject->setRules($declarationsToSet);
$this->subject->setDeclarations($declarationsToSet);
}
}
48 changes: 24 additions & 24 deletions tests/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,18 @@ public function colorParsing(): void
$selectors = $declarationBlock->getSelectors();
$selector = $selectors[0]->getSelector();
if ($selector === '#mine') {
$colorRules = $declarationBlock->getRules('color');
$colorRules = $declarationBlock->getDeclarations('color');
$colorRuleValue = $colorRules[0]->getValue();
self::assertSame('red', $colorRuleValue);
$colorRules = $declarationBlock->getRules('background-');
$colorRules = $declarationBlock->getDeclarations('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 = $declarationBlock->getRules('border-color');
$colorRules = $declarationBlock->getDeclarations('border-color');
$colorRuleValue = $colorRules[0]->getValue();
self::assertInstanceOf(Color::class, $colorRuleValue);
self::assertEquals([
Expand All @@ -122,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 = $declarationBlock->getRules('outline-color');
$colorRules = $declarationBlock->getDeclarations('outline-color');
$colorRuleValue = $colorRules[0]->getValue();
self::assertInstanceOf(Color::class, $colorRuleValue);
self::assertEquals([
Expand All @@ -131,7 +131,7 @@ public function colorParsing(): void
'b' => new Size(34.0, null, true, $colorRuleValue->getLineNumber()),
], $colorRuleValue->getColor());
} elseif ($selector === '#yours') {
$colorRules = $declarationBlock->getRules('background-color');
$colorRules = $declarationBlock->getDeclarations('background-color');
$colorRuleValue = $colorRules[0]->getValue();
self::assertInstanceOf(Color::class, $colorRuleValue);
self::assertEquals([
Expand All @@ -147,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 = $declarationBlock->getRules('outline-color');
$colorRules = $declarationBlock->getDeclarations('outline-color');
self::assertEmpty($colorRules);
}
}
Expand Down Expand Up @@ -179,7 +179,7 @@ public function unicodeParsing(): void
if (\substr($selector, 0, \strlen('.test-')) !== '.test-') {
continue;
}
$contentRules = $declarationBlock->getRules('content');
$contentRules = $declarationBlock->getDeclarations('content');
$firstContentRuleAsString = $contentRules[0]->getValue()->render(OutputFormat::create());
if ($selector === '.test-1') {
self::assertSame('" "', $firstContentRuleAsString);
Expand Down Expand Up @@ -315,7 +315,7 @@ public function manipulation(): void
$document->render()
);
foreach ($document->getAllRuleSets() as $ruleSet) {
$ruleSet->removeMatchingRules('font-');
$ruleSet->removeMatchingDeclarations('font-');
}
self::assertSame(
'#header {margin: 10px 2em 1cm 2%;color: red !important;background-color: green;'
Expand All @@ -324,7 +324,7 @@ public function manipulation(): void
$document->render()
);
foreach ($document->getAllRuleSets() as $ruleSet) {
$ruleSet->removeMatchingRules('background-');
$ruleSet->removeMatchingDeclarations('background-');
}
self::assertSame(
'#header {margin: 10px 2em 1cm 2%;color: red !important;frequency: 30Hz;transform: rotate(1turn);}
Expand All @@ -342,16 +342,16 @@ public function ruleGetters(): void
$declarationBlocks = $document->getAllDeclarationBlocks();
$headerBlock = $declarationBlocks[0];
$bodyBlock = $declarationBlocks[1];
$backgroundHeaderRules = $headerBlock->getRules('background-');
$backgroundHeaderRules = $headerBlock->getDeclarations('background-');
self::assertCount(2, $backgroundHeaderRules);
self::assertSame('background-color', $backgroundHeaderRules[0]->getPropertyName());
self::assertSame('background-color', $backgroundHeaderRules[1]->getPropertyName());
$backgroundHeaderRules = $headerBlock->getRulesAssoc('background-');
$backgroundHeaderRules = $headerBlock->getDeclarationsAssociative('background-');
self::assertCount(1, $backgroundHeaderRules);
self::assertInstanceOf(Color::class, $backgroundHeaderRules['background-color']->getValue());
self::assertSame('rgba', $backgroundHeaderRules['background-color']->getValue()->getColorDescription());
$headerBlock->removeRule($backgroundHeaderRules['background-color']);
$backgroundHeaderRules = $headerBlock->getRules('background-');
$headerBlock->removeDeclaration($backgroundHeaderRules['background-color']);
$backgroundHeaderRules = $headerBlock->getDeclarations('background-');
self::assertCount(1, $backgroundHeaderRules);
self::assertSame('green', $backgroundHeaderRules[0]->getValue());
}
Expand All @@ -372,7 +372,7 @@ public function slashedValues(): void
}
}
foreach ($document->getAllDeclarationBlocks() as $declarationBlock) {
$fontRules = $declarationBlock->getRules('font');
$fontRules = $declarationBlock->getDeclarations('font');
$fontRule = $fontRules[0];
$fontRuleValue = $fontRule->getValue();
self::assertSame(' ', $fontRuleValue->getListSeparator());
Expand All @@ -383,7 +383,7 @@ public function slashedValues(): void
self::assertInstanceOf(ValueList::class, $slashList);
self::assertSame(',', $commaList->getListSeparator());
self::assertSame('/', $slashList->getListSeparator());
$borderRadiusRules = $declarationBlock->getRules('border-radius');
$borderRadiusRules = $declarationBlock->getDeclarations('border-radius');
$borderRadiusRule = $borderRadiusRules[0];
$slashList = $borderRadiusRule->getValue();
self::assertSame('/', $slashList->getListSeparator());
Expand Down Expand Up @@ -883,7 +883,7 @@ public function missingPropertyValueLenient(): void
$block = $declarationBlocks[0];
self::assertInstanceOf(DeclarationBlock::class, $block);
self::assertEquals([new Selector('div')], $block->getSelectors());
$rules = $block->getRules();
$rules = $block->getDeclarations();
self::assertCount(1, $rules);
$rule = $rules[0];
self::assertSame('display', $rule->getPropertyName());
Expand Down Expand Up @@ -948,7 +948,7 @@ public function lineNumbersParsing(): void
$declarationBlocks = $document->getAllDeclarationBlocks();
// Choose the 2nd one
$secondDeclarationBlock = $declarationBlocks[1];
$rules = $secondDeclarationBlock->getRules();
$rules = $secondDeclarationBlock->getDeclarations();
// Choose the 2nd one
$valueOfSecondRule = $rules[1]->getValue();
self::assertInstanceOf(Color::class, $valueOfSecondRule);
Expand Down Expand Up @@ -1007,7 +1007,7 @@ public function commentExtracting(): void

// Declaration rules.
self::assertInstanceOf(DeclarationBlock::class, $fooBarBlock);
$fooBarRules = $fooBarBlock->getRules();
$fooBarRules = $fooBarBlock->getDeclarations();
$fooBarRule = $fooBarRules[0];
$fooBarRuleComments = $fooBarRule->getComments();
self::assertCount(1, $fooBarRuleComments);
Expand All @@ -1028,7 +1028,7 @@ public function commentExtracting(): void

// Media -> declaration -> rule.
self::assertInstanceOf(DeclarationBlock::class, $mediaRules[0]);
$fooBarRules = $mediaRules[0]->getRules();
$fooBarRules = $mediaRules[0]->getDeclarations();
$fooBarChildComments = $fooBarRules[0]->getComments();
self::assertCount(1, $fooBarChildComments);
self::assertSame('* Number 10b *', $fooBarChildComments[0]->getComment());
Expand All @@ -1044,7 +1044,7 @@ public function flatCommentExtractingOneComment(): void

$contents = $document->getContents();
self::assertInstanceOf(DeclarationBlock::class, $contents[0]);
$divRules = $contents[0]->getRules();
$divRules = $contents[0]->getDeclarations();
$comments = $divRules[0]->getComments();

self::assertCount(1, $comments);
Expand All @@ -1061,7 +1061,7 @@ public function flatCommentExtractingTwoConjoinedCommentsForOneRule(): void

$contents = $document->getContents();
self::assertInstanceOf(DeclarationBlock::class, $contents[0]);
$divRules = $contents[0]->getRules();
$divRules = $contents[0]->getDeclarations();
$comments = $divRules[0]->getComments();

self::assertCount(2, $comments);
Expand All @@ -1079,7 +1079,7 @@ public function flatCommentExtractingTwoSpaceSeparatedCommentsForOneRule(): void

$contents = $document->getContents();
self::assertInstanceOf(DeclarationBlock::class, $contents[0]);
$divRules = $contents[0]->getRules();
$divRules = $contents[0]->getDeclarations();
$comments = $divRules[0]->getComments();

self::assertCount(2, $comments);
Expand All @@ -1097,7 +1097,7 @@ public function flatCommentExtractingCommentsForTwoRules(): void

$contents = $document->getContents();
self::assertInstanceOf(DeclarationBlock::class, $contents[0]);
$divRules = $contents[0]->getRules();
$divRules = $contents[0]->getDeclarations();
$rule1Comments = $divRules[0]->getComments();
$rule2Comments = $divRules[1]->getComments();

Expand Down Expand Up @@ -1182,7 +1182,7 @@ public function escapedSpecialCaseTokens(): void
$document = self::parsedStructureForFile('escaped-tokens');
$contents = $document->getContents();
self::assertInstanceOf(RuleSet::class, $contents[0]);
$rules = $contents[0]->getRules();
$rules = $contents[0]->getDeclarations();
$urlRule = $rules[0];
$calcRule = $rules[1];
self::assertInstanceOf(URL::class, $urlRule->getValue());
Expand Down
18 changes: 9 additions & 9 deletions tests/RuleSet/DeclarationBlockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ public function overrideRules(): void
$wrapper = $contents[0];

self::assertInstanceOf(DeclarationBlock::class, $wrapper);
self::assertCount(2, $wrapper->getRules());
$wrapper->setRules([$declaration]);
self::assertCount(2, $wrapper->getDeclarations());
$wrapper->setDeclarations([$declaration]);

$declarations = $wrapper->getRules();
$declarations = $wrapper->getDeclarations();
self::assertCount(1, $declarations);
self::assertSame('right', $declarations[0]->getPropertyName());
self::assertSame('-10px', $declarations[0]->getValue());
Expand All @@ -53,11 +53,11 @@ public function declarationInsertion(): void

self::assertInstanceOf(DeclarationBlock::class, $wrapper);

$leftDeclarations = $wrapper->getRules('left');
$leftDeclarations = $wrapper->getDeclarations('left');
self::assertCount(1, $leftDeclarations);
$firstLeftDeclaration = $leftDeclarations[0];

$textDeclarations = $wrapper->getRules('text-');
$textDeclarations = $wrapper->getDeclarations('text-');
self::assertCount(1, $textDeclarations);
$firstTextDeclaration = $textDeclarations[0];

Expand All @@ -70,11 +70,11 @@ public function declarationInsertion(): void
$borderBottomDeclaration = new Declaration('border-bottom-width');
$borderBottomDeclaration->setValue(new Size(1, 'px'));

$wrapper->addRule($borderBottomDeclaration);
$wrapper->addRule($leftPrefixDeclaration, $firstLeftDeclaration);
$wrapper->addRule($textAlignDeclaration, $firstTextDeclaration);
$wrapper->addDeclaration($borderBottomDeclaration);
$wrapper->addDeclaration($leftPrefixDeclaration, $firstLeftDeclaration);
$wrapper->addDeclaration($textAlignDeclaration, $firstTextDeclaration);

$declarations = $wrapper->getRules();
$declarations = $wrapper->getDeclarations();

self::assertSame($leftPrefixDeclaration, $declarations[0]);
self::assertSame($firstLeftDeclaration, $declarations[1]);
Expand Down
24 changes: 12 additions & 12 deletions tests/Unit/CSSList/CSSBlockListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ public function getAllValuesReturnsOneValueDirectlySetAsContent(): void
$declarationBlock = new DeclarationBlock();
$declaration = new Declaration('font-family');
$declaration->setValue($value);
$declarationBlock->addRule($declaration);
$declarationBlock->addDeclaration($declaration);
$subject->setContents([$declarationBlock]);

$result = $subject->getAllValues();
Expand All @@ -323,10 +323,10 @@ public function getAllValuesReturnsMultipleValuesDirectlySetAsContentInOneDeclar
$declarationBlock = new DeclarationBlock();
$declaration1 = new Declaration('font-family');
$declaration1->setValue($value1);
$declarationBlock->addRule($declaration1);
$declarationBlock->addDeclaration($declaration1);
$declaration2 = new Declaration('color');
$declaration2->setValue($value2);
$declarationBlock->addRule($declaration2);
$declarationBlock->addDeclaration($declaration2);
$subject->setContents([$declarationBlock]);

$result = $subject->getAllValues();
Expand All @@ -347,11 +347,11 @@ public function getAllValuesReturnsMultipleValuesDirectlySetAsContentInMultipleD
$declarationBlock1 = new DeclarationBlock();
$declaration1 = new Declaration('font-family');
$declaration1->setValue($value1);
$declarationBlock1->addRule($declaration1);
$declarationBlock1->addDeclaration($declaration1);
$declarationBlock2 = new DeclarationBlock();
$declaration2 = new Declaration('color');
$declaration2->setValue($value2);
$declarationBlock2->addRule($declaration2);
$declarationBlock2->addDeclaration($declaration2);
$subject->setContents([$declarationBlock1, $declarationBlock2]);

$result = $subject->getAllValues();
Expand All @@ -371,7 +371,7 @@ public function getAllValuesReturnsValuesWithinAtRuleBlockList(): void
$declarationBlock = new DeclarationBlock();
$declaration = new Declaration('font-family');
$declaration->setValue($value);
$declarationBlock->addRule($declaration);
$declarationBlock->addDeclaration($declaration);
$atRuleBlockList = new AtRuleBlockList('media');
$atRuleBlockList->setContents([$declarationBlock]);
$subject->setContents([$atRuleBlockList]);
Expand All @@ -394,11 +394,11 @@ public function getAllValuesWithElementProvidedReturnsOnlyValuesWithinThatElemen
$declarationBlock1 = new DeclarationBlock();
$declaration1 = new Declaration('font-family');
$declaration1->setValue($value1);
$declarationBlock1->addRule($declaration1);
$declarationBlock1->addDeclaration($declaration1);
$declarationBlock2 = new DeclarationBlock();
$declaration2 = new Declaration('color');
$declaration2->setValue($value2);
$declarationBlock2->addRule($declaration2);
$declarationBlock2->addDeclaration($declaration2);
$subject->setContents([$declarationBlock1, $declarationBlock2]);

$result = $subject->getAllValues($declarationBlock1);
Expand All @@ -419,10 +419,10 @@ public function getAllValuesWithSearchStringProvidedReturnsOnlyValuesFromMatchin
$declarationBlock = new DeclarationBlock();
$declaration1 = new Declaration('font-family');
$declaration1->setValue($value1);
$declarationBlock->addRule($declaration1);
$declarationBlock->addDeclaration($declaration1);
$declaration2 = new Declaration('color');
$declaration2->setValue($value2);
$declarationBlock->addRule($declaration2);
$declarationBlock->addDeclaration($declaration2);
$subject->setContents([$declarationBlock]);

$result = $subject->getAllValues(null, 'font-');
Expand All @@ -443,7 +443,7 @@ public function getAllValuesByDefaultDoesNotReturnValuesInFunctionArguments(): v
$declarationBlock = new DeclarationBlock();
$declaration = new Declaration('margin');
$declaration->setValue(new CSSFunction('max', [$value1, $value2]));
$declarationBlock->addRule($declaration);
$declarationBlock->addDeclaration($declaration);
$subject->setContents([$declarationBlock]);

$result = $subject->getAllValues();
Expand All @@ -464,7 +464,7 @@ public function getAllValuesWithSearchInFunctionArgumentsReturnsValuesInFunction
$declarationBlock = new DeclarationBlock();
$declaration = new Declaration('margin');
$declaration->setValue(new CSSFunction('max', [$value1, $value2]));
$declarationBlock->addRule($declaration);
$declarationBlock->addDeclaration($declaration);
$subject->setContents([$declarationBlock]);

$result = $subject->getAllValues(null, null, true);
Expand Down
Loading