Skip to content

Commit a7747f4

Browse files
committed
[TASK] Add tests for Document::getAllRuleSets()
Part of #757
1 parent 4384bbe commit a7747f4

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;
@@ -148,6 +149,142 @@ public function getAllDeclarationBlocksIgnoresCharset(): void
148149
self::assertSame([], $result);
149150
}
150151

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+
151288
/**
152289
* @test
153290
*/

0 commit comments

Comments
 (0)