1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Backpack\CRUD\Tests\Unit\CrudPanel; |
4
|
|
|
|
5
|
|
|
class CrudPanelColumnsTest extends BaseCrudPanelTest |
6
|
|
|
{ |
7
|
|
|
private $oneColumnArray = [ |
8
|
|
|
'name' => 'column1', |
9
|
|
|
'label' => 'Column1', |
10
|
|
|
]; |
11
|
|
|
|
12
|
|
|
private $otherOneColumnArray = [ |
13
|
|
|
'name' => 'column4', |
14
|
|
|
'label' => 'Column4', |
15
|
|
|
]; |
16
|
|
|
|
17
|
|
|
private $twoColumnsArray = [ |
18
|
|
|
[ |
19
|
|
|
'name' => 'column1', |
20
|
|
|
'label' => 'Column1', |
21
|
|
|
], |
22
|
|
|
[ |
23
|
|
|
'name' => 'column2', |
24
|
|
|
'label' => 'Column2', |
25
|
|
|
], |
26
|
|
|
]; |
27
|
|
|
|
28
|
|
|
private $expectedTwoColumnsArray = [ |
29
|
|
|
'column1' => [ |
30
|
|
|
'name' => 'column1', |
31
|
|
|
'label' => 'Column1', |
32
|
|
|
], |
33
|
|
|
'column2' => [ |
34
|
|
|
'name' => 'column2', |
35
|
|
|
'label' => 'Column2', |
36
|
|
|
], |
37
|
|
|
]; |
38
|
|
|
|
39
|
|
|
private $threeColumnsArray = [ |
40
|
|
|
[ |
41
|
|
|
'name' => 'column1', |
42
|
|
|
'label' => 'Column1', |
43
|
|
|
], |
44
|
|
|
[ |
45
|
|
|
'name' => 'column2', |
46
|
|
|
'label' => 'Column2', |
47
|
|
|
], |
48
|
|
|
[ |
49
|
|
|
'name' => 'column3', |
50
|
|
|
'label' => 'Column3', |
51
|
|
|
], |
52
|
|
|
]; |
53
|
|
|
|
54
|
|
|
private $expectedThreeColumnsArray = [ |
55
|
|
|
'column1' => [ |
56
|
|
|
'name' => 'column1', |
57
|
|
|
'label' => 'Column1', |
58
|
|
|
], |
59
|
|
|
'column2' => [ |
60
|
|
|
'name' => 'column2', |
61
|
|
|
'label' => 'Column2', |
62
|
|
|
], |
63
|
|
|
'column3' => [ |
64
|
|
|
'name' => 'column3', |
65
|
|
|
'label' => 'Column3', |
66
|
|
|
], |
67
|
|
|
]; |
68
|
|
|
|
69
|
|
View Code Duplication |
public function testAddColumnByName() |
|
|
|
|
70
|
|
|
{ |
71
|
|
|
$this->crudPanel->addColumn('column1'); |
72
|
|
|
|
73
|
|
|
$this->assertEquals(1, count($this->crudPanel->columns)); |
74
|
|
|
$this->assertContains($this->oneColumnArray, $this->crudPanel->columns); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function testAddColumnsByName() |
78
|
|
|
{ |
79
|
|
|
$this->crudPanel->addColumns(['column1', 'column2']); |
80
|
|
|
|
81
|
|
|
$this->assertEquals(2, count($this->crudPanel->columns)); |
82
|
|
|
$this->assertEquals($this->expectedTwoColumnsArray, $this->crudPanel->columns); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
View Code Duplication |
public function testAddColumnAsArray() |
|
|
|
|
86
|
|
|
{ |
87
|
|
|
$this->crudPanel->addColumn($this->oneColumnArray); |
88
|
|
|
|
89
|
|
|
$this->assertEquals(1, count($this->crudPanel->columns)); |
90
|
|
|
$this->assertContains($this->oneColumnArray, $this->crudPanel->columns); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
View Code Duplication |
public function testAddColumnsAsArray() |
|
|
|
|
94
|
|
|
{ |
95
|
|
|
$this->crudPanel->addColumns($this->twoColumnsArray); |
96
|
|
|
|
97
|
|
|
$this->assertEquals(2, count($this->crudPanel->columns)); |
98
|
|
|
$this->assertEquals($this->expectedTwoColumnsArray, $this->crudPanel->columns); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public function testAddColumnNotArray() |
102
|
|
|
{ |
103
|
|
|
$this->setExpectedException(\ErrorException::class); |
104
|
|
|
|
105
|
|
|
$this->crudPanel->addColumns('column1'); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
View Code Duplication |
public function testMoveColumnBefore() |
|
|
|
|
109
|
|
|
{ |
110
|
|
|
$this->crudPanel->addColumns($this->twoColumnsArray); |
111
|
|
|
|
112
|
|
|
$this->crudPanel->beforeColumn('column1'); |
113
|
|
|
|
114
|
|
|
$keys = array_keys($this->crudPanel->columns); |
115
|
|
|
$this->assertEquals($this->expectedTwoColumnsArray['column2'], $this->crudPanel->columns[$keys[0]]); |
116
|
|
|
$this->assertEquals(['column2', 'column1'], $keys); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
View Code Duplication |
public function testMoveColumnBeforeUnknownColumnName() |
|
|
|
|
120
|
|
|
{ |
121
|
|
|
$this->crudPanel->addColumns($this->twoColumnsArray); |
122
|
|
|
|
123
|
|
|
$this->crudPanel->beforeColumn('column3'); |
124
|
|
|
|
125
|
|
|
$this->assertEquals(array_keys($this->expectedTwoColumnsArray), array_keys($this->crudPanel->columns)); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
View Code Duplication |
public function testMoveColumnAfter() |
|
|
|
|
129
|
|
|
{ |
130
|
|
|
$this->crudPanel->addColumns($this->threeColumnsArray); |
131
|
|
|
|
132
|
|
|
$this->crudPanel->afterColumn('column1'); |
133
|
|
|
|
134
|
|
|
$keys = array_keys($this->crudPanel->columns); |
135
|
|
|
$this->assertEquals($this->expectedThreeColumnsArray['column3'], $this->crudPanel->columns[$keys[1]]); |
136
|
|
|
$this->assertEquals(['column1', 'column3', 'column2'], $keys); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
View Code Duplication |
public function testMoveColumnAfterUnknownColumnName() |
|
|
|
|
140
|
|
|
{ |
141
|
|
|
$this->crudPanel->addColumns($this->twoColumnsArray); |
142
|
|
|
|
143
|
|
|
$this->crudPanel->afterColumn('column3'); |
144
|
|
|
|
145
|
|
|
$this->assertEquals(array_keys($this->expectedTwoColumnsArray), array_keys($this->crudPanel->columns)); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
public function testRemoveColumnByName() |
149
|
|
|
{ |
150
|
|
|
$this->crudPanel->addColumns(['column1', 'column2', 'column3']); |
151
|
|
|
|
152
|
|
|
$this->crudPanel->removeColumn('column1'); |
153
|
|
|
|
154
|
|
|
$this->assertEquals(2, count($this->crudPanel->columns)); |
155
|
|
|
$this->assertEquals(['column2', 'column3'], array_keys($this->crudPanel->columns)); |
156
|
|
|
$this->assertNotContains($this->oneColumnArray, $this->crudPanel->columns); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
View Code Duplication |
public function testRemoveUnknownColumnName() |
|
|
|
|
160
|
|
|
{ |
161
|
|
|
$unknownColumnName = 'column4'; |
162
|
|
|
$this->crudPanel->addColumns(['column1', 'column2', 'column3']); |
163
|
|
|
|
164
|
|
|
$this->crudPanel->removeColumn($unknownColumnName); |
165
|
|
|
|
166
|
|
|
$this->assertEquals(3, count($this->crudPanel->columns)); |
167
|
|
|
$this->assertEquals(['column1', 'column2', 'column3'], array_keys($this->crudPanel->columns)); |
168
|
|
|
$this->assertNotContains($this->otherOneColumnArray, $this->crudPanel->columns); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
public function testRemoveColumnsByName() |
172
|
|
|
{ |
173
|
|
|
$this->crudPanel->addColumns(['column1', 'column2', 'column3']); |
174
|
|
|
|
175
|
|
|
$this->crudPanel->removeColumns($this->twoColumnsArray); |
176
|
|
|
|
177
|
|
|
$this->assertEquals(1, count($this->crudPanel->columns)); |
178
|
|
|
$this->assertEquals(['column3'], array_keys($this->crudPanel->columns)); |
179
|
|
|
$this->assertNotEquals($this->expectedThreeColumnsArray, $this->crudPanel->columns); |
180
|
|
|
} |
181
|
|
|
|
182
|
|
View Code Duplication |
public function testRemoveUnknownColumnsByName() |
|
|
|
|
183
|
|
|
{ |
184
|
|
|
$unknownColumnNames = ['column4', 'column5']; |
185
|
|
|
$this->crudPanel->addColumns(['column1', 'column2', 'column3']); |
186
|
|
|
|
187
|
|
|
$this->crudPanel->removeColumns($unknownColumnNames); |
188
|
|
|
|
189
|
|
|
$this->assertEquals(3, count($this->crudPanel->columns)); |
190
|
|
|
$this->assertEquals(['column1', 'column2', 'column3'], array_keys($this->crudPanel->columns)); |
191
|
|
|
$this->assertNotContains($this->otherOneColumnArray, $this->crudPanel->columns); |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
public function testSetColumnDetails() |
195
|
|
|
{ |
196
|
|
|
$this->markTestIncomplete('Not correctly implemented'); |
197
|
|
|
|
198
|
|
|
// TODO: refactor crud panel sync method |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
public function testSetColumnsDetails() |
202
|
|
|
{ |
203
|
|
|
$this->markTestIncomplete('Not correctly implemented'); |
204
|
|
|
|
205
|
|
|
// TODO: refactor crud panel sync method |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
public function testSetColumnOrder() |
209
|
|
|
{ |
210
|
|
|
$this->markTestIncomplete('Not yet implemented'); |
211
|
|
|
|
212
|
|
|
// TODO: implement method |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
public function testSetColumnsOrder() |
216
|
|
|
{ |
217
|
|
|
$this->markTestIncomplete('Not yet implemented'); |
218
|
|
|
|
219
|
|
|
// TODO: implement method |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
public function testOrderColumns() |
223
|
|
|
{ |
224
|
|
|
$this->markTestIncomplete('Not correctly implemented'); |
225
|
|
|
|
226
|
|
|
// TODO: fix order columns method |
227
|
|
|
} |
228
|
|
|
} |
229
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.