1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Povs\ListerBundle\Service; |
4
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
6
|
|
|
use Povs\ListerBundle\Declaration\ListInterface; |
7
|
|
|
use Povs\ListerBundle\Exception\ListException; |
8
|
|
|
use Povs\ListerBundle\Type\ListType\ArrayListType; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @author Povilas Margaiatis <[email protected]> |
12
|
|
|
*/ |
13
|
|
|
class ConfigurationResolverTest extends TestCase |
14
|
|
|
{ |
15
|
|
|
private static $defaultConfig = [ |
16
|
|
|
'types' => [ |
17
|
|
|
'list' => ArrayListType::class, |
18
|
|
|
], |
19
|
|
|
'list_config' => [ |
20
|
|
|
'identifier' => 'id', |
21
|
|
|
'alias' => 'l', |
22
|
|
|
'translate' => false, |
23
|
|
|
'translation_domain' => null, |
24
|
|
|
'form_configuration' => [], |
25
|
|
|
'multi_column_sort' => false, |
26
|
|
|
'request' => [ |
27
|
|
|
'page' => 'page', |
28
|
|
|
'length' => 'length', |
29
|
|
|
'sort' => 'sort', |
30
|
|
|
'filter' => null, |
31
|
|
|
], |
32
|
|
|
'type_configuration' => [] |
33
|
|
|
] |
34
|
|
|
]; |
35
|
|
|
|
36
|
|
|
private static $config = [ |
37
|
|
|
'alias' => 'c', |
38
|
|
|
'form_configuration' => [ |
39
|
|
|
'form_config' => true, |
40
|
|
|
'form_config2' => false |
41
|
|
|
], |
42
|
|
|
'request' => [ |
43
|
|
|
'filter' => 'filter' |
44
|
|
|
], |
45
|
|
|
'multi_column_sort' => true, |
46
|
|
|
'type_configuration' => [ |
47
|
|
|
'list' => [ |
48
|
|
|
'test1' => true, |
49
|
|
|
'test2' => 'value' |
50
|
|
|
] |
51
|
|
|
] |
52
|
|
|
]; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @return ConfigurationResolver |
56
|
|
|
*/ |
57
|
|
|
public function testResolve(): ConfigurationResolver |
58
|
|
|
{ |
59
|
|
|
$resolver = new ConfigurationResolver([self::$defaultConfig]); |
60
|
|
|
$mock = $this->createMock(ListInterface::class); |
61
|
|
|
$mock->expects($this->once()) |
62
|
|
|
->method('configure') |
63
|
|
|
->willReturn(self::$config); |
64
|
|
|
|
65
|
|
|
$resolver->resolve($mock); |
66
|
|
|
|
67
|
|
|
return $resolver; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @depends testResolve |
72
|
|
|
* |
73
|
|
|
* @param ConfigurationResolver $resolver |
74
|
|
|
*/ |
75
|
|
|
public function testGetListTypeClass(ConfigurationResolver $resolver): void |
76
|
|
|
{ |
77
|
|
|
$this->assertEquals( |
78
|
|
|
ArrayListType::class, |
79
|
|
|
$resolver->getListTypeClass('list') |
80
|
|
|
); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @depends testResolve |
85
|
|
|
* |
86
|
|
|
* @param ConfigurationResolver $resolver |
87
|
|
|
*/ |
88
|
|
|
public function testGetListTypeClassThrowsException(ConfigurationResolver $resolver): void |
89
|
|
|
{ |
90
|
|
|
$this->expectException(ListException::class); |
91
|
|
|
$this->expectExceptionMessage('List type "test" is not configured'); |
92
|
|
|
|
93
|
|
|
$resolver->getListTypeClass('test'); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @depends testResolve |
98
|
|
|
* |
99
|
|
|
* @param ConfigurationResolver $resolver |
100
|
|
|
*/ |
101
|
|
|
public function testGetTypeConfiguration(ConfigurationResolver $resolver): void |
102
|
|
|
{ |
103
|
|
|
$expects = [ |
104
|
|
|
'test1' => true, |
105
|
|
|
'test2' => 'value' |
106
|
|
|
]; |
107
|
|
|
|
108
|
|
|
$this->assertEquals($expects, $resolver->getTypeConfiguration('list')); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @depends testResolve |
113
|
|
|
* |
114
|
|
|
* @param ConfigurationResolver $resolver |
115
|
|
|
*/ |
116
|
|
|
public function testGetTypeConfigurationNull(ConfigurationResolver $resolver): void |
117
|
|
|
{ |
118
|
|
|
$this->assertEquals([], $resolver->getTypeConfiguration('test')); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @depends testResolve |
123
|
|
|
* |
124
|
|
|
* @param ConfigurationResolver $resolver |
125
|
|
|
*/ |
126
|
|
|
public function testGetRequestConfiguration(ConfigurationResolver $resolver): void |
127
|
|
|
{ |
128
|
|
|
$expects = [ |
129
|
|
|
'page' => 'page', |
130
|
|
|
'length' => 'length', |
131
|
|
|
'sort' => 'sort', |
132
|
|
|
'filter' => 'filter', |
133
|
|
|
]; |
134
|
|
|
|
135
|
|
|
foreach ($expects as $key => $val) { |
136
|
|
|
$this->assertEquals($val, $resolver->getRequestConfiguration($key)); |
137
|
|
|
} |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @depends testResolve |
142
|
|
|
* |
143
|
|
|
* @param ConfigurationResolver $resolver |
144
|
|
|
*/ |
145
|
|
|
public function testGetIdentifier(ConfigurationResolver $resolver): void |
146
|
|
|
{ |
147
|
|
|
$this->assertEquals('id', $resolver->getIdentifier()); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @depends testResolve |
152
|
|
|
* @param ConfigurationResolver $resolver |
153
|
|
|
*/ |
154
|
|
|
public function testGetAlias(ConfigurationResolver $resolver): void |
155
|
|
|
{ |
156
|
|
|
$this->assertEquals('c', $resolver->getAlias()); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* @depends testResolve |
161
|
|
|
* @param ConfigurationResolver $resolver |
162
|
|
|
*/ |
163
|
|
|
public function testGetTranslate(ConfigurationResolver $resolver): void |
164
|
|
|
{ |
165
|
|
|
$this->assertFalse($resolver->getTranslate()); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* @depends testResolve |
170
|
|
|
* @param ConfigurationResolver $resolver |
171
|
|
|
*/ |
172
|
|
|
public function testGetTranslationDomain(ConfigurationResolver $resolver): void |
173
|
|
|
{ |
174
|
|
|
$this->assertNull($resolver->getTranslationDomain()); |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* @depends testResolve |
179
|
|
|
* @param ConfigurationResolver $resolver |
180
|
|
|
*/ |
181
|
|
|
public function testGetFormConfiguration(ConfigurationResolver $resolver): void |
182
|
|
|
{ |
183
|
|
|
$expected = [ |
184
|
|
|
'form_config' => true, |
185
|
|
|
'form_config2' => false |
186
|
|
|
]; |
187
|
|
|
|
188
|
|
|
$this->assertEquals($expected, $resolver->getFormConfiguration()); |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* @depends testResolve |
193
|
|
|
* @param ConfigurationResolver $resolver |
194
|
|
|
*/ |
195
|
|
|
public function testIsMultiColumnSortable(ConfigurationResolver $resolver): void |
196
|
|
|
{ |
197
|
|
|
$this->assertTrue($resolver->isMultiColumnSortable()); |
198
|
|
|
} |
199
|
|
|
} |
200
|
|
|
|