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 ( 861d7d...2ad8d1 )
by Cristian
04:38
created

CrudPanelButtonsTest::testAddButtonBeginning()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 8
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 0
dl 8
loc 8
rs 9.4285
1
<?php
2
3
namespace Backpack\CRUD\Tests\Unit\CrudPanel;
4
5
use Backpack\CRUD\PanelTraits\CrudButton;
6
7
class CrudPanelButtonsTest extends BaseCrudPanelTest
8
{
9
    private $defaultButtonNames = [
10
        'preview', 'update', 'revisions', 'delete', 'create', 'reorder',
11
    ];
12
13
    private $topViewButton;
14
    private $lineViewButton;
15
    private $bottomViewButton;
16
    private $topModelFunctionButton;
17
18
    protected function setUp()
19
    {
20
        parent::setUp();
21
22
        $this->topViewButton = new CrudButton('top', 'topViewButton', 'view', 'crud::buttons.preview');
23
        $this->lineViewButton = new CrudButton('line', 'lineViewButton', 'view', 'crud::buttons.update');
24
        $this->bottomViewButton = new CrudButton('bottom', 'bottomViewButton', 'view', 'crud::buttons.revisions');
25
26
        $this->topModelFunctionButton = new CrudButton('top', 'topModelFunctionButton', 'someModelFunctionName', 'crud::buttons.preview');
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 138 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
27
    }
28
29 View Code Duplication
    public function testDefaultButtons()
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...
30
    {
31
        $this->assertEquals(count($this->defaultButtonNames), count($this->crudPanel->buttons));
32
33
        foreach ($this->crudPanel->buttons as $button) {
34
            $this->assertTrue(in_array($button->name, $this->defaultButtonNames));
35
        }
36
    }
37
38 View Code Duplication
    public function testAddTopButtonTop()
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...
39
    {
40
        $expectedButton = $this->topViewButton;
41
42
        $this->crudPanel->addButton($expectedButton->stack, $expectedButton->name, $expectedButton->type, $expectedButton->content);
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 132 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
43
44
        $this->assertEquals($expectedButton, $this->crudPanel->buttons->last());
45
    }
46
47 View Code Duplication
    public function testAddButtonLine()
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...
48
    {
49
        $expectedButton = $this->lineViewButton;
50
51
        $this->crudPanel->addButton($expectedButton->stack, $expectedButton->name, $expectedButton->type, $expectedButton->content);
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 132 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
52
53
        $this->assertEquals($expectedButton, $this->crudPanel->buttons->first());
54
    }
55
56 View Code Duplication
    public function testAddButtonBottom()
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...
57
    {
58
        $expectedButton = $this->bottomViewButton;
59
60
        $this->crudPanel->addButton($expectedButton->stack, $expectedButton->name, $expectedButton->type, $expectedButton->content);
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 132 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
61
62
        $this->assertEquals($expectedButton, $this->crudPanel->buttons->last());
63
    }
64
65 View Code Duplication
    public function testAddButtonBottomUnknownStackName()
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...
66
    {
67
        $this->markTestIncomplete('Not correctly implemented');
68
69
        $this->setExpectedException(\Exception::class);
70
71
        $expectedButton = $this->topViewButton;
72
73
        // TODO: this should throw an error.
74
        $this->crudPanel->addButton('unknownStackName', $expectedButton->name, $expectedButton->type, $expectedButton->content);
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 128 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
75
    }
76
77
    public function testAddButtonsWithSameName()
78
    {
79
        $expectedButton = $this->topViewButton;
80
81
        $this->crudPanel->addButton($expectedButton->stack, $expectedButton->name, $expectedButton->type, $expectedButton->content);
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 132 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
82
        $this->crudPanel->addButton($expectedButton->stack, $expectedButton->name, $expectedButton->type, $expectedButton->content);
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 132 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
83
84
        $this->assertEquals(count($this->defaultButtonNames) + 1, count($this->crudPanel->buttons));
85
    }
86
87
    public function testAddButtonsWithSameNameWithoutReplacing()
88
    {
89
        $expectedButton = $this->topViewButton;
90
91
        $this->crudPanel->addButton($expectedButton->stack, $expectedButton->name, $expectedButton->type, $expectedButton->content, false, false);
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 146 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
92
        $this->crudPanel->addButton($expectedButton->stack, $expectedButton->name, $expectedButton->type, $expectedButton->content, false, false);
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 146 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
93
94
        $this->assertEquals(count($this->defaultButtonNames) + 2, count($this->crudPanel->buttons));
95
    }
96
97 View Code Duplication
    public function testAddButtonBeginning()
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...
98
    {
99
        $expectedButton = $this->topViewButton;
100
101
        $this->crudPanel->addButton($expectedButton->stack, $expectedButton->name, $expectedButton->type, $expectedButton->content, 'beginning');
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 145 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
102
103
        $this->assertEquals($expectedButton, $this->crudPanel->buttons->first());
104
    }
105
106 View Code Duplication
    public function testAddButtonEnd()
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...
107
    {
108
        $expectedButton = $this->lineViewButton;
109
110
        $this->crudPanel->addButton($expectedButton->stack, $expectedButton->name, $expectedButton->type, $expectedButton->content, 'end');
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 139 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
111
112
        $this->assertEquals($expectedButton, $this->crudPanel->buttons->last());
113
    }
114
115 View Code Duplication
    public function testAddButtonUnknownPosition()
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...
116
    {
117
        $this->markTestIncomplete('Not correctly implemented');
118
119
        $this->setExpectedException(\Exception::class);
120
121
        $expectedButton = $this->lineViewButton;
122
123
        // TODO: this should throw an error.
124
        $this->crudPanel->addButton($expectedButton->stack, $expectedButton->name, $expectedButton->type, $expectedButton->content, 'unknownPosition');
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 151 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
125
    }
126
127 View Code Duplication
    public function testAddButtonFromModelFunction()
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...
128
    {
129
        $expectedButton = $this->topModelFunctionButton;
130
131
        $this->crudPanel->addButton($expectedButton->stack, $expectedButton->name, $expectedButton->type, $expectedButton->content);
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 132 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
132
133
        $this->assertEquals($expectedButton, $this->crudPanel->buttons->last());
134
    }
135
136
    public function testAddButtonFromView()
137
    {
138
        $expectedButton = $this->topViewButton;
139
        $viewName = 'someViewName';
140
141
        $this->crudPanel->addButtonFromView($expectedButton->stack, $expectedButton->name, $viewName, $expectedButton->content);
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 128 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
142
143
        $backpackButtonViewPackage = 'vendor.backpack.crud.buttons.';
144
        $actualButton = $this->crudPanel->buttons->last();
145
146
        $this->assertEquals($expectedButton->stack, $actualButton->stack);
147
        $this->assertEquals($expectedButton->name, $actualButton->name);
148
        $this->assertEquals($backpackButtonViewPackage.$viewName, $actualButton->content);
149
        $this->assertEquals($expectedButton->stack, $actualButton->stack);
150
    }
151
152
    public function testRemoveButton()
153
    {
154
        $buttonName = $this->defaultButtonNames[0];
155
156
        $this->crudPanel->removeButton($buttonName);
157
158
        $this->assertEquals(count($this->defaultButtonNames) - 1, count($this->crudPanel->buttons));
159
        $this->assertNull($this->getButtonByName($buttonName));
160
    }
161
162
    public function testRemoveUnknownButton()
163
    {
164
        $buttonName = 'someButtonName';
165
166
        $this->crudPanel->removeButton($buttonName);
167
168
        $this->assertEquals(count($this->defaultButtonNames), count($this->crudPanel->buttons));
169
    }
170
171
    public function testRemoveAllButtons()
172
    {
173
        $this->crudPanel->removeAllButtons();
174
175
        $this->assertEmpty($this->crudPanel->buttons);
176
    }
177
178
    public function testRemoveButtonFromStack()
179
    {
180
        $button = $this->crudPanel->buttons->first();
181
182
        $this->crudPanel->removeButtonFromStack($button->name, $button->stack);
183
184
        $this->assertEquals(count($this->defaultButtonNames) - 1, count($this->crudPanel->buttons));
185
        $this->assertNull($this->getButtonByName($button->name));
186
    }
187
188
    public function testRemoveUnknownButtonFromStack()
189
    {
190
        $this->crudPanel->removeButtonFromStack('someButtonName', 'line');
191
192
        $this->assertEquals(count($this->defaultButtonNames), count($this->crudPanel->buttons));
193
    }
194
195 View Code Duplication
    public function testRemoveButtonFromUnknownStack()
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...
196
    {
197
        $button = $this->crudPanel->buttons->first();
198
199
        $this->crudPanel->removeButtonFromStack($button->name, 'someStackName');
200
201
        $this->assertEquals(count($this->defaultButtonNames), count($this->crudPanel->buttons));
202
    }
203
204
    public function testRemoveAllButtonsFromStack()
205
    {
206
        $this->crudPanel->removeAllButtonsFromStack('line');
207
208
        $this->assertEquals(2, count($this->crudPanel->buttons));
209
    }
210
211
    public function testRemoveAllButtonsFromUnknownStack()
212
    {
213
        $this->crudPanel->removeAllButtonsFromStack('someStackName');
214
215
        $this->assertEquals(count($this->defaultButtonNames), count($this->crudPanel->buttons));
216
    }
217
218
    private function getButtonByName($name)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
219
    {
220
        return $this->crudPanel->buttons->first(function ($value) use ($name) {
221
            return $value->name == $name;
222
        });
223
    }
224
}
225