From a7747f489b55b27e12e1228c2f0e3407ea6dc889 Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Tue, 25 Feb 2025 10:12:35 +0100 Subject: [PATCH 1/6] [TASK] Add tests for `Document::getAllRuleSets()` Part of #757 --- tests/Unit/CSSList/DocumentTest.php | 137 ++++++++++++++++++++++++++++ 1 file changed, 137 insertions(+) diff --git a/tests/Unit/CSSList/DocumentTest.php b/tests/Unit/CSSList/DocumentTest.php index ed1a2b22..f749d340 100644 --- a/tests/Unit/CSSList/DocumentTest.php +++ b/tests/Unit/CSSList/DocumentTest.php @@ -13,6 +13,7 @@ use Sabberworm\CSS\Property\Charset; use Sabberworm\CSS\Property\Import; use Sabberworm\CSS\Renderable; +use Sabberworm\CSS\RuleSet\AtRuleSet; use Sabberworm\CSS\RuleSet\DeclarationBlock; use Sabberworm\CSS\Value\CSSString; use Sabberworm\CSS\Value\URL; @@ -148,6 +149,142 @@ public function getAllDeclarationBlocksIgnoresCharset(): void self::assertSame([], $result); } + /** + * @test + */ + public function getAllRuleSetsForNoContentsReturnsEmptyArray(): void + { + $subject = new Document(); + + self::assertSame([], $subject->getAllRuleSets()); + } + + /** + * @test + */ + public function getAllRuleSetsCanReturnOneDirectDeclarationBlockContent(): void + { + $subject = new Document(); + + $declarationBlock = new DeclarationBlock(); + $subject->setContents([$declarationBlock]); + + $result = $subject->getAllRuleSets(); + + self::assertSame([$declarationBlock], $result); + } + + /** + * @test + */ + public function getAllRuleSetsCanReturnOneDirectAtRuleSetContent(): void + { + $subject = new Document(); + + $atRuleSet = new AtRuleSet('media'); + $subject->setContents([$atRuleSet]); + + $result = $subject->getAllRuleSets(); + + self::assertSame([$atRuleSet], $result); + } + + /** + * @test + */ + public function getAllRuleSetsCanReturnMultipleDirectDeclarationBlockContents(): void + { + $subject = new Document(); + + $declarationBlock1 = new DeclarationBlock(); + $declarationBlock2 = new DeclarationBlock(); + $subject->setContents([$declarationBlock1, $declarationBlock2]); + + $result = $subject->getAllRuleSets(); + + self::assertSame([$declarationBlock1, $declarationBlock2], $result); + } + + /** + * @test + */ + public function getAllRuleSetsCanReturnMultipleDirectAtRuleSetContents(): void + { + $subject = new Document(); + + $atRuleSet1 = new AtRuleSet('media'); + $atRuleSet2 = new AtRuleSet('media'); + $subject->setContents([$atRuleSet1, $atRuleSet2]); + + $result = $subject->getAllRuleSets(); + + self::assertSame([$atRuleSet1, $atRuleSet2], $result); + } + + /** + * @test + */ + public function getAllRuleSetsReturnsDeclarationBlocksWithinAtRuleBlockList(): void + { + $subject = new Document(); + + $declarationBlock = new DeclarationBlock(); + $atRuleBlockList = new AtRuleBlockList('media'); + $atRuleBlockList->setContents([$declarationBlock]); + $subject->setContents([$atRuleBlockList]); + + $result = $subject->getAllRuleSets(); + + self::assertSame([$declarationBlock], $result); + } + + /** + * @test + */ + public function getAllRuleSetsReturnsAtRuleSetsWithinAtRuleBlockList(): void + { + $subject = new Document(); + + $atRule = new AtRuleSet('media'); + $atRuleBlockList = new AtRuleBlockList('media'); + $atRuleBlockList->setContents([$atRule]); + $subject->setContents([$atRuleBlockList]); + + $result = $subject->getAllRuleSets(); + + self::assertSame([$atRule], $result); + } + + /** + * @test + */ + public function getAllRuleSetsIgnoresImport(): void + { + $subject = new Document(); + + $import = new Import(new URL(new CSSString('https://www.example.com/')), ''); + $subject->setContents([$import]); + + $result = $subject->getAllRuleSets(); + + self::assertSame([], $result); + } + + /** + * @test + */ + public function getAllRuleSetsIgnoresCharset(): void + { + $subject = new Document(); + + $charset = new Charset(new CSSString('UTF-8')); + $subject->setContents([$charset]); + + $result = $subject->getAllRuleSets(); + + self::assertSame([], $result); + } + /** * @test */ From eeb0bfd8a947175f38f83b77cec9ed17c81aa2f6 Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Tue, 25 Feb 2025 11:51:52 +0100 Subject: [PATCH 2/6] Update tests/Unit/CSSList/DocumentTest.php Co-authored-by: JakeQZ --- tests/Unit/CSSList/DocumentTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Unit/CSSList/DocumentTest.php b/tests/Unit/CSSList/DocumentTest.php index f749d340..61594a1a 100644 --- a/tests/Unit/CSSList/DocumentTest.php +++ b/tests/Unit/CSSList/DocumentTest.php @@ -152,7 +152,7 @@ public function getAllDeclarationBlocksIgnoresCharset(): void /** * @test */ - public function getAllRuleSetsForNoContentsReturnsEmptyArray(): void + public function getAllRuleSetsWhenNoContentSetReturnsEmptyArray(): void { $subject = new Document(); From 89e85ef7d2580f16a3a198091cb679959bbd4b30 Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Tue, 25 Feb 2025 11:51:58 +0100 Subject: [PATCH 3/6] Update tests/Unit/CSSList/DocumentTest.php Co-authored-by: JakeQZ --- tests/Unit/CSSList/DocumentTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Unit/CSSList/DocumentTest.php b/tests/Unit/CSSList/DocumentTest.php index 61594a1a..e7f76aab 100644 --- a/tests/Unit/CSSList/DocumentTest.php +++ b/tests/Unit/CSSList/DocumentTest.php @@ -162,7 +162,7 @@ public function getAllRuleSetsWhenNoContentSetReturnsEmptyArray(): void /** * @test */ - public function getAllRuleSetsCanReturnOneDirectDeclarationBlockContent(): void + public function getAllRuleSetsReturnsOneDeclarationBlockDirectlySetAsContent(): void { $subject = new Document(); From 859941853bb6311f045a58e09b8fc04784a46d09 Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Tue, 25 Feb 2025 11:52:05 +0100 Subject: [PATCH 4/6] Update tests/Unit/CSSList/DocumentTest.php Co-authored-by: JakeQZ --- tests/Unit/CSSList/DocumentTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Unit/CSSList/DocumentTest.php b/tests/Unit/CSSList/DocumentTest.php index e7f76aab..7db2fbff 100644 --- a/tests/Unit/CSSList/DocumentTest.php +++ b/tests/Unit/CSSList/DocumentTest.php @@ -177,7 +177,7 @@ public function getAllRuleSetsReturnsOneDeclarationBlockDirectlySetAsContent(): /** * @test */ - public function getAllRuleSetsCanReturnOneDirectAtRuleSetContent(): void + public function getAllRuleSetsReturnsOneAtRuleSetDirectlySetAsContent(): void { $subject = new Document(); From 26e1581afffe043f92848a8ebe3b48bdcb7d1b51 Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Tue, 25 Feb 2025 11:52:11 +0100 Subject: [PATCH 5/6] Update tests/Unit/CSSList/DocumentTest.php Co-authored-by: JakeQZ --- tests/Unit/CSSList/DocumentTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Unit/CSSList/DocumentTest.php b/tests/Unit/CSSList/DocumentTest.php index 7db2fbff..9cebea75 100644 --- a/tests/Unit/CSSList/DocumentTest.php +++ b/tests/Unit/CSSList/DocumentTest.php @@ -208,7 +208,7 @@ public function getAllRuleSetsCanReturnMultipleDirectDeclarationBlockContents(): /** * @test */ - public function getAllRuleSetsCanReturnMultipleDirectAtRuleSetContents(): void + public function getAllRuleSetsReturnsMultipleAtRuleSetsDirectlySetAsContents(): void { $subject = new Document(); From a69d2cbb35c6d84fb0b1c0b34ee64ad69a0229b5 Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Tue, 25 Feb 2025 11:52:17 +0100 Subject: [PATCH 6/6] Update tests/Unit/CSSList/DocumentTest.php Co-authored-by: JakeQZ --- tests/Unit/CSSList/DocumentTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Unit/CSSList/DocumentTest.php b/tests/Unit/CSSList/DocumentTest.php index 9cebea75..07afcf1b 100644 --- a/tests/Unit/CSSList/DocumentTest.php +++ b/tests/Unit/CSSList/DocumentTest.php @@ -192,7 +192,7 @@ public function getAllRuleSetsReturnsOneAtRuleSetDirectlySetAsContent(): void /** * @test */ - public function getAllRuleSetsCanReturnMultipleDirectDeclarationBlockContents(): void + public function getAllRuleSetsReturnsMultipleDeclarationBlocksDirectlySetAsContents(): void { $subject = new Document();