Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Completed
Push — master ( 09719b...ca9302 )
by Cristian
04:21
created

testOrderColumnsIncompleteList()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 8
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 8
loc 8
rs 9.4285
c 0
b 0
f 0
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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 View Code Duplication
    public function testAddColumnsByName()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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 View Code Duplication
    public function testOrderColumns()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
209
    {
210
        $this->crudPanel->addColumns($this->threeColumnsArray);
211
212
        $this->crudPanel->orderColumns(['column2', 'column1', 'column3']);
213
214
        $this->assertEquals(['column2', 'column1', 'column3'], array_keys($this->crudPanel->columns));
215
    }
216
217 View Code Duplication
    public function testOrderColumnsIncompleteList()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
218
    {
219
        $this->crudPanel->addColumns($this->threeColumnsArray);
220
221
        $this->crudPanel->orderColumns(['column2', 'column3']);
222
223
        $this->assertEquals(['column2', 'column3', 'column1'], array_keys($this->crudPanel->columns));
224
    }
225
226
    public function testOrderColumnsEmptyList()
227
    {
228
        $this->crudPanel->addColumns($this->threeColumnsArray);
229
230
        $this->crudPanel->orderColumns([]);
231
232
        $this->assertEquals($this->expectedThreeColumnsArray, $this->crudPanel->columns);
233
    }
234
235 View Code Duplication
    public function testOrderColumnsUnknownList()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
236
    {
237
        $this->crudPanel->addColumns($this->threeColumnsArray);
238
239
        $this->crudPanel->orderColumns(['column4', 'column5', 'column6']);
240
241
        $this->assertEquals($this->expectedThreeColumnsArray, $this->crudPanel->columns);
242
    }
243
244 View Code Duplication
    public function testOrderColumnsMixedList()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
245
    {
246
        $this->crudPanel->addColumns($this->threeColumnsArray);
247
248
        $this->crudPanel->orderColumns(['column2', 'column5', 'column6']);
249
250
        $this->assertEquals(['column2', 'column1', 'column3'], array_keys($this->crudPanel->columns));
251
    }
252
}
253