Skip to content

Commit 19ecca8

Browse files
authored
[TASK] Add some rendering tests for Document (#1138)
Part of #757
1 parent 5493982 commit 19ecca8

File tree

1 file changed

+137
-0
lines changed

1 file changed

+137
-0
lines changed
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Functional\CSSList;
6+
7+
use PHPUnit\Framework\TestCase;
8+
use Sabberworm\CSS\CSSList\AtRuleBlockList;
9+
use Sabberworm\CSS\CSSList\Document;
10+
use Sabberworm\CSS\OutputFormat;
11+
use Sabberworm\CSS\Property\Charset;
12+
use Sabberworm\CSS\Value\CSSString;
13+
14+
/**
15+
* @covers \Sabberworm\CSS\CSSList\Document
16+
*/
17+
final class DocumentTest extends TestCase
18+
{
19+
/**
20+
* @test
21+
*/
22+
public function renderWithoutOutputFormatCanRenderEmptyDocument(): void
23+
{
24+
$subject = new Document();
25+
26+
self::assertSame('', $subject->render());
27+
}
28+
29+
/**
30+
* @test
31+
*/
32+
public function renderWithVirginOutputFormatCanRenderEmptyDocument(): void
33+
{
34+
$subject = new Document();
35+
36+
self::assertSame('', $subject->render(new OutputFormat()));
37+
}
38+
39+
/**
40+
* @test
41+
*/
42+
public function renderWithDefaultOutputFormatCanRenderEmptyDocument(): void
43+
{
44+
$subject = new Document();
45+
46+
self::assertSame('', $subject->render(OutputFormat::create()));
47+
}
48+
49+
/**
50+
* @test
51+
*/
52+
public function renderWithCompactOutputFormatCanRenderEmptyDocument(): void
53+
{
54+
$subject = new Document();
55+
56+
self::assertSame('', $subject->render(OutputFormat::createCompact()));
57+
}
58+
59+
/**
60+
* @test
61+
*/
62+
public function renderWithPrettyOutputFormatCanRenderEmptyDocument(): void
63+
{
64+
$subject = new Document();
65+
66+
self::assertSame('', $subject->render(OutputFormat::createPretty()));
67+
}
68+
69+
/**
70+
* Builds a subject with one `@charset` rule and one `@media` rule.
71+
*/
72+
private function buildSubjectWithAtRules(): Document
73+
{
74+
$subject = new Document();
75+
$charset = new Charset(new CSSString('UTF-8'));
76+
$subject->append($charset);
77+
$mediaQuery = new AtRuleBlockList('media', 'screen');
78+
$subject->append($mediaQuery);
79+
80+
return $subject;
81+
}
82+
83+
/**
84+
* @test
85+
*/
86+
public function renderWithoutOutputFormatCanRenderAtRules(): void
87+
{
88+
$subject = $this->buildSubjectWithAtRules();
89+
90+
$expected = '@charset "UTF-8";' . "\n" . '@media screen {}';
91+
self::assertSame($expected, $subject->render());
92+
}
93+
94+
/**
95+
* @test
96+
*/
97+
public function renderWithVirginOutputFormatCanRenderAtRules(): void
98+
{
99+
$subject = $this->buildSubjectWithAtRules();
100+
101+
$expected = '@charset "UTF-8";' . "\n" . '@media screen {}';
102+
self::assertSame($expected, $subject->render(new OutputFormat()));
103+
}
104+
105+
/**
106+
* @test
107+
*/
108+
public function renderWithDefaultOutputFormatCanRenderAtRules(): void
109+
{
110+
$subject = $this->buildSubjectWithAtRules();
111+
112+
$expected = '@charset "UTF-8";' . "\n" . '@media screen {}';
113+
self::assertSame($expected, $subject->render(OutputFormat::create()));
114+
}
115+
116+
/**
117+
* @test
118+
*/
119+
public function renderWithCompactOutputFormatCanRenderAtRules(): void
120+
{
121+
$subject = $this->buildSubjectWithAtRules();
122+
123+
$expected = '@charset "UTF-8";@media screen{}';
124+
self::assertSame($expected, $subject->render(OutputFormat::createCompact()));
125+
}
126+
127+
/**
128+
* @test
129+
*/
130+
public function renderWithPrettyOutputFormatCanRenderAtRules(): void
131+
{
132+
$subject = $this->buildSubjectWithAtRules();
133+
134+
$expected = "\n" . '@charset "UTF-8";' . "\n\n" . '@media screen {}' . "\n";
135+
self::assertSame($expected, $subject->render(OutputFormat::createPretty()));
136+
}
137+
}

0 commit comments

Comments
 (0)