1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Povs\ListerBundle\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
6
|
|
|
use Povs\ListerBundle\Type\ListType\ArrayListType; |
7
|
|
|
use Povs\ListerBundle\Type\ListType\CsvListType; |
8
|
|
|
use Symfony\Component\Config\Definition\Processor; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @author Povilas Margaiatis <[email protected]> |
12
|
|
|
*/ |
13
|
|
|
class ConfigurationTest extends TestCase |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var Configuration |
17
|
|
|
*/ |
18
|
|
|
private $configuration; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var Processor |
22
|
|
|
*/ |
23
|
|
|
private $processor; |
24
|
|
|
|
25
|
|
|
public function setUp(): void |
26
|
|
|
{ |
27
|
|
|
$this->configuration = new Configuration(); |
28
|
|
|
$this->processor = new Processor(); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function testDefaultConfig(): void |
32
|
|
|
{ |
33
|
|
|
$defaultConfig = [ |
34
|
|
|
'types' => [ |
35
|
|
|
'list' => ArrayListType::class |
36
|
|
|
], |
37
|
|
|
'list_config' => [ |
38
|
|
|
'identifier' => 'id', |
39
|
|
|
'alias' => 'l', |
40
|
|
|
'translate' => false, |
41
|
|
|
'translation_domain' => null, |
42
|
|
|
'multi_column_sort' => false, |
43
|
|
|
'form_configuration' => [], |
44
|
|
|
'request' => [ |
45
|
|
|
'page' => 'page', |
46
|
|
|
'length' => 'length', |
47
|
|
|
'sort' => 'sort', |
48
|
|
|
'filter' => null |
49
|
|
|
], |
50
|
|
|
'type_configuration' => [] |
51
|
|
|
], |
52
|
|
|
]; |
53
|
|
|
|
54
|
|
|
$config = $this->processor->processConfiguration($this->configuration, []); |
55
|
|
|
$this->assertEquals($defaultConfig, $config); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function testCustomConfig(): void |
59
|
|
|
{ |
60
|
|
|
$customConfig = [ |
61
|
|
|
'types' => [ |
62
|
|
|
'list' => ArrayListType::class, |
63
|
|
|
'csv' => CsvListType::class |
64
|
|
|
], |
65
|
|
|
'list_config' => [ |
66
|
|
|
'translate' => true, |
67
|
|
|
'multi_column_sort' => true, |
68
|
|
|
'form_configuration' => [ |
69
|
|
|
'config' => 'value' |
70
|
|
|
], |
71
|
|
|
'request' => [ |
72
|
|
|
'filter' => 'new_filter' |
73
|
|
|
], |
74
|
|
|
'type_configuration' => [ |
75
|
|
|
'list' => [ |
76
|
|
|
'length' => 1000, |
77
|
|
|
'limit' => 10000 |
78
|
|
|
] |
79
|
|
|
] |
80
|
|
|
], |
81
|
|
|
]; |
82
|
|
|
|
83
|
|
|
$expectedConfig = [ |
84
|
|
|
'types' => [ |
85
|
|
|
'list' => ArrayListType::class, |
86
|
|
|
'csv' => CsvListType::class |
87
|
|
|
], |
88
|
|
|
'list_config' => [ |
89
|
|
|
'identifier' => 'id', |
90
|
|
|
'alias' => 'l', |
91
|
|
|
'translate' => true, |
92
|
|
|
'translation_domain' => null, |
93
|
|
|
'multi_column_sort' => true, |
94
|
|
|
'form_configuration' => [ |
95
|
|
|
'config' => 'value' |
96
|
|
|
], |
97
|
|
|
'request' => [ |
98
|
|
|
'page' => 'page', |
99
|
|
|
'length' => 'length', |
100
|
|
|
'sort' => 'sort', |
101
|
|
|
'filter' => 'new_filter' |
102
|
|
|
], |
103
|
|
|
'type_configuration' => [ |
104
|
|
|
'list' => [ |
105
|
|
|
'length' => 1000, |
106
|
|
|
'limit' => 10000 |
107
|
|
|
] |
108
|
|
|
] |
109
|
|
|
], |
110
|
|
|
]; |
111
|
|
|
|
112
|
|
|
$config = $this->processor->processConfiguration($this->configuration, ['povs_lister' => $customConfig]); |
113
|
|
|
$this->assertEquals($expectedConfig, $config); |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|