|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace AbterPhp\Website\Template\Builder\ContentList; |
|
4
|
|
|
|
|
5
|
|
|
use AbterPhp\Framework\Constant\Html5; |
|
6
|
|
|
use AbterPhp\Framework\Template\ParsedTemplate; |
|
7
|
|
|
|
|
8
|
|
|
class DefinitionListTest extends ContentListTest |
|
9
|
|
|
{ |
|
10
|
|
|
/** @var DefinitionList - System Under Test */ |
|
11
|
|
|
protected $sut; |
|
12
|
|
|
|
|
13
|
|
|
public function setUp(): void |
|
14
|
|
|
{ |
|
15
|
|
|
$this->sut = new DefinitionList(); |
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @return array |
|
20
|
|
|
*/ |
|
21
|
|
|
public function buildDefaultProvider(): array |
|
22
|
|
|
{ |
|
23
|
|
|
$identifier = 'isdfk'; |
|
24
|
|
|
$itemId0 = 'veowq'; |
|
25
|
|
|
$itemId1 = 'zzoel'; |
|
26
|
|
|
$itemIds = [$itemId0, $itemId1]; |
|
27
|
|
|
|
|
28
|
|
|
// @codingStandardsIgnoreStart |
|
29
|
|
|
$withNothing = <<<EOD |
|
30
|
|
|
<dl id="$identifier" class="definition-list"><dt class="list-item-label">Foo $itemId0</dt><dd class="list-item-content">Bar $itemId0</dd> |
|
31
|
|
|
<dt class="list-item-label">Foo $itemId1</dt><dd class="list-item-content">Bar $itemId1</dd></dl> |
|
32
|
|
|
EOD; |
|
33
|
|
|
|
|
34
|
|
|
$withLinks = <<<EOD |
|
35
|
|
|
<dl id="$identifier" class="definition-list"><dt class="list-item-label"><a href="/bar-$itemId0">Foo $itemId0</a></dt><dd class="list-item-content"><a href="/bar-$itemId0">Bar $itemId0</a></dd> |
|
36
|
|
|
<dt class="list-item-label"><a href="/bar-$itemId1">Foo $itemId1</a></dt><dd class="list-item-content"><a href="/bar-$itemId1">Bar $itemId1</a></dd></dl> |
|
37
|
|
|
EOD; |
|
38
|
|
|
|
|
39
|
|
|
$withLabelLinks = <<<EOD |
|
40
|
|
|
<dl id="$identifier" class="definition-list"><dt class="list-item-label"><a href="/foo-$itemId0">Foo $itemId0</a></dt><dd class="list-item-content"><a href="/bar-$itemId0">Bar $itemId0</a></dd> |
|
41
|
|
|
<dt class="list-item-label"><a href="/foo-$itemId1">Foo $itemId1</a></dt><dd class="list-item-content"><a href="/bar-$itemId1">Bar $itemId1</a></dd></dl> |
|
42
|
|
|
EOD; |
|
43
|
|
|
|
|
44
|
|
|
$withImage = <<<EOD |
|
45
|
|
|
<dl id="$identifier" class="definition-list"><dt class="list-item-label">Foo $itemId0</dt><dd class="list-item-content">Bar $itemId0</dd> |
|
46
|
|
|
<dt class="list-item-label">Foo $itemId1</dt><dd class="list-item-content">Bar $itemId1</dd></dl> |
|
47
|
|
|
EOD; |
|
48
|
|
|
|
|
49
|
|
|
$withAll = <<<EOD |
|
50
|
|
|
<dl id="$identifier" class="definition-list"><dt class="list-item-label"><a href="/foo-$itemId0">Foo $itemId0</a></dt><dd class="list-item-content"><a href="/bar-$itemId0">Bar $itemId0</a></dd> |
|
51
|
|
|
<dt class="list-item-label"><a href="/foo-$itemId1">Foo $itemId1</a></dt><dd class="list-item-content"><a href="/bar-$itemId1">Bar $itemId1</a></dd></dl> |
|
52
|
|
|
EOD; |
|
53
|
|
|
|
|
54
|
|
|
// @codingStandardsIgnoreEnd |
|
55
|
|
|
|
|
56
|
|
|
return [ |
|
57
|
|
|
'with nothing' => [$identifier, false, false, false, $itemIds, $withNothing], |
|
58
|
|
|
'with links' => [$identifier, true, false, false, $itemIds, $withLinks], |
|
59
|
|
|
'with label links' => [$identifier, true, true, false, $itemIds, $withLabelLinks], |
|
60
|
|
|
'with image' => [$identifier, false, false, true, $itemIds, $withImage], |
|
61
|
|
|
'with all' => [$identifier, true, true, true, $itemIds, $withAll], |
|
62
|
|
|
]; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @dataProvider buildDefaultProvider |
|
67
|
|
|
* |
|
68
|
|
|
* @param string $identifier |
|
69
|
|
|
* @param bool $withLinks |
|
70
|
|
|
* @param bool $withLabelLinks |
|
71
|
|
|
* @param bool $withImages |
|
72
|
|
|
* @param string[] $itemIds |
|
73
|
|
|
* @param string $expectedResult |
|
74
|
|
|
*/ |
|
75
|
|
|
public function testBuildDefault( |
|
76
|
|
|
string $identifier, |
|
77
|
|
|
bool $withLinks, |
|
78
|
|
|
bool $withLabelLinks, |
|
79
|
|
|
bool $withImages, |
|
80
|
|
|
array $itemIds, |
|
81
|
|
|
string $expectedResult |
|
82
|
|
|
) { |
|
83
|
|
|
$entity = $this->createEntity($identifier, ...$itemIds) |
|
84
|
|
|
->setWithLinks($withLinks) |
|
85
|
|
|
->setWithLabelLinks($withLabelLinks) |
|
86
|
|
|
->setWithImages($withImages); |
|
87
|
|
|
|
|
88
|
|
|
$actualResult = $this->sut->build($entity); |
|
89
|
|
|
|
|
90
|
|
|
$this->assertSame($expectedResult, $actualResult->getTemplates()['body']); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* @return array |
|
95
|
|
|
*/ |
|
96
|
|
|
public function buildVeryCustomProvider(): array |
|
97
|
|
|
{ |
|
98
|
|
|
$identifier = 'isdfk'; |
|
99
|
|
|
$itemId0 = 'veowq'; |
|
100
|
|
|
$itemId1 = 'zzoel'; |
|
101
|
|
|
$itemIds = [$itemId0, $itemId1]; |
|
102
|
|
|
|
|
103
|
|
|
// @codingStandardsIgnoreStart |
|
104
|
|
|
$withNothing = <<<EOD |
|
105
|
|
|
<div id="$identifier" class="definition-list d"><ul class="it"><li class="l">Foo ${itemId0}</li><li class="c">Bar ${itemId0}</li></ul> |
|
106
|
|
|
<ul class="it"><li class="l">Foo ${itemId1}</li><li class="c">Bar ${itemId1}</li></ul></div> |
|
107
|
|
|
EOD; |
|
108
|
|
|
|
|
109
|
|
|
$withLinks = <<<EOD |
|
110
|
|
|
<div id="$identifier" class="definition-list d"><ul class="it"><li class="l"><a href="/bar-$itemId0">Foo ${itemId0}</a></li><li class="c"><a href="/bar-$itemId0">Bar ${itemId0}</a></li></ul> |
|
111
|
|
|
<ul class="it"><li class="l"><a href="/bar-$itemId1">Foo ${itemId1}</a></li><li class="c"><a href="/bar-$itemId1">Bar ${itemId1}</a></li></ul></div> |
|
112
|
|
|
EOD; |
|
113
|
|
|
|
|
114
|
|
|
$withLabelLinks = <<<EOD |
|
115
|
|
|
<div id="$identifier" class="definition-list d"><ul class="it"><li class="l"><a href="/foo-$itemId0">Foo ${itemId0}</a></li><li class="c"><a href="/bar-$itemId0">Bar ${itemId0}</a></li></ul> |
|
116
|
|
|
<ul class="it"><li class="l"><a href="/foo-$itemId1">Foo ${itemId1}</a></li><li class="c"><a href="/bar-$itemId1">Bar ${itemId1}</a></li></ul></div> |
|
117
|
|
|
EOD; |
|
118
|
|
|
|
|
119
|
|
|
$withImage = <<<EOD |
|
120
|
|
|
<div id="$identifier" class="definition-list d"><ul class="it"><li class="l">Foo ${itemId0}</li><li class="c">Bar ${itemId0}</li></ul> |
|
121
|
|
|
<ul class="it"><li class="l">Foo ${itemId1}</li><li class="c">Bar ${itemId1}</li></ul></div> |
|
122
|
|
|
EOD; |
|
123
|
|
|
|
|
124
|
|
|
$withAll = <<<EOD |
|
125
|
|
|
<div id="$identifier" class="definition-list d"><ul class="it"><li class="l"><a href="/foo-$itemId0">Foo ${itemId0}</a></li><li class="c"><a href="/bar-$itemId0">Bar ${itemId0}</a></li></ul> |
|
126
|
|
|
<ul class="it"><li class="l"><a href="/foo-$itemId1">Foo ${itemId1}</a></li><li class="c"><a href="/bar-$itemId1">Bar ${itemId1}</a></li></ul></div> |
|
127
|
|
|
EOD; |
|
128
|
|
|
|
|
129
|
|
|
// @codingStandardsIgnoreEnd |
|
130
|
|
|
|
|
131
|
|
|
return [ |
|
132
|
|
|
'with nothing' => [$identifier, false, false, false, $itemIds, $withNothing], |
|
133
|
|
|
'with links' => [$identifier, true, false, false, $itemIds, $withLinks], |
|
134
|
|
|
'with label links' => [$identifier, true, true, false, $itemIds, $withLabelLinks], |
|
135
|
|
|
'with image' => [$identifier, false, false, true, $itemIds, $withImage], |
|
136
|
|
|
'with all' => [$identifier, true, true, true, $itemIds, $withAll], |
|
137
|
|
|
]; |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* @dataProvider buildVeryCustomProvider |
|
142
|
|
|
* |
|
143
|
|
|
* @param string $identifier |
|
144
|
|
|
* @param bool $withLinks |
|
145
|
|
|
* @param bool $withLabelLinks |
|
146
|
|
|
* @param bool $withImages |
|
147
|
|
|
* @param string[] $itemIds |
|
148
|
|
|
* @param string $expectedResult |
|
149
|
|
|
*/ |
|
150
|
|
|
public function testBuildVeryCustom( |
|
151
|
|
|
string $identifier, |
|
152
|
|
|
bool $withLinks, |
|
153
|
|
|
bool $withLabelLinks, |
|
154
|
|
|
bool $withImages, |
|
155
|
|
|
array $itemIds, |
|
156
|
|
|
string $expectedResult |
|
157
|
|
|
) { |
|
158
|
|
|
$entity = $this->createEntity($identifier, ...$itemIds) |
|
159
|
|
|
->setWithLinks($withLinks) |
|
160
|
|
|
->setWithLabelLinks($withLabelLinks) |
|
161
|
|
|
->setWithImages($withImages); |
|
162
|
|
|
|
|
163
|
|
|
$attributes = [ |
|
164
|
|
|
IContentList::WITH_LABEL_OPTION => '1', |
|
165
|
|
|
IContentList::WITH_IMAGES_OPTION => '1', |
|
166
|
|
|
IContentList::LIST_TAG => Html5::TAG_DIV, |
|
167
|
|
|
IContentList::LIST_CLASS => 'd', |
|
168
|
|
|
IContentList::ITEM_TAG => Html5::TAG_UL, |
|
169
|
|
|
IContentList::ITEM_CLASS => 'it', |
|
170
|
|
|
IContentList::LABEL_TAG => Html5::TAG_LI, |
|
171
|
|
|
IContentList::LABEL_CLASS => 'l', |
|
172
|
|
|
IContentList::CONTENT_TAG => Html5::TAG_LI, |
|
173
|
|
|
IContentList::CONTENT_CLASS => 'c', |
|
174
|
|
|
IContentList::IMAGE_TAG => Html5::TAG_LI, |
|
175
|
|
|
IContentList::IMAGE_CLASS => 'im', |
|
176
|
|
|
]; |
|
177
|
|
|
$parsedTemplate = new ParsedTemplate('', '', $attributes); |
|
178
|
|
|
|
|
179
|
|
|
$actualResult = $this->sut->build($entity, $parsedTemplate); |
|
180
|
|
|
|
|
181
|
|
|
$this->assertSame($expectedResult, $actualResult->getTemplates()['body']); |
|
182
|
|
|
} |
|
183
|
|
|
} |
|
184
|
|
|
|