1
|
|
|
<?php |
2
|
|
|
namespace Mezon\Gui\Tests; |
3
|
|
|
|
4
|
|
|
use PHPUnit\Framework\TestCase; |
5
|
|
|
use Mezon\Gui\ListBuilder\Simple as SimpleListBuilder; |
6
|
|
|
|
7
|
|
|
class SimpleListBuilderUnitTest extends TestCase |
8
|
|
|
{ |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Method returns list of fields |
12
|
|
|
* |
13
|
|
|
* @return array Fields algorithms object |
14
|
|
|
*/ |
15
|
|
|
protected function getFields(): array |
16
|
|
|
{ |
17
|
|
|
return [ |
18
|
|
|
'id', |
19
|
|
|
'domain_id', |
20
|
|
|
'title' |
21
|
|
|
]; |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Method runs string assertions |
26
|
|
|
* |
27
|
|
|
* @param array $asserts |
28
|
|
|
* asserts |
29
|
|
|
* @param string $content |
30
|
|
|
* content to assert |
31
|
|
|
*/ |
32
|
|
|
protected function runAssertions(array $asserts, string $content): void |
33
|
|
|
{ |
34
|
|
|
foreach ($asserts as $assert) { |
35
|
|
|
$this->assertStringContainsString($assert, $content); |
36
|
|
|
} |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Testing constructor |
41
|
|
|
*/ |
42
|
|
|
public function testConstructorValid(): void |
43
|
|
|
{ |
44
|
|
|
// setup and test body |
45
|
|
|
$listBuilder = new SimpleListBuilder($this->getFields(), new FakeAdapter()); |
46
|
|
|
|
47
|
|
|
// assertions |
48
|
|
|
$this->assertIsArray($listBuilder->getFields(), 'Invalid fields list type'); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Method returns testing records |
53
|
|
|
* |
54
|
|
|
* @return array testing records |
55
|
|
|
*/ |
56
|
|
|
private function getRecords(): array |
57
|
|
|
{ |
58
|
|
|
return [ |
59
|
|
|
[ |
60
|
|
|
'id' => 1, |
61
|
|
|
], |
62
|
|
|
[ |
63
|
|
|
'id' => 2, |
64
|
|
|
] |
65
|
|
|
]; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Data provider for the testSimpleListingForm |
70
|
|
|
* |
71
|
|
|
* @return array test data |
72
|
|
|
*/ |
73
|
|
|
public function simpleListingFormDataProvider(): array |
74
|
|
|
{ |
75
|
|
|
return [ |
76
|
|
|
// #0, no records |
77
|
|
|
[ |
78
|
|
|
[], |
79
|
|
|
[ |
80
|
|
|
'class="no-items-title"' |
81
|
|
|
] |
82
|
|
|
], |
83
|
|
|
// #1, no records |
84
|
|
|
[ |
85
|
|
|
$this->getRecords(), |
86
|
|
|
[ |
87
|
|
|
'>1<', |
88
|
|
|
'>2<', |
89
|
|
|
] |
90
|
|
|
] |
91
|
|
|
]; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Testing listing form |
96
|
|
|
* |
97
|
|
|
* @param array $records |
98
|
|
|
* records to display |
99
|
|
|
* @param array $asserts |
100
|
|
|
* asserts |
101
|
|
|
* @dataProvider simpleListingFormDataProvider |
102
|
|
|
*/ |
103
|
|
|
public function testSimpleListingForm(array $records, array $asserts): void |
104
|
|
|
{ |
105
|
|
|
// setup |
106
|
|
|
$listBuilder = new SimpleListBuilder($this->getFields(), new FakeAdapter($records)); |
107
|
|
|
|
108
|
|
|
// test body |
109
|
|
|
$content = $listBuilder->listingForm(); |
110
|
|
|
|
111
|
|
|
// assertions |
112
|
|
|
$this->runAssertions($asserts, $content); |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|