|
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\Document;
|
| 11 | +use Sabberworm\CSS\Property\Charset; |
| 12 | +use Sabberworm\CSS\Property\Import; |
10 | 13 | use Sabberworm\CSS\Renderable;
|
11 | 14 | use Sabberworm\CSS\RuleSet\DeclarationBlock;
|
| 15 | +use Sabberworm\CSS\Value\CSSString; |
| 16 | +use Sabberworm\CSS\Value\URL; |
12 | 17 |
|
13 | 18 | /**
|
| 19 | + * @covers \Sabberworm\CSS\CSSList\CSSBlockList |
| 20 | + * @covers \Sabberworm\CSS\CSSList\CSSList |
14 | 21 | * @covers \Sabberworm\CSS\CSSList\Document
|
15 | 22 | */
|
16 | 23 | final class DocumentTest extends TestCase
|
@@ -142,4 +149,92 @@ public function insertContentBeforeAppendsIfSiblingNotFound(): void
|
142 | 149 | self::assertCount(4, $subject->getContents());
|
143 | 150 | self::assertSame([$bogusOne, $sibling, $bogusTwo, $item], $subject->getContents());
|
144 | 151 | }
|
| 152 | + |
| 153 | + /** |
| 154 | + * @test |
| 155 | + */ |
| 156 | + public function getAllDeclarationBlocksForNoContentsReturnsEmptyArray(): void |
| 157 | + { |
| 158 | + $subject = new Document(); |
| 159 | + |
| 160 | + self::assertSame([], $subject->getAllDeclarationBlocks()); |
| 161 | + } |
| 162 | + |
| 163 | + /** |
| 164 | + * @test |
| 165 | + */ |
| 166 | + public function getAllDeclarationBlocksCanReturnOneDirectDeclarationBlockContent(): void |
| 167 | + { |
| 168 | + $subject = new Document(); |
| 169 | + |
| 170 | + $declarationBlock = new DeclarationBlock(); |
| 171 | + $subject->setContents([$declarationBlock]); |
| 172 | + |
| 173 | + $result = $subject->getAllDeclarationBlocks(); |
| 174 | + |
| 175 | + self::assertSame([$declarationBlock], $result); |
| 176 | + } |
| 177 | + |
| 178 | + /** |
| 179 | + * @test |
| 180 | + */ |
| 181 | + public function getAllDeclarationBlocksCanReturnMultipleDirectDeclarationBlockContents(): void |
| 182 | + { |
| 183 | + $subject = new Document(); |
| 184 | + |
| 185 | + $declarationBlock1 = new DeclarationBlock(); |
| 186 | + $declarationBlock2 = new DeclarationBlock(); |
| 187 | + $subject->setContents([$declarationBlock1, $declarationBlock2]); |
| 188 | + |
| 189 | + $result = $subject->getAllDeclarationBlocks(); |
| 190 | + |
| 191 | + self::assertSame([$declarationBlock1, $declarationBlock2], $result); |
| 192 | + } |
| 193 | + |
| 194 | + /** |
| 195 | + * @test |
| 196 | + */ |
| 197 | + public function getAllDeclarationBlocksAlsoReturnsDeclarationBlocksWithinAtRuleBlockList(): void |
| 198 | + { |
| 199 | + $subject = new Document(); |
| 200 | + |
| 201 | + $declarationBlock = new DeclarationBlock(); |
| 202 | + $atRuleBlockList = new AtRuleBlockList('media'); |
| 203 | + $atRuleBlockList->setContents([$declarationBlock]); |
| 204 | + $subject->setContents([$atRuleBlockList]); |
| 205 | + |
| 206 | + $result = $subject->getAllDeclarationBlocks(); |
| 207 | + |
| 208 | + self::assertSame([$declarationBlock], $result); |
| 209 | + } |
| 210 | + |
| 211 | + /** |
| 212 | + * @test |
| 213 | + */ |
| 214 | + public function getAllDeclarationBlocksIgnoresImport(): void |
| 215 | + { |
| 216 | + $subject = new Document(); |
| 217 | + |
| 218 | + $import = new Import(new URL(new CSSString('')), ''); |
| 219 | + $subject->setContents([$import]); |
| 220 | + |
| 221 | + $result = $subject->getAllDeclarationBlocks(); |
| 222 | + |
| 223 | + self::assertSame([], $result); |
| 224 | + } |
| 225 | + |
| 226 | + /** |
| 227 | + * @test |
| 228 | + */ |
| 229 | + public function getAllDeclarationBlocksIgnoresCharset(): void |
| 230 | + { |
| 231 | + $subject = new Document(); |
| 232 | + |
| 233 | + $charset = new Charset(new CSSString('')); |
| 234 | + $subject->setContents([$charset]); |
| 235 | + |
| 236 | + $result = $subject->getAllDeclarationBlocks(); |
| 237 | + |
| 238 | + self::assertSame([], $result); |
| 239 | + } |
145 | 240 | }
|
0 commit comments