Remove replication_info global variable
[phpmyadmin.git] / test / classes / Controllers / Server / Status / ProcessesControllerTest.php
blobae72274f403b2f675da70d23dfd8253b0909f4a3
1 <?php
2 /**
3 * Holds ProcessesControllerTest
4 */
6 declare(strict_types=1);
8 namespace PhpMyAdmin\Tests\Controllers\Server\Status;
10 use PhpMyAdmin\Controllers\Server\Status\ProcessesController;
11 use PhpMyAdmin\Server\Status\Data;
12 use PhpMyAdmin\Template;
13 use PhpMyAdmin\Tests\AbstractTestCase;
14 use PhpMyAdmin\Tests\Stubs\Response;
15 use PhpMyAdmin\Url;
16 use function htmlspecialchars;
18 class ProcessesControllerTest extends AbstractTestCase
20 /** @var Data */
21 private $data;
23 protected function setUp(): void
25 parent::setUp();
26 $GLOBALS['text_dir'] = 'ltr';
27 parent::setGlobalConfig();
28 $GLOBALS['PMA_Config']->enableBc();
29 parent::setTheme();
31 $GLOBALS['server'] = 1;
32 $GLOBALS['db'] = 'db';
33 $GLOBALS['table'] = 'table';
34 $GLOBALS['PMA_PHP_SELF'] = 'index.php';
35 $GLOBALS['cfg']['Server']['DisableIS'] = false;
36 $GLOBALS['cfg']['Server']['host'] = 'localhost';
38 $this->data = new Data();
41 public function testIndex(): void
43 $response = new Response();
45 $controller = new ProcessesController(
46 $response,
47 $GLOBALS['dbi'],
48 new Template(),
49 $this->data
52 $controller->index();
53 $html = $response->getHTMLResult();
55 $this->assertStringContainsString(
56 'Note: Enabling the auto refresh here might cause '
57 . 'heavy traffic between the web server and the MySQL server.',
58 $html
60 // Test tab links
61 $this->assertStringContainsString(
62 '<div class="tabLinks row">',
63 $html
65 $this->assertStringContainsString(
66 '<a id="toggleRefresh" href="#">',
67 $html
69 $this->assertStringContainsString(
70 'play',
71 $html
73 $this->assertStringContainsString(
74 'Start auto refresh',
75 $html
77 $this->assertStringContainsString(
78 '<select id="id_refreshRate"',
79 $html
81 $this->assertStringContainsString(
82 '<option value="5" selected>',
83 $html
85 $this->assertStringContainsString(
86 '5 seconds',
87 $html
90 $this->assertStringContainsString(
91 '<table id="tableprocesslist" '
92 . 'class="data clearfloat noclick sortable">',
93 $html
95 $this->assertStringContainsString(
96 '<th>Processes</th>',
97 $html
99 $this->assertStringContainsString(
100 'Show full queries',
101 $html
103 $this->assertStringContainsString(
104 'index.php?route=/server/status/processes',
105 $html
108 $_POST['full'] = '1';
109 $_POST['column_name'] = 'Database';
110 $_POST['order_by_field'] = 'db';
111 $_POST['sort_order'] = 'ASC';
113 $controller->index();
114 $html = $response->getHTMLResult();
116 $this->assertStringContainsString(
117 'Truncate shown queries',
118 $html
120 $this->assertStringContainsString(
121 'Database',
122 $html
124 $this->assertStringContainsString(
125 'DESC',
126 $html
129 $_POST['column_name'] = 'Host';
130 $_POST['order_by_field'] = 'Host';
131 $_POST['sort_order'] = 'DESC';
133 $controller->index();
134 $html = $response->getHTMLResult();
136 $this->assertStringContainsString(
137 'Host',
138 $html
140 $this->assertStringContainsString(
141 'ASC',
142 $html
146 public function testRefresh(): void
148 $process = [
149 'User' => 'User1',
150 'Host' => 'Host1',
151 'Id' => 'Id1',
152 'db' => 'db1',
153 'Command' => 'Command1',
154 'Info' => 'Info1',
155 'State' => 'State1',
156 'Time' => 'Time1',
158 $GLOBALS['cfg']['MaxCharactersInDisplayedSQL'] = 12;
160 $response = new Response();
161 $response->setAjax(true);
163 $controller = new ProcessesController(
164 $response,
165 $GLOBALS['dbi'],
166 new Template(),
167 $this->data
170 $_POST['full'] = '1';
171 $_POST['order_by_field'] = 'process';
172 $_POST['sort_order'] = 'DESC';
174 $controller->refresh();
175 $html = $response->getHTMLResult();
177 $this->assertStringContainsString(
178 'index.php?route=/server/status/processes',
179 $html
181 $killProcess = 'data-post="'
182 . Url::getCommon(['kill' => $process['Id']], '') . '"';
183 $this->assertStringContainsString(
184 $killProcess,
185 $html
187 $this->assertStringContainsString(
188 'ajax kill_process',
189 $html
191 $this->assertStringContainsString(
192 __('Kill'),
193 $html
196 //validate 2: $process['User']
197 $this->assertStringContainsString(
198 htmlspecialchars($process['User']),
199 $html
202 //validate 3: $process['Host']
203 $this->assertStringContainsString(
204 htmlspecialchars($process['Host']),
205 $html
208 //validate 4: $process['db']
209 $this->assertStringContainsString(
210 __('None'),
211 $html
214 //validate 5: $process['Command']
215 $this->assertStringContainsString(
216 htmlspecialchars($process['Command']),
217 $html
220 //validate 6: $process['Time']
221 $this->assertStringContainsString(
222 $process['Time'],
223 $html
226 //validate 7: $process['state']
227 $this->assertStringContainsString(
228 $process['State'],
229 $html
232 //validate 8: $process['info']
233 $this->assertStringContainsString(
234 $process['Info'],
235 $html