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 — v4dot1 ( e6b5d2...496635 )
by Cristian
23:20 queued 15:38
created

CrudPanelSaveActionsTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 37

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 37
rs 9.328
c 0
b 0
f 0
1
<?php
2
3
namespace Backpack\CRUD\Tests\Unit\CrudPanel;
4
5
class CrudPanelSaveActionsTest extends BaseDBCrudPanelTest
0 ignored issues
show
Bug introduced by
There is at least one abstract method in this class. Maybe declare it as abstract, or implement the remaining methods: artisan, be, call, seed
Loading history...
6
{
7
    private $singleSaveAction;
8
9
    private $multipleSaveActions;
10
11
    /**
12
     * Setup the test environment.
13
     *
14
     * @return void
15
     */
16
    protected function setUp(): void
17
    {
18
        parent::setUp();
19
20
        $this->crudPanel->setOperation('create');
21
22
        $this->singleSaveAction = [
23
            'name' => 'save_action_one',
24
            'redirect' => function ($crud, $request, $itemId) {
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $itemId is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
25
                return $crud->route;
26
            },
27
            'visible' => function ($crud) {
0 ignored issues
show
Unused Code introduced by
The parameter $crud is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
28
                return true;
29
            },
30
        ];
31
32
        $this->multipleSaveActions = [
33
            [
34
                'name' => 'save_action_one',
35
                'redirect' => function ($crud, $request, $itemId) {
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $itemId is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
36
                    return $crud->route;
37
                },
38
                'visible' => function ($crud) {
0 ignored issues
show
Unused Code introduced by
The parameter $crud is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
39
                    return true;
40
                },
41
            ],
42
            [
43
                'name' => 'save_action_two',
44
                'redirect' => function ($crud, $request, $itemId) {
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $itemId is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
45
                    return $crud->route;
46
                },
47
                'visible' => function ($crud) {
0 ignored issues
show
Unused Code introduced by
The parameter $crud is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
48
                    return true;
49
                },
50
            ],
51
        ];
52
    }
53
54
    public function testAddDefaultSaveActions()
55
    {
56
        $this->crudPanel->setupDefaultSaveActions();
57
        $this->assertEquals(3, count($this->crudPanel->getOperationSetting('save_actions')));
58
    }
59
60 View Code Duplication
    public function testAddOneSaveAction()
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...
61
    {
62
        $this->crudPanel->setupDefaultSaveActions();
63
        $this->crudPanel->addSaveAction($this->singleSaveAction);
64
65
        $this->assertEquals(4, count($this->crudPanel->getOperationSetting('save_actions')));
66
        $this->assertEquals(['save_and_back', 'save_and_edit', 'save_and_new', 'save_action_one'], array_keys($this->crudPanel->getOperationSetting('save_actions')));
67
    }
68
69 View Code Duplication
    public function testAddMultipleSaveActions()
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->setupDefaultSaveActions();
72
        $this->crudPanel->addSaveActions($this->multipleSaveActions);
73
74
        $this->assertEquals(5, count($this->crudPanel->getOperationSetting('save_actions')));
75
        $this->assertEquals(['save_and_back', 'save_and_edit', 'save_and_new', 'save_action_one', 'save_action_two'], array_keys($this->crudPanel->getOperationSetting('save_actions')));
76
    }
77
78 View Code Duplication
    public function testRemoveOneSaveAction()
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...
79
    {
80
        $this->crudPanel->setupDefaultSaveActions();
81
        $this->crudPanel->removeSaveAction('save_and_new');
82
        $this->assertEquals(2, count($this->crudPanel->getOperationSetting('save_actions')));
83
        $this->assertEquals(['save_and_back', 'save_and_edit'], array_keys($this->crudPanel->getOperationSetting('save_actions')));
84
    }
85
86 View Code Duplication
    public function testRemoveMultipleSaveActions()
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...
87
    {
88
        $this->crudPanel->setupDefaultSaveActions();
89
        $this->crudPanel->removeSaveActions(['save_and_new', 'save_and_edit']);
90
        $this->assertEquals(1, count($this->crudPanel->getOperationSetting('save_actions')));
91
        $this->assertEquals(['save_and_back'], array_keys($this->crudPanel->getOperationSetting('save_actions')));
92
    }
93
94 View Code Duplication
    public function testReplaceSaveActionsWithOneSaveAction()
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...
95
    {
96
        $this->crudPanel->setupDefaultSaveActions();
97
        $this->crudPanel->replaceSaveActions($this->singleSaveAction);
98
        $this->assertEquals(1, count($this->crudPanel->getOperationSetting('save_actions')));
99
        $this->assertEquals(['save_action_one'], array_keys($this->crudPanel->getOperationSetting('save_actions')));
100
    }
101
102 View Code Duplication
    public function testReplaceSaveActionsWithMultipleSaveActions()
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...
103
    {
104
        $this->crudPanel->setupDefaultSaveActions();
105
        $this->crudPanel->replaceSaveActions($this->multipleSaveActions);
106
        $this->assertEquals(2, count($this->crudPanel->getOperationSetting('save_actions')));
107
        $this->assertEquals(['save_action_one', 'save_action_two'], array_keys($this->crudPanel->getOperationSetting('save_actions')));
108
    }
109
110
    public function testOrderOneSaveAction()
111
    {
112
        $this->crudPanel->setupDefaultSaveActions();
113
        $this->crudPanel->orderSaveAction('save_and_new', 1);
114
        $this->assertEquals(1, $this->crudPanel->getOperationSetting('save_actions')['save_and_new']['order']);
115
    }
116
117
    public function testOrderMultipleSaveActions()
118
    {
119
        $this->crudPanel->setupDefaultSaveActions();
120
        $this->crudPanel->orderSaveActions(['save_and_new', 'save_and_back']);
121
        $this->assertEquals(1, $this->crudPanel->getOperationSetting('save_actions')['save_and_new']['order']);
122
        $this->assertEquals(2, $this->crudPanel->getOperationSetting('save_actions')['save_and_back']['order']);
123
        $this->assertEquals(3, $this->crudPanel->getOperationSetting('save_actions')['save_and_edit']['order']);
124
    }
125
}
126