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 ( b25548...bfec59 )
by Cristian
05:53
created

CrudPanelTabsTest   A

Complexity

Total Complexity 20

Size/Duplication

Total Lines 242
Duplicated Lines 5.79 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 82.14%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 14
loc 242
rs 10
ccs 46
cts 56
cp 0.8214
wmc 20
lcom 1
cbo 2

20 Methods

Rating   Name   Duplication   Size   Complexity  
A testEnableTabs() 0 6 1
A testDisableTabs() 0 6 1
A testTabsEnabled() 0 6 1
A testTabsDisabled() 0 6 1
A testSetTabsType() 0 6 1
A testGetTabsType() 0 6 1
A testEnableVerticalTabs() 0 6 1
A testDisableVerticalTabs() 0 6 1
A testEnableHorizontalTabs() 0 6 1
A testDisableHorizontalTabs() 0 6 1
A testTabExists() 0 8 1
A testTabExistsUnknownLabel() 0 8 1
A testGetLastTab() 0 8 1
A testGetLastTabNoTabs() 0 6 1
A testIsLastTab() 0 12 1
A testIsLastTabUnknownLabel() 0 8 1
A testGetTabFields() 0 16 1
A testGetTabFieldsUnknownLabel() 0 6 1
A testGetTabs() 0 8 1
A testGetTabsEntryExists() 14 14 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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