diff --git a/tests/ParserTest.php b/tests/ParserTest.php index 4b1fabcd..af3b1ae4 100644 --- a/tests/ParserTest.php +++ b/tests/ParserTest.php @@ -95,60 +95,60 @@ public function colorParsing(): void $selectors = $declarationBlock->getSelectors(); $selector = $selectors[0]->getSelector(); if ($selector === '#mine') { - $colorRules = $declarationBlock->getDeclarations('color'); - $colorRuleValue = $colorRules[0]->getValue(); - self::assertSame('red', $colorRuleValue); - $colorRules = $declarationBlock->getDeclarations('background-'); - $colorRuleValue = $colorRules[0]->getValue(); - self::assertInstanceOf(Color::class, $colorRuleValue); + $colorDeclarations = $declarationBlock->getDeclarations('color'); + $colorDeclarationValue = $colorDeclarations[0]->getValue(); + self::assertSame('red', $colorDeclarationValue); + $colorDeclarations = $declarationBlock->getDeclarations('background-'); + $colorDeclarationValue = $colorDeclarations[0]->getValue(); + self::assertInstanceOf(Color::class, $colorDeclarationValue); 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->getDeclarations('border-color'); - $colorRuleValue = $colorRules[0]->getValue(); - self::assertInstanceOf(Color::class, $colorRuleValue); + 'r' => new Size(35.0, null, true, $colorDeclarationValue->getLineNumber()), + 'g' => new Size(35.0, null, true, $colorDeclarationValue->getLineNumber()), + 'b' => new Size(35.0, null, true, $colorDeclarationValue->getLineNumber()), + ], $colorDeclarationValue->getColor()); + $colorDeclarations = $declarationBlock->getDeclarations('border-color'); + $colorDeclarationValue = $colorDeclarations[0]->getValue(); + self::assertInstanceOf(Color::class, $colorDeclarationValue); self::assertEquals([ - 'r' => new Size(10.0, null, true, $colorRuleValue->getLineNumber()), - 'g' => new Size(100.0, null, true, $colorRuleValue->getLineNumber()), - 'b' => new Size(230.0, null, true, $colorRuleValue->getLineNumber()), - ], $colorRuleValue->getColor()); - $colorRuleValue = $colorRules[1]->getValue(); - self::assertInstanceOf(Color::class, $colorRuleValue); + 'r' => new Size(10.0, null, true, $colorDeclarationValue->getLineNumber()), + 'g' => new Size(100.0, null, true, $colorDeclarationValue->getLineNumber()), + 'b' => new Size(230.0, null, true, $colorDeclarationValue->getLineNumber()), + ], $colorDeclarationValue->getColor()); + $colorDeclarationValue = $colorDeclarations[1]->getValue(); + self::assertInstanceOf(Color::class, $colorDeclarationValue); self::assertEquals([ - 'r' => new Size(10.0, null, true, $colorRuleValue->getLineNumber()), - 'g' => new Size(100.0, null, true, $colorRuleValue->getLineNumber()), - 'b' => new Size(231.0, null, true, $colorRuleValue->getLineNumber()), - 'a' => new Size('0000.3', null, true, $colorRuleValue->getLineNumber()), - ], $colorRuleValue->getColor()); - $colorRules = $declarationBlock->getDeclarations('outline-color'); - $colorRuleValue = $colorRules[0]->getValue(); - self::assertInstanceOf(Color::class, $colorRuleValue); + 'r' => new Size(10.0, null, true, $colorDeclarationValue->getLineNumber()), + 'g' => new Size(100.0, null, true, $colorDeclarationValue->getLineNumber()), + 'b' => new Size(231.0, null, true, $colorDeclarationValue->getLineNumber()), + 'a' => new Size('0000.3', null, true, $colorDeclarationValue->getLineNumber()), + ], $colorDeclarationValue->getColor()); + $colorDeclarations = $declarationBlock->getDeclarations('outline-color'); + $colorDeclarationValue = $colorDeclarations[0]->getValue(); + self::assertInstanceOf(Color::class, $colorDeclarationValue); self::assertEquals([ - 'r' => new Size(34.0, null, true, $colorRuleValue->getLineNumber()), - 'g' => new Size(34.0, null, true, $colorRuleValue->getLineNumber()), - 'b' => new Size(34.0, null, true, $colorRuleValue->getLineNumber()), - ], $colorRuleValue->getColor()); + 'r' => new Size(34.0, null, true, $colorDeclarationValue->getLineNumber()), + 'g' => new Size(34.0, null, true, $colorDeclarationValue->getLineNumber()), + 'b' => new Size(34.0, null, true, $colorDeclarationValue->getLineNumber()), + ], $colorDeclarationValue->getColor()); } elseif ($selector === '#yours') { - $colorRules = $declarationBlock->getDeclarations('background-color'); - $colorRuleValue = $colorRules[0]->getValue(); - self::assertInstanceOf(Color::class, $colorRuleValue); + $colorDeclarations = $declarationBlock->getDeclarations('background-color'); + $colorDeclarationValue = $colorDeclarations[0]->getValue(); + self::assertInstanceOf(Color::class, $colorDeclarationValue); self::assertEquals([ - 'h' => new Size(220.0, null, true, $colorRuleValue->getLineNumber()), - 's' => new Size(10.0, '%', true, $colorRuleValue->getLineNumber()), - 'l' => new Size(220.0, '%', true, $colorRuleValue->getLineNumber()), - ], $colorRuleValue->getColor()); - $colorRuleValue = $colorRules[1]->getValue(); - self::assertInstanceOf(Color::class, $colorRuleValue); + 'h' => new Size(220.0, null, true, $colorDeclarationValue->getLineNumber()), + 's' => new Size(10.0, '%', true, $colorDeclarationValue->getLineNumber()), + 'l' => new Size(220.0, '%', true, $colorDeclarationValue->getLineNumber()), + ], $colorDeclarationValue->getColor()); + $colorDeclarationValue = $colorDeclarations[1]->getValue(); + self::assertInstanceOf(Color::class, $colorDeclarationValue); self::assertEquals([ - 'h' => new Size(220.0, null, true, $colorRuleValue->getLineNumber()), - 's' => new Size(10.0, '%', true, $colorRuleValue->getLineNumber()), - 'l' => new Size(220.0, '%', true, $colorRuleValue->getLineNumber()), - 'a' => new Size(0000.3, null, true, $colorRuleValue->getLineNumber()), - ], $colorRuleValue->getColor()); - $colorRules = $declarationBlock->getDeclarations('outline-color'); - self::assertEmpty($colorRules); + 'h' => new Size(220.0, null, true, $colorDeclarationValue->getLineNumber()), + 's' => new Size(10.0, '%', true, $colorDeclarationValue->getLineNumber()), + 'l' => new Size(220.0, '%', true, $colorDeclarationValue->getLineNumber()), + 'a' => new Size(0000.3, null, true, $colorDeclarationValue->getLineNumber()), + ], $colorDeclarationValue->getColor()); + $colorDeclarations = $declarationBlock->getDeclarations('outline-color'); + self::assertEmpty($colorDeclarations); } } foreach ($document->getAllValues(null, 'color') as $colorValue) { @@ -179,40 +179,40 @@ public function unicodeParsing(): void if (\substr($selector, 0, \strlen('.test-')) !== '.test-') { continue; } - $contentRules = $declarationBlock->getDeclarations('content'); - $firstContentRuleAsString = $contentRules[0]->getValue()->render(OutputFormat::create()); + $contentDeclarations = $declarationBlock->getDeclarations('content'); + $firstContentDeclarationAsString = $contentDeclarations[0]->getValue()->render(OutputFormat::create()); if ($selector === '.test-1') { - self::assertSame('" "', $firstContentRuleAsString); + self::assertSame('" "', $firstContentDeclarationAsString); } if ($selector === '.test-2') { - self::assertSame('"é"', $firstContentRuleAsString); + self::assertSame('"é"', $firstContentDeclarationAsString); } if ($selector === '.test-3') { - self::assertSame('" "', $firstContentRuleAsString); + self::assertSame('" "', $firstContentDeclarationAsString); } if ($selector === '.test-4') { - self::assertSame('"𝄞"', $firstContentRuleAsString); + self::assertSame('"𝄞"', $firstContentDeclarationAsString); } if ($selector === '.test-5') { - self::assertSame('"水"', $firstContentRuleAsString); + self::assertSame('"水"', $firstContentDeclarationAsString); } if ($selector === '.test-6') { - self::assertSame('"¥"', $firstContentRuleAsString); + self::assertSame('"¥"', $firstContentDeclarationAsString); } if ($selector === '.test-7') { - self::assertSame('"\\A"', $firstContentRuleAsString); + self::assertSame('"\\A"', $firstContentDeclarationAsString); } if ($selector === '.test-8') { - self::assertSame('"\\"\\""', $firstContentRuleAsString); + self::assertSame('"\\"\\""', $firstContentDeclarationAsString); } if ($selector === '.test-9') { - self::assertSame('"\\"\'"', $firstContentRuleAsString); + self::assertSame('"\\"\'"', $firstContentDeclarationAsString); } if ($selector === '.test-10') { - self::assertSame('"\'\\\\"', $firstContentRuleAsString); + self::assertSame('"\'\\\\"', $firstContentDeclarationAsString); } if ($selector === '.test-11') { - self::assertSame('"test"', $firstContentRuleAsString); + self::assertSame('"test"', $firstContentDeclarationAsString); } } } @@ -336,24 +336,24 @@ public function manipulation(): void /** * @test */ - public function ruleGetters(): void + public function declarationGetters(): void { $document = self::parsedStructureForFile('values'); $declarationBlocks = $document->getAllDeclarationBlocks(); $headerBlock = $declarationBlocks[0]; $bodyBlock = $declarationBlocks[1]; - $backgroundHeaderRules = $headerBlock->getDeclarations('background-'); - self::assertCount(2, $backgroundHeaderRules); - self::assertSame('background-color', $backgroundHeaderRules[0]->getPropertyName()); - self::assertSame('background-color', $backgroundHeaderRules[1]->getPropertyName()); - $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->removeDeclaration($backgroundHeaderRules['background-color']); - $backgroundHeaderRules = $headerBlock->getDeclarations('background-'); - self::assertCount(1, $backgroundHeaderRules); - self::assertSame('green', $backgroundHeaderRules[0]->getValue()); + $backgroundHeaderDeclarations = $headerBlock->getDeclarations('background-'); + self::assertCount(2, $backgroundHeaderDeclarations); + self::assertSame('background-color', $backgroundHeaderDeclarations[0]->getPropertyName()); + self::assertSame('background-color', $backgroundHeaderDeclarations[1]->getPropertyName()); + $backgroundHeaderDeclarations = $headerBlock->getDeclarationsAssociative('background-'); + self::assertCount(1, $backgroundHeaderDeclarations); + self::assertInstanceOf(Color::class, $backgroundHeaderDeclarations['background-color']->getValue()); + self::assertSame('rgba', $backgroundHeaderDeclarations['background-color']->getValue()->getColorDescription()); + $headerBlock->removeDeclaration($backgroundHeaderDeclarations['background-color']); + $backgroundHeaderDeclarations = $headerBlock->getDeclarations('background-'); + self::assertCount(1, $backgroundHeaderDeclarations); + self::assertSame('green', $backgroundHeaderDeclarations[0]->getValue()); } /** @@ -372,20 +372,20 @@ public function slashedValues(): void } } foreach ($document->getAllDeclarationBlocks() as $declarationBlock) { - $fontRules = $declarationBlock->getDeclarations('font'); - $fontRule = $fontRules[0]; - $fontRuleValue = $fontRule->getValue(); - self::assertSame(' ', $fontRuleValue->getListSeparator()); - $fontRuleValueComponents = $fontRuleValue->getListComponents(); - $commaList = $fontRuleValueComponents[1]; + $fontDeclarations = $declarationBlock->getDeclarations('font'); + $fontDeclaration = $fontDeclarations[0]; + $fontDeclarationValue = $fontDeclaration->getValue(); + self::assertSame(' ', $fontDeclarationValue->getListSeparator()); + $fontDeclarationValueComponents = $fontDeclarationValue->getListComponents(); + $commaList = $fontDeclarationValueComponents[1]; self::assertInstanceOf(ValueList::class, $commaList); - $slashList = $fontRuleValueComponents[0]; + $slashList = $fontDeclarationValueComponents[0]; self::assertInstanceOf(ValueList::class, $slashList); self::assertSame(',', $commaList->getListSeparator()); self::assertSame('/', $slashList->getListSeparator()); - $borderRadiusRules = $declarationBlock->getDeclarations('border-radius'); - $borderRadiusRule = $borderRadiusRules[0]; - $slashList = $borderRadiusRule->getValue(); + $borderRadiusDeclarations = $declarationBlock->getDeclarations('border-radius'); + $borderRadiusDeclaration = $borderRadiusDeclarations[0]; + $slashList = $borderRadiusDeclaration->getValue(); self::assertSame('/', $slashList->getListSeparator()); $slashListComponents = $slashList->getListComponents(); $secondSlashListComponent = $slashListComponents[1]; @@ -883,11 +883,11 @@ public function missingPropertyValueLenient(): void $block = $declarationBlocks[0]; self::assertInstanceOf(DeclarationBlock::class, $block); self::assertEquals([new Selector('div')], $block->getSelectors()); - $rules = $block->getDeclarations(); - self::assertCount(1, $rules); - $rule = $rules[0]; - self::assertSame('display', $rule->getPropertyName()); - self::assertSame('inline-block', $rule->getValue()); + $declarations = $block->getDeclarations(); + self::assertCount(1, $declarations); + $declaration = $declarations[0]; + self::assertSame('display', $declaration->getPropertyName()); + self::assertSame('inline-block', $declaration->getValue()); } /** @@ -943,19 +943,19 @@ public function lineNumbersParsing(): void } } - // Checking for the multiline color rule lines 27-31 + // Checking for the multiline color declaration lines 27-31 $expectedColorLineNumbers = [28, 29, 30]; $declarationBlocks = $document->getAllDeclarationBlocks(); // Choose the 2nd one $secondDeclarationBlock = $declarationBlocks[1]; - $rules = $secondDeclarationBlock->getDeclarations(); + $declarations = $secondDeclarationBlock->getDeclarations(); // Choose the 2nd one - $valueOfSecondRule = $rules[1]->getValue(); - self::assertInstanceOf(Color::class, $valueOfSecondRule); - self::assertSame(27, $rules[1]->getLineNumber()); + $valueOfSecondDeclaration = $declarations[1]->getValue(); + self::assertInstanceOf(Color::class, $valueOfSecondDeclaration); + self::assertSame(27, $declarations[1]->getLineNumber()); $actualColorLineNumbers = []; - foreach ($valueOfSecondRule->getColor() as $size) { + foreach ($valueOfSecondDeclaration->getColor() as $size) { $actualColorLineNumbers[] = $size->getLineNumber(); } @@ -1005,13 +1005,13 @@ public function commentExtracting(): void self::assertSame(' Number 4 ', $fooBarBlockComments[0]->getComment()); self::assertSame(' Number 5 ', $fooBarBlockComments[1]->getComment()); - // Declaration rules. + // Declarations. self::assertInstanceOf(DeclarationBlock::class, $fooBarBlock); - $fooBarRules = $fooBarBlock->getDeclarations(); - $fooBarRule = $fooBarRules[0]; - $fooBarRuleComments = $fooBarRule->getComments(); - self::assertCount(1, $fooBarRuleComments); - self::assertSame(' Number 6 ', $fooBarRuleComments[0]->getComment()); + $fooBarDeclarations = $fooBarBlock->getDeclarations(); + $fooBarDeclaration = $fooBarDeclarations[0]; + $fooBarDeclarationComments = $fooBarDeclaration->getComments(); + self::assertCount(1, $fooBarDeclarationComments); + self::assertSame(' Number 6 ', $fooBarDeclarationComments[0]->getComment()); // Media property. self::assertInstanceOf(Commentable::class, $nodes[2]); @@ -1026,10 +1026,10 @@ public function commentExtracting(): void self::assertCount(1, $fooBarComments); self::assertSame('* Number 10 *', $fooBarComments[0]->getComment()); - // Media -> declaration -> rule. + // Media -> rule -> declaration. self::assertInstanceOf(DeclarationBlock::class, $mediaRules[0]); - $fooBarRules = $mediaRules[0]->getDeclarations(); - $fooBarChildComments = $fooBarRules[0]->getComments(); + $fooBarDeclarations = $mediaRules[0]->getDeclarations(); + $fooBarChildComments = $fooBarDeclarations[0]->getComments(); self::assertCount(1, $fooBarChildComments); self::assertSame('* Number 10b *', $fooBarChildComments[0]->getComment()); } @@ -1044,8 +1044,8 @@ public function flatCommentExtractingOneComment(): void $contents = $document->getContents(); self::assertInstanceOf(DeclarationBlock::class, $contents[0]); - $divRules = $contents[0]->getDeclarations(); - $comments = $divRules[0]->getComments(); + $divDeclarations = $contents[0]->getDeclarations(); + $comments = $divDeclarations[0]->getComments(); self::assertCount(1, $comments); self::assertSame('Find Me!', $comments[0]->getComment()); @@ -1054,15 +1054,15 @@ public function flatCommentExtractingOneComment(): void /** * @test */ - public function flatCommentExtractingTwoConjoinedCommentsForOneRule(): void + public function flatCommentExtractingTwoConjoinedCommentsForOneDeclaration(): void { $parser = new Parser('div {/*Find Me!*//*Find Me Too!*/left:10px; text-align:left;}'); $document = $parser->parse(); $contents = $document->getContents(); self::assertInstanceOf(DeclarationBlock::class, $contents[0]); - $divRules = $contents[0]->getDeclarations(); - $comments = $divRules[0]->getComments(); + $divDeclarations = $contents[0]->getDeclarations(); + $comments = $divDeclarations[0]->getComments(); self::assertCount(2, $comments); self::assertSame('Find Me!', $comments[0]->getComment()); @@ -1072,15 +1072,15 @@ public function flatCommentExtractingTwoConjoinedCommentsForOneRule(): void /** * @test */ - public function flatCommentExtractingTwoSpaceSeparatedCommentsForOneRule(): void + public function flatCommentExtractingTwoSpaceSeparatedCommentsForOneDeclaration(): void { $parser = new Parser('div { /*Find Me!*/ /*Find Me Too!*/ left:10px; text-align:left;}'); $document = $parser->parse(); $contents = $document->getContents(); self::assertInstanceOf(DeclarationBlock::class, $contents[0]); - $divRules = $contents[0]->getDeclarations(); - $comments = $divRules[0]->getComments(); + $divDeclarations = $contents[0]->getDeclarations(); + $comments = $divDeclarations[0]->getComments(); self::assertCount(2, $comments); self::assertSame('Find Me!', $comments[0]->getComment()); @@ -1090,21 +1090,21 @@ public function flatCommentExtractingTwoSpaceSeparatedCommentsForOneRule(): void /** * @test */ - public function flatCommentExtractingCommentsForTwoRules(): void + public function flatCommentExtractingCommentsForTwoDeclarations(): void { $parser = new Parser('div {/*Find Me!*/left:10px; /*Find Me Too!*/text-align:left;}'); $document = $parser->parse(); $contents = $document->getContents(); self::assertInstanceOf(DeclarationBlock::class, $contents[0]); - $divRules = $contents[0]->getDeclarations(); - $rule1Comments = $divRules[0]->getComments(); - $rule2Comments = $divRules[1]->getComments(); - - self::assertCount(1, $rule1Comments); - self::assertCount(1, $rule2Comments); - self::assertSame('Find Me!', $rule1Comments[0]->getComment()); - self::assertSame('Find Me Too!', $rule2Comments[0]->getComment()); + $divDeclarations = $contents[0]->getDeclarations(); + $declaration1Comments = $divDeclarations[0]->getComments(); + $declaration2Comments = $divDeclarations[1]->getComments(); + + self::assertCount(1, $declaration1Comments); + self::assertCount(1, $declaration2Comments); + self::assertSame('Find Me!', $declaration1Comments[0]->getComment()); + self::assertSame('Find Me Too!', $declaration2Comments[0]->getComment()); } /** @@ -1182,10 +1182,10 @@ public function escapedSpecialCaseTokens(): void $document = self::parsedStructureForFile('escaped-tokens'); $contents = $document->getContents(); self::assertInstanceOf(RuleSet::class, $contents[0]); - $rules = $contents[0]->getDeclarations(); - $urlRule = $rules[0]; - $calcRule = $rules[1]; - self::assertInstanceOf(URL::class, $urlRule->getValue()); - self::assertInstanceOf(CalcFunction::class, $calcRule->getValue()); + $declarations = $contents[0]->getDeclarations(); + $urlDeclaration = $declarations[0]; + $calcDeclaration = $declarations[1]; + self::assertInstanceOf(URL::class, $urlDeclaration->getValue()); + self::assertInstanceOf(CalcFunction::class, $calcDeclaration->getValue()); } } diff --git a/tests/RuleSet/DeclarationBlockTest.php b/tests/RuleSet/DeclarationBlockTest.php index b1e16d51..f3e4a9bf 100644 --- a/tests/RuleSet/DeclarationBlockTest.php +++ b/tests/RuleSet/DeclarationBlockTest.php @@ -20,7 +20,7 @@ final class DeclarationBlockTest extends TestCase /** * @test */ - public function overrideRules(): void + public function overrideDeclarations(): void { $css = '.wrapper { left: 10px; text-align: left; }'; $parser = new Parser($css);