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
|
<?php
declare(strict_types=1);
namespace PhpMyAdmin\Tests\Selenium;
/**
* @coversNothing
*/
#[\PHPUnit\Framework\Attributes\CoversNothing]
class TrackingTest extends TestBase
{
/**
* Setup the browser environment to run the selenium test case
*/
protected function setUp(): void
{
parent::setUp();
$this->dbQuery(
'USE `' . $this->databaseName . '`;'
. 'CREATE TABLE `test_table` ('
. ' `id` int(11) NOT NULL AUTO_INCREMENT,'
. ' `val` int(11) NOT NULL,'
. ' PRIMARY KEY (`id`)'
. ');'
. 'CREATE TABLE `test_table_2` ('
. ' `id` int(11) NOT NULL AUTO_INCREMENT,'
. ' `val` int(11) NOT NULL,'
. ' PRIMARY KEY (`id`)'
. ');'
. 'INSERT INTO `test_table` (val) VALUES (2), (3);'
);
$this->login();
$this->skipIfNotPMADB();
$this->navigateDatabase($this->databaseName);
$this->expandMore();
$this->waitForElement('partialLinkText', 'Tracking')->click();
$this->waitAjax();
$this->waitForElement('partialLinkText', 'Track table');
$this->byXPath("(//a[contains(., 'Track table')])[1]")->click();
$this->waitAjax();
$this->waitForElement('name', 'delete')->click();
$this->byCssSelector("input[value='Create version']")->click();
$this->waitForElement('id', 'versions');
}
/**
* Tests basic tracking functionality
*
* @group large
*/
#[\PHPUnit\Framework\Attributes\Group('large-group')]
public function testTrackingData(): void
{
$this->executeSqlAndReturnToTableTracking();
$this->byPartialLinkText('Tracking report')->click();
$this->waitForElement('xpath', "//h3[contains(., 'Tracking report')]");
self::assertStringContainsString(
'DROP TABLE IF EXISTS `test_table`',
$this->getCellByTableId('ddl_versions', 1, 4)
);
self::assertStringContainsString('CREATE TABLE `test_table` (', $this->getCellByTableId('ddl_versions', 2, 4));
self::assertStringContainsString(
'UPDATE test_table SET val = val + 1',
$this->getCellByTableId('dml_versions', 1, 4)
);
self::assertStringNotContainsString(
'DELETE FROM test_table WHERE val = 3',
$this->byId('dml_versions')->getText()
);
// only structure
$this->selectByLabel(
$this->byName('logtype'),
'Structure only'
);
$this->byCssSelector("input[value='Go']")->click();
$this->waitAjax();
self::assertFalse($this->isElementPresent('id', 'dml_versions'));
self::assertStringContainsString(
'DROP TABLE IF EXISTS `test_table`',
$this->getCellByTableId('ddl_versions', 1, 4)
);
self::assertStringContainsString('CREATE TABLE `test_table` (', $this->getCellByTableId('ddl_versions', 2, 4));
// only data
$this->selectByLabel(
$this->waitForElement('name', 'logtype'),
'Data only'
);
$this->byCssSelector("input[value='Go']")->click();
$this->waitAjax();
self::assertFalse($this->isElementPresent('id', 'ddl_versions'));
self::assertStringContainsString(
'UPDATE test_table SET val = val + 1',
$this->getCellByTableId('dml_versions', 1, 4)
);
self::assertStringNotContainsString(
'DELETE FROM test_table WHERE val = 3',
$this->byId('dml_versions')->getText()
);
}
/**
* Tests deactivation of tracking
*
* @group large
*/
#[\PHPUnit\Framework\Attributes\Group('large-group')]
public function testDeactivateTracking(): void
{
$this->byCssSelector("input[value='Deactivate now']")->click();
$this->waitForElement('cssSelector', "input[value='Activate now']");
$this->executeSqlAndReturnToTableTracking();
self::assertFalse($this->isElementPresent('id', 'dml_versions'));
}
/**
* Tests dropping a tracking
*
* @group large
*/
#[\PHPUnit\Framework\Attributes\Group('large-group')]
public function testDropTracking(): void
{
$this->navigateDatabase($this->databaseName, true);
$this->expandMore();
$this->byPartialLinkText('Tracking')->click();
$this->waitAjax();
$this->waitForElement('id', 'versions');
$ele = $this->waitForElement('cssSelector', 'table#versions tbody tr:nth-child(1) td:nth-child(7) a');
$this->moveto($ele);
$this->click();
$this->waitForElement('cssSelector', 'button.submitOK')->click();
$this->waitAjax();
$this->waitForElement(
'xpath',
'//div[@class=\'alert alert-success\' and contains(., \'Tracking data deleted successfully.\')]'
);
// Can not use getCellByTableId,
// since this is under 'th' and not 'td'
self::assertStringContainsString('test_table', $this->waitForElement(
'cssSelector',
'table#noversions tbody tr:nth-child(1) th:nth-child(2)'
)->getText());
self::assertStringContainsString('test_table_2', $this->waitForElement(
'cssSelector',
'table#noversions tbody tr:nth-child(2) th:nth-child(2)'
)->getText());
}
/**
* Tests structure snapshot of a tracking
*
* @group large
*/
#[\PHPUnit\Framework\Attributes\Group('large-group')]
public function testStructureSnapshot(): void
{
$this->byPartialLinkText('Structure snapshot')->click();
$this->waitForElement('id', 'tablestructure');
self::assertStringContainsString('id', $this->getCellByTableId('tablestructure', 1, 2));
self::assertStringContainsString('val', $this->getCellByTableId('tablestructure', 2, 2));
self::assertStringContainsString('PRIMARY', $this->getCellByTableId('tablestructure_indexes', 1, 1));
self::assertStringContainsString('id', $this->getCellByTableId('tablestructure_indexes', 1, 5));
}
/**
* Goes to SQL tab, executes queries, returns to tracking page
*/
private function executeSqlAndReturnToTableTracking(): void
{
$this->byPartialLinkText('SQL')->click();
$this->waitAjax();
$this->waitForElement('id', 'queryfieldscontainer');
$this->typeInTextArea(';UPDATE test_table SET val = val + 1; DELETE FROM test_table WHERE val = 3');
$this->scrollToBottom();
$this->byCssSelector("input[value='Go']")->click();
$this->waitAjax();
$this->waitForElement('className', 'alert-success');
$this->expandMore();
$this->byPartialLinkText('Tracking')->click();
$this->waitAjax();
$this->waitForElement('id', 'versions');
}
}
|