Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ProcessesControllerTest.php « Status « Server « Controllers « classes « test - github.com/phpmyadmin/phpmyadmin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: cae09c768f1d0159c8675dcde80d7b4e2a95a5f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
<?php

declare(strict_types=1);

namespace PhpMyAdmin\Tests\Controllers\Server\Status;

use PhpMyAdmin\Controllers\Server\Status\ProcessesController;
use PhpMyAdmin\Server\Status\Data;
use PhpMyAdmin\Template;
use PhpMyAdmin\Tests\AbstractTestCase;
use PhpMyAdmin\Tests\Stubs\ResponseRenderer;
use PhpMyAdmin\Url;

use function __;
use function htmlspecialchars;

/**
 * @covers \PhpMyAdmin\Controllers\Server\Status\ProcessesController
 */
class ProcessesControllerTest extends AbstractTestCase
{
    /** @var Data */
    private $data;

    protected function setUp(): void
    {
        parent::setUp();
        $GLOBALS['text_dir'] = 'ltr';
        parent::setGlobalConfig();
        parent::setTheme();

        $GLOBALS['server'] = 1;
        $GLOBALS['db'] = 'db';
        $GLOBALS['table'] = 'table';
        $GLOBALS['PMA_PHP_SELF'] = 'index.php';
        $GLOBALS['cfg']['Server']['DisableIS'] = false;
        $GLOBALS['cfg']['Server']['host'] = 'localhost';

        $this->data = new Data();
    }

    public function testIndex(): void
    {
        $response = new ResponseRenderer();

        $controller = new ProcessesController($response, new Template(), $this->data, $GLOBALS['dbi']);

        $this->dummyDbi->addSelectDb('mysql');
        $controller->index();
        $this->assertAllSelectsConsumed();
        $html = $response->getHTMLResult();

        $this->assertStringContainsString(
            'Note: Enabling the auto refresh here might cause '
            . 'heavy traffic between the web server and the MySQL server.',
            $html
        );
        // Test tab links
        $this->assertStringContainsString(
            '<div class="tabLinks row">',
            $html
        );
        $this->assertStringContainsString(
            '<a id="toggleRefresh" href="#">',
            $html
        );
        $this->assertStringContainsString(
            'play',
            $html
        );
        $this->assertStringContainsString(
            'Start auto refresh',
            $html
        );
        $this->assertStringContainsString(
            '<select id="id_refreshRate"',
            $html
        );
        $this->assertStringContainsString(
            '<option value="5" selected>',
            $html
        );
        $this->assertStringContainsString(
            '5 seconds',
            $html
        );

        $this->assertStringContainsString(
            '<table id="tableprocesslist" class="table table-light table-striped table-hover sortable w-auto">',
            $html
        );
        $this->assertStringContainsString(
            '<th>Processes</th>',
            $html
        );
        $this->assertStringContainsString(
            'Show full queries',
            $html
        );
        $this->assertStringContainsString(
            'index.php?route=/server/status/processes',
            $html
        );

        $_POST['full'] = '1';
        $_POST['column_name'] = 'Database';
        $_POST['order_by_field'] = 'db';
        $_POST['sort_order'] = 'ASC';

        $this->dummyDbi->addSelectDb('mysql');
        $controller->index();
        $this->assertAllSelectsConsumed();
        $html = $response->getHTMLResult();

        $this->assertStringContainsString(
            'Truncate shown queries',
            $html
        );
        $this->assertStringContainsString(
            'Database',
            $html
        );
        $this->assertStringContainsString(
            'DESC',
            $html
        );

        $_POST['column_name'] = 'Host';
        $_POST['order_by_field'] = 'Host';
        $_POST['sort_order'] = 'DESC';

        $this->dummyDbi->addSelectDb('mysql');
        $controller->index();
        $this->assertAllSelectsConsumed();
        $html = $response->getHTMLResult();

        $this->assertStringContainsString(
            'Host',
            $html
        );
        $this->assertStringContainsString(
            'ASC',
            $html
        );
    }

    public function testRefresh(): void
    {
        $process = [
            'User' => 'User1',
            'Host' => 'Host1',
            'Id' => 'Id1',
            'db' => 'db1',
            'Command' => 'Command1',
            'Info' => 'Info1',
            'State' => 'State1',
            'Time' => 'Time1',
        ];
        $GLOBALS['cfg']['MaxCharactersInDisplayedSQL'] = 12;

        $response = new ResponseRenderer();
        $response->setAjax(true);

        $controller = new ProcessesController($response, new Template(), $this->data, $GLOBALS['dbi']);

        $_POST['full'] = '1';
        $_POST['order_by_field'] = 'process';
        $_POST['sort_order'] = 'DESC';

        $controller->refresh();
        $html = $response->getHTMLResult();

        $this->assertStringContainsString(
            'index.php?route=/server/status/processes',
            $html
        );
        $killProcess = 'data-post="'
            . Url::getCommon(['kill' => $process['Id']], '') . '"';
        $this->assertStringContainsString(
            $killProcess,
            $html
        );
        $this->assertStringContainsString(
            'ajax kill_process',
            $html
        );
        $this->assertStringContainsString(
            __('Kill'),
            $html
        );

        //validate 2: $process['User']
        $this->assertStringContainsString(
            htmlspecialchars($process['User']),
            $html
        );

        //validate 3: $process['Host']
        $this->assertStringContainsString(
            htmlspecialchars($process['Host']),
            $html
        );

        //validate 4: $process['db']
        $this->assertStringContainsString(
            __('None'),
            $html
        );

        //validate 5: $process['Command']
        $this->assertStringContainsString(
            htmlspecialchars($process['Command']),
            $html
        );

        //validate 6: $process['Time']
        $this->assertStringContainsString(
            $process['Time'],
            $html
        );

        //validate 7: $process['state']
        $this->assertStringContainsString(
            $process['State'],
            $html
        );

        //validate 8: $process['info']
        $this->assertStringContainsString(
            $process['Info'],
            $html
        );
    }
}