|
13 | 13 | use Sabberworm\CSS\Property\Charset; |
14 | 14 | use Sabberworm\CSS\Property\Import; |
15 | 15 | use Sabberworm\CSS\Renderable; |
| 16 | +use Sabberworm\CSS\RuleSet\AtRuleSet; |
16 | 17 | use Sabberworm\CSS\RuleSet\DeclarationBlock; |
17 | 18 | use Sabberworm\CSS\Value\CSSString; |
18 | 19 | use Sabberworm\CSS\Value\URL; |
@@ -148,6 +149,142 @@ public function getAllDeclarationBlocksIgnoresCharset(): void |
148 | 149 | self::assertSame([], $result); |
149 | 150 | } |
150 | 151 |
|
| 152 | + /** |
| 153 | + * @test |
| 154 | + */ |
| 155 | + public function getAllRuleSetsForNoContentsReturnsEmptyArray(): void |
| 156 | + { |
| 157 | + $subject = new Document(); |
| 158 | + |
| 159 | + self::assertSame([], $subject->getAllRuleSets()); |
| 160 | + } |
| 161 | + |
| 162 | + /** |
| 163 | + * @test |
| 164 | + */ |
| 165 | + public function getAllRuleSetsCanReturnOneDirectDeclarationBlockContent(): void |
| 166 | + { |
| 167 | + $subject = new Document(); |
| 168 | + |
| 169 | + $declarationBlock = new DeclarationBlock(); |
| 170 | + $subject->setContents([$declarationBlock]); |
| 171 | + |
| 172 | + $result = $subject->getAllRuleSets(); |
| 173 | + |
| 174 | + self::assertSame([$declarationBlock], $result); |
| 175 | + } |
| 176 | + |
| 177 | + /** |
| 178 | + * @test |
| 179 | + */ |
| 180 | + public function getAllRuleSetsCanReturnOneDirectAtRuleSetContent(): void |
| 181 | + { |
| 182 | + $subject = new Document(); |
| 183 | + |
| 184 | + $atRuleSet = new AtRuleSet('media'); |
| 185 | + $subject->setContents([$atRuleSet]); |
| 186 | + |
| 187 | + $result = $subject->getAllRuleSets(); |
| 188 | + |
| 189 | + self::assertSame([$atRuleSet], $result); |
| 190 | + } |
| 191 | + |
| 192 | + /** |
| 193 | + * @test |
| 194 | + */ |
| 195 | + public function getAllRuleSetsCanReturnMultipleDirectDeclarationBlockContents(): void |
| 196 | + { |
| 197 | + $subject = new Document(); |
| 198 | + |
| 199 | + $declarationBlock1 = new DeclarationBlock(); |
| 200 | + $declarationBlock2 = new DeclarationBlock(); |
| 201 | + $subject->setContents([$declarationBlock1, $declarationBlock2]); |
| 202 | + |
| 203 | + $result = $subject->getAllRuleSets(); |
| 204 | + |
| 205 | + self::assertSame([$declarationBlock1, $declarationBlock2], $result); |
| 206 | + } |
| 207 | + |
| 208 | + /** |
| 209 | + * @test |
| 210 | + */ |
| 211 | + public function getAllRuleSetsCanReturnMultipleDirectAtRuleSetContents(): void |
| 212 | + { |
| 213 | + $subject = new Document(); |
| 214 | + |
| 215 | + $atRuleSet1 = new AtRuleSet('media'); |
| 216 | + $atRuleSet2 = new AtRuleSet('media'); |
| 217 | + $subject->setContents([$atRuleSet1, $atRuleSet2]); |
| 218 | + |
| 219 | + $result = $subject->getAllRuleSets(); |
| 220 | + |
| 221 | + self::assertSame([$atRuleSet1, $atRuleSet2], $result); |
| 222 | + } |
| 223 | + |
| 224 | + /** |
| 225 | + * @test |
| 226 | + */ |
| 227 | + public function getAllRuleSetsReturnsDeclarationBlocksWithinAtRuleBlockList(): void |
| 228 | + { |
| 229 | + $subject = new Document(); |
| 230 | + |
| 231 | + $declarationBlock = new DeclarationBlock(); |
| 232 | + $atRuleBlockList = new AtRuleBlockList('media'); |
| 233 | + $atRuleBlockList->setContents([$declarationBlock]); |
| 234 | + $subject->setContents([$atRuleBlockList]); |
| 235 | + |
| 236 | + $result = $subject->getAllRuleSets(); |
| 237 | + |
| 238 | + self::assertSame([$declarationBlock], $result); |
| 239 | + } |
| 240 | + |
| 241 | + /** |
| 242 | + * @test |
| 243 | + */ |
| 244 | + public function getAllRuleSetsReturnsAtRuleSetsWithinAtRuleBlockList(): void |
| 245 | + { |
| 246 | + $subject = new Document(); |
| 247 | + |
| 248 | + $atRule = new AtRuleSet('media'); |
| 249 | + $atRuleBlockList = new AtRuleBlockList('media'); |
| 250 | + $atRuleBlockList->setContents([$atRule]); |
| 251 | + $subject->setContents([$atRuleBlockList]); |
| 252 | + |
| 253 | + $result = $subject->getAllRuleSets(); |
| 254 | + |
| 255 | + self::assertSame([$atRule], $result); |
| 256 | + } |
| 257 | + |
| 258 | + /** |
| 259 | + * @test |
| 260 | + */ |
| 261 | + public function getAllRuleSetsIgnoresImport(): void |
| 262 | + { |
| 263 | + $subject = new Document(); |
| 264 | + |
| 265 | + $import = new Import(new URL(new CSSString('https://www.example.com/')), ''); |
| 266 | + $subject->setContents([$import]); |
| 267 | + |
| 268 | + $result = $subject->getAllRuleSets(); |
| 269 | + |
| 270 | + self::assertSame([], $result); |
| 271 | + } |
| 272 | + |
| 273 | + /** |
| 274 | + * @test |
| 275 | + */ |
| 276 | + public function getAllRuleSetsIgnoresCharset(): void |
| 277 | + { |
| 278 | + $subject = new Document(); |
| 279 | + |
| 280 | + $charset = new Charset(new CSSString('UTF-8')); |
| 281 | + $subject->setContents([$charset]); |
| 282 | + |
| 283 | + $result = $subject->getAllRuleSets(); |
| 284 | + |
| 285 | + self::assertSame([], $result); |
| 286 | + } |
| 287 | + |
151 | 288 | /** |
152 | 289 | * @test |
153 | 290 | */ |
|
0 commit comments