Skip to content

Commit 52bd86e

Browse files
committed
[TASK] Add tests for Document::getAllRuleSets()
Part of #757
1 parent ce26af6 commit 52bd86e

File tree

1 file changed

+137
-0
lines changed

1 file changed

+137
-0
lines changed

tests/Unit/CSSList/DocumentTest.php

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Sabberworm\CSS\Property\Charset;
1414
use Sabberworm\CSS\Property\Import;
1515
use Sabberworm\CSS\Renderable;
16+
use Sabberworm\CSS\RuleSet\AtRuleSet;
1617
use Sabberworm\CSS\RuleSet\DeclarationBlock;
1718
use Sabberworm\CSS\Value\CSSString;
1819
use Sabberworm\CSS\Value\URL;
@@ -156,6 +157,142 @@ public function getAllDeclarationBlocksIgnoresCharset(): void
156157
self::assertSame([], $result);
157158
}
158159

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

0 commit comments

Comments
 (0)