Completed
Push — master ( 14d45a...b068a0 )
by Maurício
07:49
created

ServerCollationsControllerTest::testIndexAction()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 77
Code Lines 58

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 58
dl 0
loc 77
rs 8.9163
c 0
b 0
f 0
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
/* vim: set expandtab sw=4 ts=4 sts=4: */
3
/**
4
 * Holds ServerCollationsControllerTest class
5
 *
6
 * @package PhpMyAdmin-test
7
 */
8
declare(strict_types=1);
9
10
namespace PhpMyAdmin\Tests\Controllers\Server;
11
12
use PhpMyAdmin\Charsets;
13
use PhpMyAdmin\Config;
14
use PhpMyAdmin\Controllers\Server\ServerCollationsController;
15
use PhpMyAdmin\Response;
16
use PHPUnit\Framework\TestCase;
17
18
/**
19
 * Tests for ServerCollationsController class
20
 *
21
 * @package PhpMyAdmin-test
22
 */
23
class ServerCollationsControllerTest extends TestCase
24
{
25
    /**
26
     * Prepares environment for the test.
27
     *
28
     * @return void
29
     */
30
    protected function setUp(): void
31
    {
32
        $GLOBALS['PMA_Config'] = new Config();
33
        $GLOBALS['PMA_Config']->enableBc();
34
35
        $GLOBALS['server'] = 1;
36
        $GLOBALS['db'] = 'db';
37
        $GLOBALS['table'] = 'table';
38
        $GLOBALS['PMA_PHP_SELF'] = 'index.php';
39
        $GLOBALS['cfg']['Server']['DisableIS'] = false;
40
    }
41
42
    /**
43
     * @return void
44
     */
45
    public function testIndexAction(): void
46
    {
47
        $charsets = [
48
            'armscii8',
49
            'ascii',
50
            'big5',
51
            'binary',
52
        ];
53
        $charsetsDescriptions = [
54
            'armscii8' => 'PMA_armscii8_general_ci',
55
            'ascii' => 'PMA_ascii_general_ci',
56
            'big5' => 'PMA_big5_general_ci',
57
            'binary' => 'PMA_binary_general_ci',
58
        ];
59
        $collations = [
60
            'armscii8' => ['armscii8'],
61
            'ascii' => ['ascii'],
62
            'big5' => ['big5'],
63
            'binary' => ['binary'],
64
        ];
65
        $defaultCollations = [
66
            'armscii8' => 'armscii8',
67
            'ascii' => 'ascii',
68
            'big5' => 'big5',
69
            'binary' => 'binary',
70
        ];
71
72
        $controller = new ServerCollationsController(
73
            Response::getInstance(),
74
            $GLOBALS['dbi'],
75
            $charsets,
76
            $charsetsDescriptions,
77
            $collations,
78
            $defaultCollations
79
        );
80
81
        $actual = $controller->indexAction();
82
83
        $this->assertContains(
84
            '<div id="div_mysql_charset_collations">',
85
            $actual
86
        );
87
        $this->assertContains(
88
            __('Collation'),
89
            $actual
90
        );
91
        $this->assertContains(
92
            __('Description'),
93
            $actual
94
        );
95
        $this->assertContains(
96
            '<em>PMA_armscii8_general_ci</em>',
97
            $actual
98
        );
99
        $this->assertContains(
100
            '<td>armscii8</td>',
101
            $actual
102
        );
103
        $this->assertContains(
104
            '<td>' .  Charsets::getCollationDescr('armscii8') . '</td>',
0 ignored issues
show
Coding Style introduced by
Concat operator must be surrounded by a single space
Loading history...
105
            $actual
106
        );
107
        $this->assertContains(
108
            '<em>PMA_ascii_general_ci</em>',
109
            $actual
110
        );
111
        $this->assertContains(
112
            '<td>ascii</td>',
113
            $actual
114
        );
115
        $this->assertContains(
116
            '<em>PMA_big5_general_ci</em>',
117
            $actual
118
        );
119
        $this->assertContains(
120
            '<td>big5</td>',
121
            $actual
122
        );
123
    }
124
}
125