Passed
Push — master ( 6af672...0107a4 )
by Peter
07:37
created

SimpleTest::buildDefaultProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 41
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 30
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 41
rs 9.44
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 SimpleTest extends ContentListTest
9
{
10
    /** @var Simple - System Under Test */
11
    protected $sut;
12
13
    public function setUp(): void
14
    {
15
        $this->sut = new Simple();
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
<ul id="$identifier" class="simple"><li class="list-item">Bar $itemId0</li>
31
<li class="list-item">Bar $itemId1</li></ul>
32
EOD;
33
34
        $withLinks = <<<EOD
35
<ul id="$identifier" class="simple"><li class="list-item"><a href="/bar-$itemId0">Bar $itemId0</a></li>
36
<li class="list-item"><a href="/bar-$itemId1">Bar $itemId1</a></li></ul>
37
EOD;
38
39
        $withLabelLinks = <<<EOD
40
<ul id="$identifier" class="simple"><li class="list-item"><a href="/bar-$itemId0">Bar $itemId0</a></li>
41
<li class="list-item"><a href="/bar-$itemId1">Bar $itemId1</a></li></ul>
42
EOD;
43
44
        $withImage = <<<EOD
45
<ul id="$identifier" class="simple"><li class="list-item">Bar $itemId0</li>
46
<li class="list-item">Bar $itemId1</li></ul>
47
EOD;
48
49
        $withAll = <<<EOD
50
<ul id="$identifier" class="simple"><li class="list-item"><a href="/bar-$itemId0">Bar $itemId0</a></li>
51
<li class="list-item"><a href="/bar-$itemId1">Bar $itemId1</a></li></ul>
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 buildWrappedProvider(): array
97
    {
98
        $identifier = 'isdfk';
99
        $itemId0    = 'veowq';
100
        $itemId1    = 'zzoel';
101
        $itemIds    = [$itemId0, $itemId1];
102
103
        // @codingStandardsIgnoreStart
104
        $withNothing = <<<EOD
105
<ul id="$identifier" class="simple"><li class="list-item"><span class="list-item-content">Bar $itemId0</span></li>
106
<li class="list-item"><span class="list-item-content">Bar $itemId1</span></li></ul>
107
EOD;
108
109
        $withLinks = <<<EOD
110
<ul id="$identifier" class="simple"><li class="list-item"><span class="list-item-content"><a href="/bar-$itemId0">Bar $itemId0</a></span></li>
111
<li class="list-item"><span class="list-item-content"><a href="/bar-$itemId1">Bar $itemId1</a></span></li></ul>
112
EOD;
113
114
        $withLabelLinks = <<<EOD
115
<ul id="$identifier" class="simple"><li class="list-item"><span class="list-item-content"><a href="/bar-$itemId0">Bar $itemId0</a></span></li>
116
<li class="list-item"><span class="list-item-content"><a href="/bar-$itemId1">Bar $itemId1</a></span></li></ul>
117
EOD;
118
119
        $withImage = <<<EOD
120
<ul id="$identifier" class="simple"><li class="list-item"><span class="list-item-content">Bar $itemId0</span></li>
121
<li class="list-item"><span class="list-item-content">Bar $itemId1</span></li></ul>
122
EOD;
123
124
        $withAll = <<<EOD
125
<ul id="$identifier" class="simple"><li class="list-item"><span class="list-item-content"><a href="/bar-$itemId0">Bar $itemId0</a></span></li>
126
<li class="list-item"><span class="list-item-content"><a href="/bar-$itemId1">Bar $itemId1</a></span></li></ul>
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 buildWrappedProvider
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 testBuildWrapped(
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     = [IContentList::CONTENT_TAG => Html5::TAG_SPAN];
164
        $parsedTemplate = new ParsedTemplate('', '', $attributes);
165
166
        $actualResult = $this->sut->build($entity, $parsedTemplate);
167
168
        $this->assertSame($expectedResult, $actualResult->getTemplates()['body']);
169
    }
170
171
    /**
172
     * @return array
173
     */
174
    public function buildWithAllWithoutTagsProvider(): array
175
    {
176
        $identifier = 'isdfk';
177
        $itemId0    = 'veowq';
178
        $itemId1    = 'zzoel';
179
        $itemIds    = [$itemId0, $itemId1];
180
181
        // @codingStandardsIgnoreStart
182
        $withNothing = <<<EOD
183
<ul id="$identifier" class="simple"><li class="list-item">Foo ${itemId0}Bar ${itemId0}</li>
184
<li class="list-item">Foo ${itemId1}Bar ${itemId1}</li></ul>
185
EOD;
186
187
        $withLinks = <<<EOD
188
<ul id="$identifier" class="simple"><li class="list-item"><a href="/bar-$itemId0">Foo $itemId0</a><a href="/bar-$itemId0">Bar $itemId0</a></li>
189
<li class="list-item"><a href="/bar-$itemId1">Foo $itemId1</a><a href="/bar-$itemId1">Bar $itemId1</a></li></ul>
190
EOD;
191
192
        $withLabelLinks = <<<EOD
193
<ul id="$identifier" class="simple"><li class="list-item"><a href="/foo-$itemId0">Foo $itemId0</a><a href="/bar-$itemId0">Bar $itemId0</a></li>
194
<li class="list-item"><a href="/foo-$itemId1">Foo $itemId1</a><a href="/bar-$itemId1">Bar $itemId1</a></li></ul>
195
EOD;
196
197
        $withImage = <<<EOD
198
<ul id="$identifier" class="simple"><li class="list-item">Foo ${itemId0}Bar ${itemId0}<img src="/baz-${itemId0}.png" alt="Baz ${itemId0}"></li>
199
<li class="list-item">Foo ${itemId1}Bar ${itemId1}<img src="/baz-${itemId1}.png" alt="Baz ${itemId1}"></li></ul>
200
EOD;
201
202
        $withAll = <<<EOD
203
<ul id="$identifier" class="simple"><li class="list-item"><a href="/foo-$itemId0">Foo $itemId0</a><a href="/bar-$itemId0">Bar $itemId0</a><a href="/baz-$itemId0"><img src="/baz-${itemId0}.png" alt="Baz ${itemId0}"></a></li>
204
<li class="list-item"><a href="/foo-$itemId1">Foo $itemId1</a><a href="/bar-$itemId1">Bar $itemId1</a><a href="/baz-$itemId1"><img src="/baz-${itemId1}.png" alt="Baz ${itemId1}"></a></li></ul>
205
EOD;
206
207
        // @codingStandardsIgnoreEnd
208
209
        return [
210
            'with nothing'     => [$identifier, false, false, false, $itemIds, $withNothing],
211
            'with links'       => [$identifier, true, false, false, $itemIds, $withLinks],
212
            'with label links' => [$identifier, true, true, false, $itemIds, $withLabelLinks],
213
            'with image'       => [$identifier, false, false, true, $itemIds, $withImage],
214
            'with all'         => [$identifier, true, true, true, $itemIds, $withAll],
215
        ];
216
    }
217
218
    /**
219
     * @dataProvider buildWithAllWithoutTagsProvider
220
     *
221
     * @param string   $identifier
222
     * @param bool     $withLinks
223
     * @param bool     $withLabelLinks
224
     * @param bool     $withImages
225
     * @param string[] $itemIds
226
     * @param string   $expectedResult
227
     */
228
    public function testBuildWithAllWithoutTags(
229
        string $identifier,
230
        bool $withLinks,
231
        bool $withLabelLinks,
232
        bool $withImages,
233
        array $itemIds,
234
        string $expectedResult
235
    ) {
236
        $entity = $this->createEntity($identifier, ...$itemIds)
237
            ->setWithLinks($withLinks)
238
            ->setWithLabelLinks($withLabelLinks)
239
            ->setWithImages($withImages);
240
241
        $attributes     = [
242
            IContentList::WITH_LABEL_OPTION  => '1',
243
            IContentList::WITH_IMAGES_OPTION => '1',
244
        ];
245
        $parsedTemplate = new ParsedTemplate('', '', $attributes);
246
247
        $actualResult = $this->sut->build($entity, $parsedTemplate);
248
249
        $this->assertSame($expectedResult, $actualResult->getTemplates()['body']);
250
    }
251
252
    /**
253
     * @return array
254
     */
255
    public function buildVeryCustomProvider(): array
256
    {
257
        $identifier = 'isdfk';
258
        $itemId0    = 'veowq';
259
        $itemId1    = 'zzoel';
260
        $itemIds    = [$itemId0, $itemId1];
261
262
        // @codingStandardsIgnoreStart
263
        $withNothing = <<<EOD
264
<div id="$identifier" class="simple d"><ul class="it"><li class="l">Foo ${itemId0}</li><li class="c">Bar ${itemId0}</li></ul>
265
<ul class="it"><li class="l">Foo ${itemId1}</li><li class="c">Bar ${itemId1}</li></ul></div>
266
EOD;
267
268
        $withLinks = <<<EOD
269
<div id="$identifier" class="simple 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>
270
<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>
271
EOD;
272
273
        $withLabelLinks = <<<EOD
274
<div id="$identifier" class="simple 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>
275
<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>
276
EOD;
277
278
        $withImage = <<<EOD
279
<div id="$identifier" class="simple d"><ul class="it"><li class="l">Foo ${itemId0}</li><li class="c">Bar ${itemId0}</li><li class="im"><img src="/baz-${itemId0}.png" alt="Baz ${itemId0}"></li></ul>
280
<ul class="it"><li class="l">Foo ${itemId1}</li><li class="c">Bar ${itemId1}</li><li class="im"><img src="/baz-${itemId1}.png" alt="Baz ${itemId1}"></li></ul></div>
281
EOD;
282
283
        $withAll = <<<EOD
284
<div id="$identifier" class="simple 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><li class="im"><a href="/baz-$itemId0"><img src="/baz-${itemId0}.png" alt="Baz ${itemId0}"></a></li></ul>
285
<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><li class="im"><a href="/baz-$itemId1"><img src="/baz-${itemId1}.png" alt="Baz ${itemId1}"></a></li></ul></div>
286
EOD;
287
288
        // @codingStandardsIgnoreEnd
289
290
        return [
291
            'with nothing'     => [$identifier, false, false, false, $itemIds, $withNothing],
292
            'with links'       => [$identifier, true, false, false, $itemIds, $withLinks],
293
            'with label links' => [$identifier, true, true, false, $itemIds, $withLabelLinks],
294
            'with image'       => [$identifier, false, false, true, $itemIds, $withImage],
295
            'with all'         => [$identifier, true, true, true, $itemIds, $withAll],
296
        ];
297
    }
298
299
    /**
300
     * @dataProvider buildVeryCustomProvider
301
     *
302
     * @param string   $identifier
303
     * @param bool     $withLinks
304
     * @param bool     $withLabelLinks
305
     * @param bool     $withImages
306
     * @param string[] $itemIds
307
     * @param string   $expectedResult
308
     */
309
    public function testBuildVeryCustom(
310
        string $identifier,
311
        bool $withLinks,
312
        bool $withLabelLinks,
313
        bool $withImages,
314
        array $itemIds,
315
        string $expectedResult
316
    ) {
317
        $entity = $this->createEntity($identifier, ...$itemIds)
318
            ->setWithLinks($withLinks)
319
            ->setWithLabelLinks($withLabelLinks)
320
            ->setWithImages($withImages);
321
322
        $attributes     = [
323
            IContentList::WITH_LABEL_OPTION  => '1',
324
            IContentList::WITH_IMAGES_OPTION => '1',
325
            IContentList::LIST_TAG           => Html5::TAG_DIV,
326
            IContentList::LIST_CLASS         => 'd',
327
            IContentList::ITEM_TAG           => Html5::TAG_UL,
328
            IContentList::ITEM_CLASS         => 'it',
329
            IContentList::LABEL_TAG          => Html5::TAG_LI,
330
            IContentList::LABEL_CLASS        => 'l',
331
            IContentList::CONTENT_TAG        => Html5::TAG_LI,
332
            IContentList::CONTENT_CLASS      => 'c',
333
            IContentList::IMAGE_TAG          => Html5::TAG_LI,
334
            IContentList::IMAGE_CLASS        => 'im',
335
        ];
336
        $parsedTemplate = new ParsedTemplate('', '', $attributes);
337
338
        $actualResult = $this->sut->build($entity, $parsedTemplate);
339
340
        $this->assertSame($expectedResult, $actualResult->getTemplates()['body']);
341
    }
342
}
343