Passed
Push — master ( 600079...672aee )
by Maurício
09:05
created

PrivilegesControllerTest::testIndex()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 69
Code Lines 48

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 48
c 1
b 0
f 0
dl 0
loc 69
rs 9.1344
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\Database
5
 */
6
declare(strict_types=1);
7
8
namespace PhpMyAdmin\Tests\Controllers\Database;
9
10
use PhpMyAdmin\Controllers\Database\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\Database
20
 */
21
class PrivilegesControllerTest extends PmaTestCase
22
{
23
    /**
24
     * @return void
25
     */
26
    public function testIndex(): void
27
    {
28
        global $dbi, $db, $server, $cfg, $PMA_PHP_SELF, $is_grantuser, $is_createuser;
29
30
        $db = 'db';
31
        $server = 0;
32
        $cfg['Server']['DisableIS'] = false;
33
        $PMA_PHP_SELF = 'index.php';
34
        $is_grantuser = true;
35
        $is_createuser = true;
36
37
        $privileges = [];
38
39
        $serverPrivileges = $this->createMock(Privileges::class);
40
        $serverPrivileges->method('getAllPrivileges')
41
            ->willReturn($privileges);
42
43
        $controller = new PrivilegesController(
44
            Response::getInstance(),
45
            $dbi,
46
            new Template(),
47
            $db,
48
            $serverPrivileges
49
        );
50
        $actual = $controller->index(['checkprivsdb' => $db]);
51
52
        $this->assertStringContainsString(
53
            Url::getCommon(['db' => $db], ''),
54
            $actual
55
        );
56
57
        $this->assertStringContainsString(
58
            $db,
59
            $actual
60
        );
61
62
        $this->assertStringContainsString(
63
            __('User'),
64
            $actual
65
        );
66
        $this->assertStringContainsString(
67
            __('Host'),
68
            $actual
69
        );
70
        $this->assertStringContainsString(
71
            __('Type'),
72
            $actual
73
        );
74
        $this->assertStringContainsString(
75
            __('Privileges'),
76
            $actual
77
        );
78
        $this->assertStringContainsString(
79
            __('Grant'),
80
            $actual
81
        );
82
        $this->assertStringContainsString(
83
            __('Action'),
84
            $actual
85
        );
86
87
        //_pgettext('Create new user', 'New')
88
        $this->assertStringContainsString(
89
            _pgettext('Create new user', 'New'),
90
            $actual
91
        );
92
        $this->assertStringContainsString(
93
            Url::getCommon(['checkprivsdb' => $db]),
94
            $actual
95
        );
96
    }
97
}
98