1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kunstmaan\AdminListBundle\Tests\AdminList; |
4
|
|
|
|
5
|
|
|
use Codeception\Test\Unit; |
6
|
|
|
use Kunstmaan\AdminListBundle\AdminList\AdminList; |
7
|
|
|
use Kunstmaan\AdminListBundle\AdminList\BulkAction\BulkActionInterface; |
8
|
|
|
use Kunstmaan\AdminListBundle\AdminList\Configurator\AdminListConfiguratorInterface; |
9
|
|
|
use Kunstmaan\AdminListBundle\AdminList\FilterBuilder; |
10
|
|
|
use Kunstmaan\AdminListBundle\AdminList\ItemAction\ItemActionInterface; |
11
|
|
|
use Kunstmaan\AdminListBundle\AdminList\ListAction\ListActionInterface; |
12
|
|
|
use Pagerfanta\Pagerfanta; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class AdminListTest |
16
|
|
|
*/ |
17
|
|
|
class AdminListTest extends Unit |
18
|
|
|
{ |
19
|
|
|
/** @var AdminList */ |
20
|
|
|
protected $adminList; |
21
|
|
|
|
22
|
|
|
public function _before() |
23
|
|
|
{ |
24
|
|
|
/** @var AdminListConfiguratorInterface */ |
25
|
|
|
$configurator = $this->makeEmpty(AdminListConfiguratorInterface::class, [ |
26
|
|
|
'getFilterBuilder' => new FilterBuilder(), |
27
|
|
|
'getFields' => ['a', 'b'], |
28
|
|
|
'getExportFields' => ['c', 'd'], |
29
|
|
|
'getCount' => '666', |
30
|
|
|
'getItems' => ['item'], |
31
|
|
|
'getIterator' => $this->makeEmpty(\Iterator::class), |
32
|
|
|
'getSortFields' => ['e', 'f'], |
33
|
|
|
'canEdit' => true, |
34
|
|
|
'canAdd' => true, |
35
|
|
|
'canView' => true, |
36
|
|
|
'canDelete' => true, |
37
|
|
|
'canExport' => true, |
38
|
|
|
'getIndexUrl' => [], |
39
|
|
|
'getEditUrlFor' => [], |
40
|
|
|
'getDeleteUrlFor' => [], |
41
|
|
|
'getAddUrlFor' => [], |
42
|
|
|
'getExportUrl' => [], |
43
|
|
|
'getViewUrlFor' => [], |
44
|
|
|
'getValue' => 'test', |
45
|
|
|
'getStringValue' => 'stringtest', |
46
|
|
|
'getOrderBy' => 'name', |
47
|
|
|
'getOrderDirection' => 'up', |
48
|
|
|
'getItemActions' => [$this->makeEmpty(ItemActionInterface::class)], |
49
|
|
|
'hasItemActions' => true, |
50
|
|
|
'getListActions' => [$this->makeEmpty(ListActionInterface::class)], |
51
|
|
|
'hasListActions' => true, |
52
|
|
|
'getBulkActions' => [$this->makeEmpty(BulkActionInterface::class)], |
53
|
|
|
'hasBulkActions' => true, |
54
|
|
|
'getPagerfanta' => $this->makeEmpty(Pagerfanta::class), |
55
|
|
|
]); |
56
|
|
|
|
57
|
|
|
$this->adminList = new AdminList($configurator); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function testGetConfigurator() |
61
|
|
|
{ |
62
|
|
|
$this->assertInstanceOf(AdminListConfiguratorInterface::class, $this->adminList->getConfigurator()); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function testGetFilterBuilder() |
66
|
|
|
{ |
67
|
|
|
$this->assertInstanceOf(FilterBuilder::class, $this->adminList->getFilterBuilder()); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function testGetColumns() |
71
|
|
|
{ |
72
|
|
|
$this->assertContains('a', $this->adminList->getColumns()); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function testGetExportColumns() |
76
|
|
|
{ |
77
|
|
|
$this->assertContains('c', $this->adminList->getExportColumns()); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function testGetCount() |
81
|
|
|
{ |
82
|
|
|
$this->assertEquals(666, $this->adminList->getCount()); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function testGetItems() |
86
|
|
|
{ |
87
|
|
|
$this->assertContains('item', $this->adminList->getItems()); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function getIterator() |
91
|
|
|
{ |
92
|
|
|
$this->assertInstanceOf(\Iterator::class, $this->adminList->getIterator()); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function testHasSort() |
96
|
|
|
{ |
97
|
|
|
$this->assertEquals(2, $this->adminList->hasSort()); |
98
|
|
|
$this->assertTrue($this->adminList->hasSort('e')); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public function testCanEdit() |
102
|
|
|
{ |
103
|
|
|
$item = new \stdClass(); |
104
|
|
|
$this->assertTrue($this->adminList->canEdit($item)); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
public function testCanAdd() |
108
|
|
|
{ |
109
|
|
|
$item = new \stdClass(); |
110
|
|
|
$this->assertTrue($this->adminList->canAdd($item)); |
|
|
|
|
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
public function testCanView() |
114
|
|
|
{ |
115
|
|
|
$item = new \stdClass(); |
116
|
|
|
$this->assertTrue($this->adminList->canView($item)); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
public function testCanDelete() |
120
|
|
|
{ |
121
|
|
|
$item = new \stdClass(); |
122
|
|
|
$this->assertTrue($this->adminList->canDelete($item)); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
public function testCanExport() |
126
|
|
|
{ |
127
|
|
|
$this->assertTrue($this->adminList->canExport()); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
public function testGetIndexUrl() |
131
|
|
|
{ |
132
|
|
|
$this->assertTrue(is_array($this->adminList->getIndexUrl())); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
public function testGetEditUrlFor() |
136
|
|
|
{ |
137
|
|
|
$item = new \stdClass(); |
138
|
|
|
$this->assertTrue(is_array($this->adminList->getEditUrlFor($item))); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
public function testGetDeleteUrlFor() |
142
|
|
|
{ |
143
|
|
|
$item = new \stdClass(); |
144
|
|
|
$this->assertTrue(is_array($this->adminList->getDeleteUrlFor($item))); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
public function testGetAddUrlFor() |
148
|
|
|
{ |
149
|
|
|
$this->assertTrue(is_array($this->adminList->getAddUrlFor([]))); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
public function testGetExportUrl() |
153
|
|
|
{ |
154
|
|
|
$this->assertTrue(is_array($this->adminList->getExportUrl())); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
public function testGetViewUrl() |
158
|
|
|
{ |
159
|
|
|
$item = new \stdClass(); |
160
|
|
|
$this->assertTrue(is_array($this->adminList->getViewUrlFor($item))); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
public function testGetValue() |
164
|
|
|
{ |
165
|
|
|
$object = new \stdClass(); |
166
|
|
|
$this->assertEquals('test', $this->adminList->getValue($object, 'test')); |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
public function testGetStringValue() |
170
|
|
|
{ |
171
|
|
|
$object = new \stdClass(); |
172
|
|
|
$this->assertEquals('stringtest', $this->adminList->getStringValue($object, 'test')); |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
public function testGetOrderBy() |
176
|
|
|
{ |
177
|
|
|
$this->assertEquals('name', $this->adminList->getOrderBy()); |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
public function testGetOrderDirection() |
181
|
|
|
{ |
182
|
|
|
$this->assertEquals('up', $this->adminList->getOrderDirection()); |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
public function testGetItemActions() |
186
|
|
|
{ |
187
|
|
|
$itemActions = $this->adminList->getItemActions(); |
188
|
|
|
$this->assertTrue(is_array($itemActions)); |
189
|
|
|
$this->assertInstanceOf(ItemActionInterface::class, current($itemActions)); |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
public function testHasItemActions() |
193
|
|
|
{ |
194
|
|
|
$this->assertTrue($this->adminList->hasItemActions()); |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
public function testHasListActions() |
198
|
|
|
{ |
199
|
|
|
$this->assertTrue($this->adminList->hasListActions()); |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
public function testGetListActions() |
203
|
|
|
{ |
204
|
|
|
$listActions = $this->adminList->getListActions(); |
205
|
|
|
$this->assertTrue(is_array($listActions)); |
206
|
|
|
$this->assertInstanceOf(ListActionInterface::class, current($listActions)); |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
public function testGetBulkActions() |
210
|
|
|
{ |
211
|
|
|
$bulkActions = $this->adminList->getBulkActions(); |
212
|
|
|
$this->assertTrue(is_array($bulkActions)); |
213
|
|
|
$this->assertInstanceOf(BulkActionInterface::class, current($bulkActions)); |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
public function testHasBulkActions() |
217
|
|
|
{ |
218
|
|
|
$this->assertTrue($this->adminList->hasBulkActions()); |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
public function testGetPagerfanta() |
222
|
|
|
{ |
223
|
|
|
$this->assertInstanceOf(Pagerfanta::class, $this->adminList->getPagerfanta()); |
224
|
|
|
} |
225
|
|
|
} |
226
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.