1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Backpack\CRUD\Tests\Unit\CrudPanel; |
4
|
|
|
|
5
|
|
|
use Backpack\CRUD\Tests\config\Models\Article; |
6
|
|
|
use Illuminate\Support\Arr; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* @covers Backpack\CRUD\app\Library\CrudPanel\Traits\Tabs |
10
|
|
|
*/ |
11
|
|
|
class CrudPanelTabsTest extends \Backpack\CRUD\Tests\config\CrudPanel\BaseCrudPanel |
12
|
|
|
{ |
13
|
|
|
private $horizontalTabsType = 'horizontal'; |
14
|
|
|
private $verticalTabsType = 'vertical'; |
15
|
|
|
|
16
|
|
|
private $threeTextFieldsArray = [ |
17
|
|
|
[ |
18
|
|
|
'name' => 'field1', |
19
|
|
|
'label' => 'Field1', |
20
|
|
|
], |
21
|
|
|
[ |
22
|
|
|
'name' => 'field2', |
23
|
|
|
'label' => 'Field2', |
24
|
|
|
'tab' => 'First Tab', |
25
|
|
|
], |
26
|
|
|
[ |
27
|
|
|
'name' => 'field3', |
28
|
|
|
'label' => 'Field3', |
29
|
|
|
'tab' => 'First Tab', |
30
|
|
|
'type' => 'email', |
31
|
|
|
], |
32
|
|
|
[ |
33
|
|
|
'name' => 'field4', |
34
|
|
|
'label' => 'Field4', |
35
|
|
|
'tab' => 'Second Tab', |
36
|
|
|
], |
37
|
|
|
[ |
38
|
|
|
'name' => 'field5', |
39
|
|
|
'label' => 'Field5', |
40
|
|
|
'tab' => 'Third Tab', |
41
|
|
|
], |
42
|
|
|
]; |
43
|
|
|
|
44
|
|
|
private $expectedTabNames = ['First Tab', 'Second Tab', 'Third Tab']; |
45
|
|
|
|
46
|
|
|
private $expectedFieldsInFirstTab = [ |
47
|
|
|
'field2' => [ |
48
|
|
|
'name' => 'field2', |
49
|
|
|
'label' => 'Field2', |
50
|
|
|
'tab' => 'First Tab', |
51
|
|
|
'type' => 'text', |
52
|
|
|
], |
53
|
|
|
'field3' => [ |
54
|
|
|
'name' => 'field3', |
55
|
|
|
'label' => 'Field3', |
56
|
|
|
'tab' => 'First Tab', |
57
|
|
|
'type' => 'email', |
58
|
|
|
], |
59
|
|
|
]; |
60
|
|
|
|
61
|
|
|
private $expectedFieldsInSecondTab = [ |
62
|
|
|
'field2' => [ |
63
|
|
|
'name' => 'field4', |
64
|
|
|
'label' => 'Field4', |
65
|
|
|
'tab' => 'Second Tab', |
66
|
|
|
'type' => 'text', |
67
|
|
|
], |
68
|
|
|
]; |
69
|
|
|
|
70
|
|
|
private $expectedFieldsInThirdTab = [ |
71
|
|
|
'field2' => [ |
72
|
|
|
'name' => 'field5', |
73
|
|
|
'label' => 'Field5', |
74
|
|
|
'tab' => 'Third Tab', |
75
|
|
|
'type' => 'text', |
76
|
|
|
], |
77
|
|
|
]; |
78
|
|
|
|
79
|
|
|
public function testEnableTabs() |
80
|
|
|
{ |
81
|
|
|
$this->crudPanel->setOperation('create'); |
82
|
|
|
$this->crudPanel->enableTabs(); |
83
|
|
|
|
84
|
|
|
$this->assertTrue($this->crudPanel->getOperationSetting('tabsEnabled')); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function testDisableTabs() |
88
|
|
|
{ |
89
|
|
|
$this->crudPanel->disableTabs(); |
90
|
|
|
|
91
|
|
|
$this->assertFalse($this->crudPanel->getOperationSetting('tabsEnabled')); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function testTabsEnabled() |
95
|
|
|
{ |
96
|
|
|
$this->crudPanel->enableTabs(); |
97
|
|
|
|
98
|
|
|
$this->assertTrue($this->crudPanel->tabsEnabled()); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public function testTabsDisabled() |
102
|
|
|
{ |
103
|
|
|
$this->crudPanel->disableTabs(); |
104
|
|
|
|
105
|
|
|
$this->assertTrue($this->crudPanel->tabsDisabled()); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
public function testSetTabsType() |
109
|
|
|
{ |
110
|
|
|
$this->crudPanel->setTabsType($this->verticalTabsType); |
111
|
|
|
|
112
|
|
|
$this->assertEquals($this->verticalTabsType, $this->crudPanel->getOperationSetting('tabsType')); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
public function testGetTabsType() |
116
|
|
|
{ |
117
|
|
|
$this->crudPanel->setOperation('create'); |
118
|
|
|
$this->crudPanel->enableTabs(); |
119
|
|
|
|
120
|
|
|
$defaultTabsType = $this->crudPanel->getTabsType(); |
121
|
|
|
|
122
|
|
|
$this->assertEquals($this->horizontalTabsType, $defaultTabsType); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
public function testEnableVerticalTabs() |
126
|
|
|
{ |
127
|
|
|
$this->crudPanel->enableVerticalTabs(); |
128
|
|
|
|
129
|
|
|
$this->assertEquals($this->verticalTabsType, $this->crudPanel->getTabsType()); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
public function testDisableVerticalTabs() |
133
|
|
|
{ |
134
|
|
|
$this->crudPanel->disableVerticalTabs(); |
135
|
|
|
|
136
|
|
|
$this->assertEquals($this->horizontalTabsType, $this->crudPanel->getTabsType()); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
public function testEnableHorizontalTabs() |
140
|
|
|
{ |
141
|
|
|
$this->crudPanel->enableHorizontalTabs(); |
142
|
|
|
|
143
|
|
|
$this->assertEquals($this->horizontalTabsType, $this->crudPanel->getTabsType()); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
public function testDisableHorizontalTabs() |
147
|
|
|
{ |
148
|
|
|
$this->crudPanel->disableHorizontalTabs(); |
149
|
|
|
|
150
|
|
|
$this->assertEquals($this->verticalTabsType, $this->crudPanel->getTabsType()); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
public function testTabExists() |
154
|
|
|
{ |
155
|
|
|
$this->crudPanel->addFields($this->threeTextFieldsArray); |
156
|
|
|
|
157
|
|
|
$tabExists = $this->crudPanel->tabExists($this->expectedTabNames[0]); |
158
|
|
|
|
159
|
|
|
$this->assertTrue($tabExists); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
public function testTabExistsUnknownLabel() |
163
|
|
|
{ |
164
|
|
|
$this->crudPanel->addFields($this->threeTextFieldsArray); |
165
|
|
|
|
166
|
|
|
$tabExists = $this->crudPanel->tabExists('someLabel'); |
167
|
|
|
|
168
|
|
|
$this->assertFalse($tabExists); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
public function testGetLastTab() |
172
|
|
|
{ |
173
|
|
|
$this->crudPanel->addFields($this->threeTextFieldsArray); |
174
|
|
|
|
175
|
|
|
$lastTab = $this->crudPanel->getLastTab(); |
176
|
|
|
|
177
|
|
|
$this->assertEquals(Arr::last($this->expectedTabNames), $lastTab); |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
public function testGetLastTabNoTabs() |
181
|
|
|
{ |
182
|
|
|
$lastTab = $this->crudPanel->getLastTab(); |
183
|
|
|
|
184
|
|
|
$this->assertFalse($lastTab); |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
public function testIsLastTab() |
188
|
|
|
{ |
189
|
|
|
$this->crudPanel->addFields($this->threeTextFieldsArray); |
190
|
|
|
|
191
|
|
|
$isFirstLastTab = $this->crudPanel->isLastTab($this->expectedTabNames[0]); |
192
|
|
|
$isSecondLastTab = $this->crudPanel->isLastTab($this->expectedTabNames[1]); |
193
|
|
|
$isThirdLastTab = $this->crudPanel->isLastTab($this->expectedTabNames[2]); |
194
|
|
|
|
195
|
|
|
$this->assertFalse($isFirstLastTab); |
196
|
|
|
$this->assertFalse($isSecondLastTab); |
197
|
|
|
$this->assertTrue($isThirdLastTab); |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
public function testIsLastTabUnknownLabel() |
201
|
|
|
{ |
202
|
|
|
$this->crudPanel->addFields($this->threeTextFieldsArray); |
203
|
|
|
|
204
|
|
|
$isUnknownLastTab = $this->crudPanel->isLastTab('someLabel'); |
205
|
|
|
|
206
|
|
|
$this->assertFalse($isUnknownLastTab); |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
public function testGetTabFields() |
210
|
|
|
{ |
211
|
|
|
$this->markTestIncomplete('Not correctly implemented'); |
212
|
|
|
|
213
|
|
|
$this->crudPanel->addFields($this->threeTextFieldsArray); |
214
|
|
|
|
215
|
|
|
// TODO: the method returns an eloquent collection in case fields for a given label are found, array if |
216
|
|
|
// otherwise. the return type should be either one or the other. |
217
|
|
|
$firstTabFields = $this->crudPanel->getTabItems($this->expectedTabNames[0]); |
218
|
|
|
$secondTabFields = $this->crudPanel->getTabItems($this->expectedTabNames[1]); |
219
|
|
|
$thirdTabFields = $this->crudPanel->getTabItems($this->expectedTabNames[2]); |
220
|
|
|
|
221
|
|
|
$this->assertEquals($this->expectedFieldsInFirstTab, $firstTabFields); |
222
|
|
|
$this->assertEquals($this->expectedFieldsInSecondTab, $secondTabFields); |
223
|
|
|
$this->assertEquals($this->expectedFieldsInThirdTab, $thirdTabFields); |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
public function testGetTabFieldsUnknownLabel() |
227
|
|
|
{ |
228
|
|
|
$tabFields = $this->crudPanel->getTabItems('someLabel', 'fields'); |
229
|
|
|
|
230
|
|
|
$this->assertEmpty($tabFields); |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
public function testGetTabs() |
234
|
|
|
{ |
235
|
|
|
$this->crudPanel->addFields($this->threeTextFieldsArray); |
236
|
|
|
|
237
|
|
|
$tabNames = $this->crudPanel->getTabs(); |
238
|
|
|
|
239
|
|
|
$this->assertEquals($this->expectedTabNames, $tabNames); |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
public function testGetTabsEntryExists() |
243
|
|
|
{ |
244
|
|
|
$this->crudPanel->setModel(Article::class); |
245
|
|
|
$this->crudPanel->addFields($this->threeTextFieldsArray); |
246
|
|
|
$tabNames = $this->crudPanel->getTabs(); |
247
|
|
|
$this->assertEquals($this->expectedTabNames, $tabNames); |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
public function testGetFieldsWithoutTab() |
251
|
|
|
{ |
252
|
|
|
$this->crudPanel->addFields($this->threeTextFieldsArray); |
253
|
|
|
|
254
|
|
|
$fieldsWithoutTab = $this->crudPanel->getElementsWithoutATab($this->crudPanel->fields()); |
255
|
|
|
$fieldWithoutTab = $this->threeTextFieldsArray[0]; |
256
|
|
|
$this->assertCount(1, $fieldsWithoutTab); |
257
|
|
|
$this->assertEquals('field1', $fieldWithoutTab['name']); |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
public function testItCanGetTabItemsForDifferentSources() |
261
|
|
|
{ |
262
|
|
|
$this->crudPanel->addColumns($this->threeTextFieldsArray); |
263
|
|
|
|
264
|
|
|
$tabItems = $this->crudPanel->getTabItems($this->expectedTabNames[0], 'columns'); |
265
|
|
|
|
266
|
|
|
$this->assertCount(2, $tabItems); |
267
|
|
|
} |
268
|
|
|
} |
269
|
|
|
|