Passed
Push — master ( 9b36c0...600079 )
by Maurício
07:43
created

PrivilegesControllerTest::testIndex()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 87
Code Lines 61

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 61
c 1
b 0
f 0
dl 0
loc 87
rs 8.8509
cc 1
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * Class PrivilegesControllerTest
4
 * @package PhpMyAdmin\Tests\Controllers\Table
5
 */
6
declare(strict_types=1);
7
8
namespace PhpMyAdmin\Tests\Controllers\Table;
9
10
use PhpMyAdmin\Controllers\Table\PrivilegesController;
11
use PhpMyAdmin\Response;
12
use PhpMyAdmin\Server\Privileges;
13
use PhpMyAdmin\Template;
14
use PhpMyAdmin\Tests\PmaTestCase;
15
use PhpMyAdmin\Url;
16
17
/**
18
 * Class PrivilegesControllerTest
19
 * @package PhpMyAdmin\Tests\Controllers\Table
20
 */
21
class PrivilegesControllerTest extends PmaTestCase
22
{
23
    /**
24
     * @return void
25
     */
26
    public function testIndex(): void
27
    {
28
        global $dbi, $db, $table, $server, $cfg, $PMA_PHP_SELF, $is_grantuser, $is_createuser;
29
30
        $db = 'db';
31
        $table = 'table';
32
        $server = 0;
33
        $cfg['Server']['DisableIS'] = false;
34
        $PMA_PHP_SELF = 'index.php';
35
        $is_grantuser = true;
36
        $is_createuser = true;
37
38
        $privileges = [];
39
40
        $serverPrivileges = $this->createMock(Privileges::class);
41
        $serverPrivileges->method('getAllPrivileges')
42
            ->willReturn($privileges);
43
44
        $controller = new PrivilegesController(
45
            Response::getInstance(),
46
            $dbi,
47
            new Template(),
48
            $db,
49
            $table,
50
            $serverPrivileges
51
        );
52
        $actual = $controller->index([
53
            'checkprivsdb' => $db,
54
            'checkprivstable' => $table,
55
        ]);
56
57
        $this->assertStringContainsString(
58
            $db . '.' . $table,
59
            $actual
60
        );
61
62
        //validate 2: Url::getCommon
63
        $item = Url::getCommon([
64
            'db' => $db,
65
            'table' => $table,
66
        ], '');
67
        $this->assertStringContainsString(
68
            $item,
69
            $actual
70
        );
71
72
        //validate 3: items
73
        $this->assertStringContainsString(
74
            __('User'),
75
            $actual
76
        );
77
        $this->assertStringContainsString(
78
            __('Host'),
79
            $actual
80
        );
81
        $this->assertStringContainsString(
82
            __('Type'),
83
            $actual
84
        );
85
        $this->assertStringContainsString(
86
            __('Privileges'),
87
            $actual
88
        );
89
        $this->assertStringContainsString(
90
            __('Grant'),
91
            $actual
92
        );
93
        $this->assertStringContainsString(
94
            __('Action'),
95
            $actual
96
        );
97
        $this->assertStringContainsString(
98
            __('No user found'),
99
            $actual
100
        );
101
102
        //_pgettext('Create new user', 'New')
103
        $this->assertStringContainsString(
104
            _pgettext('Create new user', 'New'),
105
            $actual
106
        );
107
        $this->assertStringContainsString(
108
            Url::getCommon([
109
                'checkprivsdb' => $db,
110
                'checkprivstable' => $table,
111
            ]),
112
            $actual
113
        );
114
    }
115
}
116