Skip to content

Commit e57a7ba

Browse files
authored
[TASK] Add tests for removeDeclarationBlockBySelector() (#1335)
1 parent e5e24f7 commit e57a7ba

File tree

1 file changed

+137
-0
lines changed

1 file changed

+137
-0
lines changed

tests/Unit/CSSList/CSSListTest.php

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Sabberworm\CSS\Comment\Commentable;
99
use Sabberworm\CSS\CSSElement;
1010
use Sabberworm\CSS\CSSList\CSSListItem;
11+
use Sabberworm\CSS\Property\Selector;
1112
use Sabberworm\CSS\Renderable;
1213
use Sabberworm\CSS\RuleSet\DeclarationBlock;
1314
use Sabberworm\CSS\Tests\Unit\CSSList\Fixtures\ConcreteCSSList;
@@ -189,4 +190,140 @@ public function insertBeforeAppendsIfSiblingNotFound(): void
189190
self::assertCount(4, $subject->getContents());
190191
self::assertSame([$bogusOne, $sibling, $bogusTwo, $item], $subject->getContents());
191192
}
193+
194+
/**
195+
* @test
196+
*/
197+
public function removeDeclarationBlockBySelectorRemovesDeclarationBlockProvided(): void
198+
{
199+
$subject = new ConcreteCSSList();
200+
$declarationBlock = new DeclarationBlock();
201+
$declarationBlock->setSelectors(['html', 'body']);
202+
$subject->setContents([$declarationBlock]);
203+
self::assertNotSame([], $subject->getContents()); // make sure contents are set
204+
205+
$subject->removeDeclarationBlockBySelector($declarationBlock);
206+
207+
self::assertSame([], $subject->getContents());
208+
}
209+
210+
/**
211+
* @test
212+
*/
213+
public function removeDeclarationBlockBySelectorRemovesDeclarationBlockWithSelectorsProvidedFromItself(): void
214+
{
215+
$subject = new ConcreteCSSList();
216+
$declarationBlock = new DeclarationBlock();
217+
$declarationBlock->setSelectors(['html', 'body']);
218+
$subject->setContents([$declarationBlock]);
219+
self::assertNotSame([], $subject->getContents()); // make sure contents are set
220+
221+
$subject->removeDeclarationBlockBySelector($declarationBlock->getSelectors());
222+
223+
self::assertSame([], $subject->getContents());
224+
}
225+
226+
/**
227+
* @test
228+
*/
229+
public function removeDeclarationBlockBySelectorRemovesDeclarationBlockWithOutsourcedSelectorsProvided(): void
230+
{
231+
$subject = new ConcreteCSSList();
232+
$declarationBlock = new DeclarationBlock();
233+
$declarationBlock->setSelectors(['html', 'body']);
234+
$subject->setContents([$declarationBlock]);
235+
self::assertNotSame([], $subject->getContents()); // make sure contents are set
236+
237+
$subject->removeDeclarationBlockBySelector([new Selector('html'), new Selector('body')]);
238+
239+
self::assertSame([], $subject->getContents());
240+
}
241+
242+
/**
243+
* @test
244+
*/
245+
public function removeDeclarationBlockBySelectorRemovesDeclarationBlockWithStringSelectorsProvided(): void
246+
{
247+
$subject = new ConcreteCSSList();
248+
$declarationBlock = new DeclarationBlock();
249+
$declarationBlock->setSelectors(['html', 'body']);
250+
$subject->setContents([$declarationBlock]);
251+
self::assertNotSame([], $subject->getContents()); // make sure contents are set
252+
253+
$subject->removeDeclarationBlockBySelector(['html', 'body']);
254+
255+
self::assertSame([], $subject->getContents());
256+
}
257+
258+
/**
259+
* @test
260+
*/
261+
public function removeDeclarationBlockBySelectorRemovesDeclarationBlockProvidedAndAnotherWithSameSelectors(): void
262+
{
263+
$subject = new ConcreteCSSList();
264+
$declarationBlock1 = new DeclarationBlock();
265+
$declarationBlock1->setSelectors(['html', 'body']);
266+
$declarationBlock2 = new DeclarationBlock();
267+
$declarationBlock2->setSelectors(['html', 'body']);
268+
$subject->setContents([$declarationBlock1, $declarationBlock2]);
269+
self::assertNotSame([], $subject->getContents()); // make sure contents are set
270+
271+
$subject->removeDeclarationBlockBySelector($declarationBlock1, true);
272+
273+
self::assertSame([], $subject->getContents());
274+
}
275+
276+
/**
277+
* @test
278+
*/
279+
public function removeDeclarationBlockBySelectorRemovesBlockWithSelectorsFromItselfAndAnotherMatching(): void
280+
{
281+
$subject = new ConcreteCSSList();
282+
$declarationBlock1 = new DeclarationBlock();
283+
$declarationBlock1->setSelectors(['html', 'body']);
284+
$declarationBlock2 = new DeclarationBlock();
285+
$declarationBlock2->setSelectors(['html', 'body']);
286+
$subject->setContents([$declarationBlock1, $declarationBlock2]);
287+
self::assertNotSame([], $subject->getContents()); // make sure contents are set
288+
289+
$subject->removeDeclarationBlockBySelector($declarationBlock1->getSelectors(), true);
290+
291+
self::assertSame([], $subject->getContents());
292+
}
293+
294+
/**
295+
* @test
296+
*/
297+
public function removeDeclarationBlockBySelectorRemovesMultipleBlocksWithOutsourcedSelectors(): void
298+
{
299+
$subject = new ConcreteCSSList();
300+
$declarationBlock1 = new DeclarationBlock();
301+
$declarationBlock1->setSelectors(['html', 'body']);
302+
$declarationBlock2 = new DeclarationBlock();
303+
$declarationBlock2->setSelectors(['html', 'body']);
304+
$subject->setContents([$declarationBlock1, $declarationBlock2]);
305+
self::assertNotSame([], $subject->getContents()); // make sure contents are set
306+
307+
$subject->removeDeclarationBlockBySelector([new Selector('html'), new Selector('body')], true);
308+
309+
self::assertSame([], $subject->getContents());
310+
}
311+
312+
/**
313+
* @test
314+
*/
315+
public function removeDeclarationBlockBySelectorRemovesMultipleBlocksWithStringSelectorsProvided(): void
316+
{
317+
$subject = new ConcreteCSSList();
318+
$declarationBlock1 = new DeclarationBlock();
319+
$declarationBlock1->setSelectors(['html', 'body']);
320+
$declarationBlock2 = new DeclarationBlock();
321+
$declarationBlock2->setSelectors(['html', 'body']);
322+
$subject->setContents([$declarationBlock1, $declarationBlock2]);
323+
self::assertNotSame([], $subject->getContents()); // make sure contents are set
324+
325+
$subject->removeDeclarationBlockBySelector(['html', 'body'], true);
326+
327+
self::assertSame([], $subject->getContents());
328+
}
192329
}

0 commit comments

Comments
 (0)