3 declare(strict_types
=1);
5 namespace PhpMyAdmin\Tests
;
7 use PhpMyAdmin\Replication
;
8 use PhpMyAdmin\ReplicationGui
;
9 use PhpMyAdmin\ReplicationInfo
;
10 use PhpMyAdmin\Template
;
13 * PhpMyAdmin\Tests\ReplicationGuiTest class
15 * this class is for testing PhpMyAdmin\ReplicationGui methods
17 class ReplicationGuiTest
extends AbstractTestCase
20 * ReplicationGui instance
24 private $replicationGui;
27 * Prepares environment for the test.
29 protected function setUp(): void
33 $_POST['mr_adduser'] = 'mr_adduser';
36 $GLOBALS['cfg']['MaxRows'] = 10;
37 $GLOBALS['cfg']['ServerDefault'] = 'server';
38 $GLOBALS['cfg']['RememberSorting'] = true;
39 $GLOBALS['cfg']['SQP'] = [];
40 $GLOBALS['cfg']['MaxCharactersInDisplayedSQL'] = 1000;
41 $GLOBALS['cfg']['ShowSQL'] = true;
42 $GLOBALS['cfg']['TableNavigationLinksMode'] = 'icons';
43 $GLOBALS['cfg']['LimitChars'] = 100;
44 $GLOBALS['cfg']['DBG']['sql'] = false;
45 $GLOBALS['cfg']['ShowHint'] = true;
47 $GLOBALS['table'] = 'table';
48 $GLOBALS['server'] = 0;
49 $GLOBALS['url_params'] = [];
51 $this->replicationGui
= new ReplicationGui(new Replication(), new Template());
55 * Test for getHtmlForMasterReplication
59 public function testGetHtmlForMasterReplication(): void
61 $html = $this->replicationGui
->getHtmlForMasterReplication();
63 //validate 1: Master replication
64 $this->assertStringContainsString(
65 '<legend>Master replication</legend>',
68 $this->assertStringContainsString(
69 'This server is configured as master in a replication process.',
73 //validate 2: getHtmlForReplicationStatusTable
74 $this->assertStringContainsString(
75 '<div id="replication_master_section"',
79 $this->assertStringContainsString(
83 $this->assertStringContainsString(
88 $this->assertStringContainsString(
93 //validate 3: getHtmlForReplicationSlavesTable
94 $this->assertStringContainsString(
95 'replication_slaves_section',
98 $this->assertStringContainsString(
102 $this->assertStringContainsString(
107 $this->assertStringContainsString(
108 '<td class="value">Server_id1</td>',
111 $this->assertStringContainsString(
112 '<td class="value">Server_id2</td>',
115 $this->assertStringContainsString(
116 '<td class="value">Host1</td>',
119 $this->assertStringContainsString(
120 '<td class="value">Host2</td>',
124 $this->assertStringContainsString(
125 'Only slaves started with the',
129 //validate 4: navigation URL
130 $this->assertStringContainsString(
131 '<a href="index.php?route=/server/replication',
134 $this->assertStringContainsString(
135 'Add slave replication user',
139 //validate 5: 'Add replication slave user' form
140 $this->assertStringContainsString(
141 '<div id="master_addslaveuser_gui">',
147 * Test for getHtmlForSlaveConfiguration
149 public function testGetHtmlForSlaveConfiguration(): void
151 $replicationInfo = new ReplicationInfo($GLOBALS['dbi']);
152 $replicationInfo->load();
154 //Call the test function
155 $html = $this->replicationGui
->getHtmlForSlaveConfiguration(
157 $replicationInfo->getReplicaStatus()
161 $this->assertStringContainsString(
162 '<legend>Slave replication</legend>',
165 $this->assertStringContainsString(
166 '<div id="slave_configuration_gui">',
170 $this->assertStringContainsString(
171 'Server is configured as slave in a replication process.',
175 $this->assertStringContainsString(
176 '<div id="replication_slave_section"',
180 $this->assertStringContainsString(
181 'Master_SSL_CA_Path',
184 $this->assertStringContainsString(
188 $this->assertStringContainsString(
192 $this->assertStringContainsString(
193 'Seconds_Behind_Master',
199 * Test for getHtmlForReplicationChangeMaster
201 public function testGetHtmlForReplicationChangeMaster(): void
203 //Call the test function
204 $html = $this->replicationGui
->getHtmlForReplicationChangeMaster(
208 $this->assertStringContainsString(
209 '<form method="post" action="index.php?route=/server/replication',
212 $this->assertStringContainsString(
213 'Slave configuration',
216 $this->assertStringContainsString(
217 'Change or reconfigure master server',
220 $notice = 'Make sure you have a unique server-id '
221 . 'in your configuration file (my.cnf)';
222 $this->assertStringContainsString(