-
Notifications
You must be signed in to change notification settings - Fork 152
Expand file tree
/
Copy pathRuleSetTest.php
More file actions
119 lines (103 loc) · 3.54 KB
/
Copy pathRuleSetTest.php
File metadata and controls
119 lines (103 loc) · 3.54 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
<?php
declare(strict_types=1);
namespace Sabberworm\CSS\Tests\Functional\RuleSet;
use PHPUnit\Framework\TestCase;
use Sabberworm\CSS\OutputFormat;
use Sabberworm\CSS\Property\Declaration;
use Sabberworm\CSS\RuleSet\RuleSet;
/**
* @covers \Sabberworm\CSS\RuleSet\RuleSet
*/
final class RuleSetTest extends TestCase
{
/**
* @var RuleSet
*/
private $subject;
protected function setUp(): void
{
$this->subject = new RuleSet();
}
/**
* @return array<string, array{0: list<array{name: string, value: string}>, 1: string}>
*/
public static function providePropertyNamesAndValuesAndExpectedCss(): array
{
return [
'no properties' => [[], ''],
'one property' => [
[['name' => 'color', 'value' => 'green']],
'color: green;',
],
'two different properties' => [
[
['name' => 'color', 'value' => 'green'],
['name' => 'display', 'value' => 'block'],
],
'color: green;display: block;',
],
'two of the same property' => [
[
['name' => 'color', 'value' => '#40A040'],
['name' => 'color', 'value' => 'rgba(0, 128, 0, 0.25)'],
],
'color: #40A040;color: rgba(0, 128, 0, 0.25);',
],
];
}
/**
* @test
*
* @param list<array{name: string, value: string}> $propertyNamesAndValuesToSet
*
* @dataProvider providePropertyNamesAndValuesAndExpectedCss
*/
public function renderReturnsCssForDeclarationsSet(array $propertyNamesAndValuesToSet, string $expectedCss): void
{
$this->setDeclarationsFromPropertyNamesAndValues($propertyNamesAndValuesToSet);
$result = $this->subject->render(OutputFormat::create());
self::assertSame($expectedCss, $result);
}
/**
* @test
*/
public function renderWithCompactOutputFormatReturnsCssWithoutWhitespaceOrTrailingSemicolon(): void
{
$this->setDeclarationsFromPropertyNamesAndValues([
['name' => 'color', 'value' => 'green'],
['name' => 'display', 'value' => 'block'],
]);
$result = $this->subject->render(OutputFormat::createCompact());
self::assertSame('color:green;display:block', $result);
}
/**
* @test
*/
public function renderWithPrettyOutputFormatReturnsCssWithNewlinesAroundIndentedDeclarations(): void
{
$this->setDeclarationsFromPropertyNamesAndValues([
['name' => 'color', 'value' => 'green'],
['name' => 'display', 'value' => 'block'],
]);
$result = $this->subject->render(OutputFormat::createPretty());
self::assertSame("\n\tcolor: green;\n\tdisplay: block;\n", $result);
}
/**
* @param list<array{name: string, value: string}> $propertyNamesAndValues
*/
private function setDeclarationsFromPropertyNamesAndValues(array $propertyNamesAndValues): void
{
$declarationsToSet = \array_map(
/**
* @param array{name: string, value: string} $nameAndValue
*/
static function (array $nameAndValue): Declaration {
$declaration = new Declaration($nameAndValue['name']);
$declaration->setValue($nameAndValue['value']);
return $declaration;
},
$propertyNamesAndValues
);
$this->subject->setRules($declarationsToSet);
}
}