|
6 | 6 |
|
7 | 7 | use PHPUnit\Framework\TestCase; |
8 | 8 | use Sabberworm\CSS\Comment\Commentable; |
| 9 | +use Sabberworm\CSS\CSSList\AtRuleBlockList; |
9 | 10 | use Sabberworm\CSS\CSSList\CSSBlockList; |
10 | 11 | use Sabberworm\CSS\CSSList\CSSList; |
11 | 12 | use Sabberworm\CSS\CSSList\Document; |
| 13 | +use Sabberworm\CSS\Property\Charset; |
| 14 | +use Sabberworm\CSS\Property\Import; |
12 | 15 | use Sabberworm\CSS\Renderable; |
| 16 | +use Sabberworm\CSS\RuleSet\AtRuleSet; |
| 17 | +use Sabberworm\CSS\RuleSet\DeclarationBlock; |
| 18 | +use Sabberworm\CSS\Value\CSSString; |
| 19 | +use Sabberworm\CSS\Value\URL; |
13 | 20 |
|
14 | 21 | /** |
15 | 22 | * @covers \Sabberworm\CSS\CSSList\CSSBlockList |
@@ -54,6 +61,142 @@ public function isCSSList(): void |
54 | 61 | self::assertInstanceOf(CSSList::class, $subject); |
55 | 62 | } |
56 | 63 |
|
| 64 | + /** |
| 65 | + * @test |
| 66 | + */ |
| 67 | + public function getAllRuleSetsWhenNoContentSetReturnsEmptyArray(): void |
| 68 | + { |
| 69 | + $subject = new Document(); |
| 70 | + |
| 71 | + self::assertSame([], $subject->getAllRuleSets()); |
| 72 | + } |
| 73 | + |
| 74 | + /** |
| 75 | + * @test |
| 76 | + */ |
| 77 | + public function getAllRuleSetsReturnsOneDeclarationBlockDirectlySetAsContent(): void |
| 78 | + { |
| 79 | + $subject = new Document(); |
| 80 | + |
| 81 | + $declarationBlock = new DeclarationBlock(); |
| 82 | + $subject->setContents([$declarationBlock]); |
| 83 | + |
| 84 | + $result = $subject->getAllRuleSets(); |
| 85 | + |
| 86 | + self::assertSame([$declarationBlock], $result); |
| 87 | + } |
| 88 | + |
| 89 | + /** |
| 90 | + * @test |
| 91 | + */ |
| 92 | + public function getAllRuleSetsReturnsOneAtRuleSetDirectlySetAsContent(): void |
| 93 | + { |
| 94 | + $subject = new Document(); |
| 95 | + |
| 96 | + $atRuleSet = new AtRuleSet('media'); |
| 97 | + $subject->setContents([$atRuleSet]); |
| 98 | + |
| 99 | + $result = $subject->getAllRuleSets(); |
| 100 | + |
| 101 | + self::assertSame([$atRuleSet], $result); |
| 102 | + } |
| 103 | + |
| 104 | + /** |
| 105 | + * @test |
| 106 | + */ |
| 107 | + public function getAllRuleSetsReturnsMultipleDeclarationBlocksDirectlySetAsContents(): void |
| 108 | + { |
| 109 | + $subject = new Document(); |
| 110 | + |
| 111 | + $declarationBlock1 = new DeclarationBlock(); |
| 112 | + $declarationBlock2 = new DeclarationBlock(); |
| 113 | + $subject->setContents([$declarationBlock1, $declarationBlock2]); |
| 114 | + |
| 115 | + $result = $subject->getAllRuleSets(); |
| 116 | + |
| 117 | + self::assertSame([$declarationBlock1, $declarationBlock2], $result); |
| 118 | + } |
| 119 | + |
| 120 | + /** |
| 121 | + * @test |
| 122 | + */ |
| 123 | + public function getAllRuleSetsReturnsMultipleAtRuleSetsDirectlySetAsContents(): void |
| 124 | + { |
| 125 | + $subject = new Document(); |
| 126 | + |
| 127 | + $atRuleSet1 = new AtRuleSet('media'); |
| 128 | + $atRuleSet2 = new AtRuleSet('media'); |
| 129 | + $subject->setContents([$atRuleSet1, $atRuleSet2]); |
| 130 | + |
| 131 | + $result = $subject->getAllRuleSets(); |
| 132 | + |
| 133 | + self::assertSame([$atRuleSet1, $atRuleSet2], $result); |
| 134 | + } |
| 135 | + |
| 136 | + /** |
| 137 | + * @test |
| 138 | + */ |
| 139 | + public function getAllRuleSetsReturnsDeclarationBlocksWithinAtRuleBlockList(): void |
| 140 | + { |
| 141 | + $subject = new Document(); |
| 142 | + |
| 143 | + $declarationBlock = new DeclarationBlock(); |
| 144 | + $atRuleBlockList = new AtRuleBlockList('media'); |
| 145 | + $atRuleBlockList->setContents([$declarationBlock]); |
| 146 | + $subject->setContents([$atRuleBlockList]); |
| 147 | + |
| 148 | + $result = $subject->getAllRuleSets(); |
| 149 | + |
| 150 | + self::assertSame([$declarationBlock], $result); |
| 151 | + } |
| 152 | + |
| 153 | + /** |
| 154 | + * @test |
| 155 | + */ |
| 156 | + public function getAllRuleSetsReturnsAtRuleSetsWithinAtRuleBlockList(): void |
| 157 | + { |
| 158 | + $subject = new Document(); |
| 159 | + |
| 160 | + $atRule = new AtRuleSet('media'); |
| 161 | + $atRuleBlockList = new AtRuleBlockList('media'); |
| 162 | + $atRuleBlockList->setContents([$atRule]); |
| 163 | + $subject->setContents([$atRuleBlockList]); |
| 164 | + |
| 165 | + $result = $subject->getAllRuleSets(); |
| 166 | + |
| 167 | + self::assertSame([$atRule], $result); |
| 168 | + } |
| 169 | + |
| 170 | + /** |
| 171 | + * @test |
| 172 | + */ |
| 173 | + public function getAllRuleSetsIgnoresImport(): void |
| 174 | + { |
| 175 | + $subject = new Document(); |
| 176 | + |
| 177 | + $import = new Import(new URL(new CSSString('https://www.example.com/')), ''); |
| 178 | + $subject->setContents([$import]); |
| 179 | + |
| 180 | + $result = $subject->getAllRuleSets(); |
| 181 | + |
| 182 | + self::assertSame([], $result); |
| 183 | + } |
| 184 | + |
| 185 | + /** |
| 186 | + * @test |
| 187 | + */ |
| 188 | + public function getAllRuleSetsIgnoresCharset(): void |
| 189 | + { |
| 190 | + $subject = new Document(); |
| 191 | + |
| 192 | + $charset = new Charset(new CSSString('UTF-8')); |
| 193 | + $subject->setContents([$charset]); |
| 194 | + |
| 195 | + $result = $subject->getAllRuleSets(); |
| 196 | + |
| 197 | + self::assertSame([], $result); |
| 198 | + } |
| 199 | + |
57 | 200 | /** |
58 | 201 | * @test |
59 | 202 | */ |
|
0 commit comments