|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace AbterPhp\Framework\Html; |
|
6
|
|
|
|
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
|
8
|
|
|
|
|
9
|
|
|
class AttributeTest extends TestCase |
|
10
|
|
|
{ |
|
11
|
|
|
protected const KEY = 'foo'; |
|
12
|
|
|
|
|
13
|
|
|
/** @var Attribute - System Under Test */ |
|
14
|
|
|
protected Attribute $sut; |
|
15
|
|
|
|
|
16
|
|
|
public function setUp(): void |
|
17
|
|
|
{ |
|
18
|
|
|
$this->sut = new Attribute(static::KEY); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
public function testToString(): void |
|
22
|
|
|
{ |
|
23
|
|
|
$expectedResult = 'foo'; |
|
24
|
|
|
|
|
25
|
|
|
$actualResult = (string)($this->sut); |
|
26
|
|
|
|
|
27
|
|
|
$this->assertSame($expectedResult, $actualResult); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function testSet(): void |
|
31
|
|
|
{ |
|
32
|
|
|
$expectedResult = 'foo="bar"'; |
|
33
|
|
|
|
|
34
|
|
|
$this->sut->set('bar'); |
|
35
|
|
|
|
|
36
|
|
|
$actualResult = (string)($this->sut); |
|
37
|
|
|
|
|
38
|
|
|
$this->assertSame($expectedResult, $actualResult); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @return array<string,array> |
|
43
|
|
|
*/ |
|
44
|
|
|
public function appendProvider(): array |
|
45
|
|
|
{ |
|
46
|
|
|
return [ |
|
47
|
|
|
'empty' => [ |
|
48
|
|
|
[], |
|
49
|
|
|
'foo', |
|
50
|
|
|
], |
|
51
|
|
|
'simple' => [ |
|
52
|
|
|
['bar'], |
|
53
|
|
|
'foo="bar"', |
|
54
|
|
|
], |
|
55
|
|
|
'more' => [ |
|
56
|
|
|
['bar', 'baz'], |
|
57
|
|
|
'foo="bar baz"', |
|
58
|
|
|
], |
|
59
|
|
|
'repeat' => [ |
|
60
|
|
|
['bar', 'baz', 'baz', 'bar'], |
|
61
|
|
|
'foo="bar baz"', |
|
62
|
|
|
], |
|
63
|
|
|
]; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @dataProvider appendProvider |
|
68
|
|
|
* |
|
69
|
|
|
* @param array $values |
|
70
|
|
|
* @param string $expectedResult |
|
71
|
|
|
*/ |
|
72
|
|
|
public function testAppend(array $values, string $expectedResult): void |
|
73
|
|
|
{ |
|
74
|
|
|
$this->sut->append(...$values); |
|
75
|
|
|
|
|
76
|
|
|
$actualResult = (string)$this->sut; |
|
77
|
|
|
|
|
78
|
|
|
$this->assertSame($expectedResult, $actualResult); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @return array<string,string[]> |
|
83
|
|
|
*/ |
|
84
|
|
|
public function removeProvider(): array |
|
85
|
|
|
{ |
|
86
|
|
|
return [ |
|
87
|
|
|
'simple' => [['bar', 'baz', 'quix'], 'baz', 1], |
|
88
|
|
|
'repeat' => [['bar', 'baz', 'quix', 'baz'], 'baz', 1], |
|
89
|
|
|
'expression' => [['bar', 'baz quix'], 'baz', 0], |
|
90
|
|
|
]; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* @dataProvider removeProvider |
|
95
|
|
|
* |
|
96
|
|
|
* @param string[] $values |
|
97
|
|
|
* @param string $removeValue |
|
98
|
|
|
* @param int $expectedResult |
|
99
|
|
|
*/ |
|
100
|
|
|
public function testRemove(array $values, string $removeValue, int $expectedResult): void |
|
101
|
|
|
{ |
|
102
|
|
|
$sut = new Attribute(self::KEY, ...$values); |
|
103
|
|
|
$actualResult = $sut->remove($removeValue); |
|
104
|
|
|
|
|
105
|
|
|
$this->assertSame($expectedResult, $actualResult); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
public function testReset(): void |
|
109
|
|
|
{ |
|
110
|
|
|
$this->sut->append('foo', 'bar', 'baz'); |
|
111
|
|
|
$this->sut->reset(); |
|
112
|
|
|
|
|
113
|
|
|
$actualResult = $this->sut->getValues(); |
|
114
|
|
|
|
|
115
|
|
|
$this->assertNull($actualResult); |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
public function testGetValuesDefault(): void |
|
119
|
|
|
{ |
|
120
|
|
|
$actualResult = $this->sut->getValues(); |
|
121
|
|
|
|
|
122
|
|
|
$this->assertNull($actualResult); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
public function testGetValuesWithValues(): void |
|
126
|
|
|
{ |
|
127
|
|
|
$this->sut->append('foo', 'bar', 'baz'); |
|
128
|
|
|
|
|
129
|
|
|
$actualResult = $this->sut->getValues(); |
|
130
|
|
|
|
|
131
|
|
|
$this->assertSame(['foo', 'bar', 'baz'], $actualResult); |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* @return array[] |
|
136
|
|
|
*/ |
|
137
|
|
|
public function isEqualProvider(): array |
|
138
|
|
|
{ |
|
139
|
|
|
return [ |
|
140
|
|
|
[new Attribute('foo', 'bar', 'baz'), new Attribute('foo', 'bar', 'baz'), true], |
|
141
|
|
|
[new Attribute('foo', 'bar', 'baz'), new Attribute('bar', 'bar', 'baz'), false], |
|
142
|
|
|
[new Attribute('foo', 'bar', 'baz'), new Attribute('foo', 'bar', 'bar'), false], |
|
143
|
|
|
[new Attribute('foo', 'bar', 'baz'), new Attribute('foo', 'bar'), false], |
|
144
|
|
|
[new Attribute('foo', 'bar'), new Attribute('foo', 'bar', 'baz'), false], |
|
145
|
|
|
]; |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* @dataProvider isEqualProvider |
|
150
|
|
|
* |
|
151
|
|
|
* @param Attribute $a |
|
152
|
|
|
* @param Attribute $b |
|
153
|
|
|
* @param bool $expectedResult |
|
154
|
|
|
*/ |
|
155
|
|
|
public function testIsEqual(Attribute $a, Attribute $b, bool $expectedResult): void |
|
156
|
|
|
{ |
|
157
|
|
|
$actualResult = $a->isEqual($b); |
|
158
|
|
|
|
|
159
|
|
|
$this->assertSame($expectedResult, $actualResult); |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
/** |
|
163
|
|
|
* @return array[] |
|
164
|
|
|
*/ |
|
165
|
|
|
public function isNullProvider(): array |
|
166
|
|
|
{ |
|
167
|
|
|
return [ |
|
168
|
|
|
[new Attribute('foo'), true], |
|
169
|
|
|
[new Attribute('foo', ''), false], |
|
170
|
|
|
]; |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
/** |
|
174
|
|
|
* @dataProvider isEqualProvider |
|
175
|
|
|
* |
|
176
|
|
|
* @param Attribute $a |
|
177
|
|
|
* @param bool $expectedResult |
|
178
|
|
|
*/ |
|
179
|
|
|
public function tesIsNull(Attribute $a, bool $expectedResult): void |
|
180
|
|
|
{ |
|
181
|
|
|
$actualResult = $a->isNull(); |
|
182
|
|
|
|
|
183
|
|
|
$this->assertSame($expectedResult, $actualResult); |
|
184
|
|
|
} |
|
185
|
|
|
} |
|
186
|
|
|
|