forked from MyIntervals/PHP-CSS-Parser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDocumentTest.php
More file actions
143 lines (115 loc) · 3.62 KB
/
Copy pathDocumentTest.php
File metadata and controls
143 lines (115 loc) · 3.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
namespace Sabberworm\CSS\Tests\CSSList;
use PHPUnit\Framework\TestCase;
use Sabberworm\CSS\Comment\Commentable;
use Sabberworm\CSS\CSSList\Document;
use Sabberworm\CSS\Renderable;
use Sabberworm\CSS\RuleSet\DeclarationBlock;
/**
* @covers \Sabberworm\CSS\CSSList\Document
*/
final class DocumentTest extends TestCase
{
/**
* @var Document
*/
private $subject;
protected function setUp(): void
{
$this->subject = new Document();
}
/**
* @test
*/
public function implementsRenderable(): void
{
self::assertInstanceOf(Renderable::class, $this->subject);
}
/**
* @test
*/
public function implementsCommentable(): void
{
self::assertInstanceOf(Commentable::class, $this->subject);
}
/**
* @test
*/
public function getContentsInitiallyReturnsEmptyArray(): void
{
self::assertSame([], $this->subject->getContents());
}
/**
* @return array<string, array<int, array<int, DeclarationBlock>>>
*/
public static function contentsDataProvider(): array
{
return [
'empty array' => [[]],
'1 item' => [[new DeclarationBlock()]],
'2 items' => [[new DeclarationBlock(), new DeclarationBlock()]],
];
}
/**
* @test
*
* @param array<int, DeclarationBlock> $contents
*
* @dataProvider contentsDataProvider
*/
public function setContentsSetsContents(array $contents): void
{
$this->subject->setContents($contents);
self::assertSame($contents, $this->subject->getContents());
}
/**
* @test
*/
public function setContentsReplacesContentsSetInPreviousCall(): void
{
$contents2 = [new DeclarationBlock()];
$this->subject->setContents([new DeclarationBlock()]);
$this->subject->setContents($contents2);
self::assertSame($contents2, $this->subject->getContents());
}
/**
* @test
*/
public function insertContentBeforeInsertsContentBeforeSibbling()
{
$bogusOne = new DeclarationBlock();
$bogusOne->setSelectors('.bogus-one');
$bogusTwo = new DeclarationBlock();
$bogusTwo->setSelectors('.bogus-two');
$item = new DeclarationBlock();
$item->setSelectors('.item');
$sibling = new DeclarationBlock();
$sibling->setSelectors('.sibling');
$this->subject->setContents([$bogusOne, $sibling, $bogusTwo]);
self::assertCount(3, $this->subject->getContents());
$this->subject->insertBefore($item, $sibling);
self::assertCount(4, $this->subject->getContents());
self::assertSame([$bogusOne, $item, $sibling, $bogusTwo], $this->subject->getContents());
}
/**
* @test
*/
public function insertContentBeforeAppendsIfSibblingNotFound()
{
$bogusOne = new DeclarationBlock();
$bogusOne->setSelectors('.bogus-one');
$bogusTwo = new DeclarationBlock();
$bogusTwo->setSelectors('.bogus-two');
$item = new DeclarationBlock();
$item->setSelectors('.item');
$sibling = new DeclarationBlock();
$sibling->setSelectors('.sibling');
$orphan = new DeclarationBlock();
$orphan->setSelectors('.forever-alone');
$this->subject->setContents([$bogusOne, $sibling, $bogusTwo]);
self::assertCount(3, $this->subject->getContents());
$this->subject->insertBefore($item, $orphan);
self::assertCount(4, $this->subject->getContents());
self::assertSame([$bogusOne, $sibling, $bogusTwo, $item], $this->subject->getContents());
}
}