Merge pull request #19552 from kamil-tekiela/Fix-default-values
[phpmyadmin.git] / tests / end-to-end / Table / BrowseTest.php
blobf460dd0f27bbe60e85e5f65e5f7d74e56beefeb9
1 <?php
3 declare(strict_types=1);
5 namespace PhpMyAdmin\Tests\Selenium\Table;
7 use Facebook\WebDriver\WebDriverKeys;
8 use PhpMyAdmin\Tests\Selenium\TestBase;
9 use PHPUnit\Framework\Attributes\CoversNothing;
10 use PHPUnit\Framework\Attributes\Large;
12 #[CoversNothing]
13 #[Large]
14 class BrowseTest extends TestBase
16 /**
17 * Setup the browser environment to run the selenium test case
19 protected function setUp(): void
21 parent::setUp();
23 $this->dbQuery(
24 'USE `' . $this->databaseName . '`;'
25 . 'CREATE TABLE `test_table` ('
26 . ' `id` int(11) NOT NULL AUTO_INCREMENT,'
27 . ' `name` varchar(20) NOT NULL,'
28 . ' `datetimefield` datetime NOT NULL,'
29 . ' PRIMARY KEY (`id`)'
30 . ');'
31 . 'INSERT INTO `test_table` (`id`, `name`, `datetimefield`) VALUES'
32 . " (1, 'abcd', '2011-01-20 02:00:02'),"
33 . " (2, 'foo', '2010-01-20 02:00:02'),"
34 . " (3, 'Abcd', '2012-01-20 02:00:02');",
37 $this->login();
38 $this->navigateTable('test_table');
40 $this->waitAjax();
43 /**
44 * Test sorting of records in browse table
46 public function testSortRecords(): void
48 // case 1
49 $this->byPartialLinkText('name')->click();
50 $this->waitAjax();
52 self::assertSame(
53 '1',
54 $this->getCellByTableClass('table_results', 1, 5),
57 self::assertSame(
58 '3',
59 $this->getCellByTableClass('table_results', 2, 5),
62 self::assertSame(
63 '2',
64 $this->getCellByTableClass('table_results', 3, 5),
67 // case 2
68 $this->byPartialLinkText('name')->click();
69 $this->waitAjax();
71 self::assertSame(
72 '2',
73 $this->getCellByTableClass('table_results', 1, 5),
76 self::assertSame(
77 '1',
78 $this->getCellByTableClass('table_results', 2, 5),
81 self::assertSame(
82 '3',
83 $this->getCellByTableClass('table_results', 3, 5),
86 // case 2
87 $this->byLinkText('datetimefield')->click();
88 $this->waitAjax();
90 $this->getCellByTableClass('table_results', 1, 5);
91 self::assertSame(
92 '3',
93 $this->getCellByTableClass('table_results', 1, 5),
96 self::assertSame(
97 '1',
98 $this->getCellByTableClass('table_results', 2, 5),
101 self::assertSame(
102 '2',
103 $this->getCellByTableClass('table_results', 3, 5),
106 // case 4
107 $this->byPartialLinkText('datetimefield')->click();
108 $this->waitAjax();
110 self::assertSame(
111 '2',
112 $this->getCellByTableClass('table_results', 1, 5),
115 self::assertSame(
116 '1',
117 $this->getCellByTableClass('table_results', 2, 5),
120 self::assertSame(
121 '3',
122 $this->getCellByTableClass('table_results', 3, 5),
127 * Test Edit Record
129 public function testChangeRecords(): void
131 $ele = $this->byCssSelector('table.table_results tbody tr:nth-child(2) td:nth-child(2)');
132 $this->moveto($ele);
133 $this->click();
135 $this->waitForElement('id', 'insertForm');
137 $this->waitAjax();
138 $this->waitForElement('id', 'insertForm');
140 self::assertSame(
141 '2',
142 $this->byId('field_1_3')->getAttribute('value'),
145 self::assertSame(
146 'foo',
147 $this->byId('field_2_3')->getAttribute('value'),
150 self::assertSame(
151 '2010-01-20 02:00:02',
152 $this->byId('field_3_3')->getAttribute('value'),
155 $this->byId('field_3_3')->clear();
156 $this->byId('field_3_3')->sendKeys('2009-01-2');
157 // shorter date to prevent error,
158 // automatically gets appended with 00:00:00
160 $this->byId('field_2_3')->clear();
161 $this->byId('field_2_3')->sendKeys('foobar');
163 $this->byId('buttonYes')->click();
165 $this->waitAjax();
166 $success = $this->waitForElement('className', 'alert-success');
167 self::assertStringContainsString('1 row affected', $success->getText());
169 self::assertSame(
170 'foobar',
171 $this->getCellByTableClass('table_results', 2, 6),
174 self::assertSame(
175 '2009-01-02 00:00:00',
176 $this->getCellByTableClass('table_results', 2, 7),
181 * Test edit record by double click
183 public function testChangeRecordsByDoubleClick(): void
185 $element = $this->byCssSelector('table.table_results tbody tr:nth-child(1) td:nth-child(6)');
187 $this->moveto($element);
188 $this->doubleclick();
190 self::assertSame(
191 $this->waitForElement(
192 'xpath',
193 "//div[not(contains(@style,'display: none;'))]//textarea[contains(@class, 'edit_box')]",
194 )->getAttribute('value'),
195 'abcd',
198 $this->byCssSelector('textarea.edit_box')->clear();
199 $this->byCssSelector('textarea.edit_box')->sendKeys('abcde');
201 $this->keys(WebDriverKeys::RETURN_KEY);
203 $this->waitAjax();
204 $success = $this->waitForElement('cssSelector', 'span.ajax_notification .alert-success');
205 self::assertStringContainsString('1 row affected', $success->getText());
207 self::assertSame(
208 'abcde',
209 $this->getCellByTableClass('table_results', 1, 6),
214 * Test copy and insert record
216 public function testCopyRecords(): void
218 $ele = $this->byCssSelector('table.table_results tbody tr:nth-child(3) td:nth-child(3)');
219 $this->moveto($ele);
220 $this->click();
221 $this->waitForElement('id', 'insertForm');
223 self::assertSame(
224 'Abcd',
225 $this->byId('field_2_3')->getAttribute('value'),
228 self::assertSame(
229 '2012-01-20 02:00:02',
230 $this->byId('field_3_3')->getAttribute('value'),
233 $this->byId('field_2_3')->clear();
234 $this->byId('field_2_3')->sendKeys('ABCDEFG');
236 $this->byId('field_3_3')->clear();
237 $this->byId('field_3_3')->sendKeys('2012-01-02');
239 $this->waitForElement('id', 'buttonYes')->click();
241 $this->waitAjax();
242 $success = $this->waitForElement('className', 'alert-success');
243 self::assertStringContainsString('1 row inserted', $success->getText());
245 self::assertSame(
246 'ABCDEFG',
247 $this->getCellByTableClass('table_results', 4, 6),
250 self::assertSame(
251 '2012-01-02 00:00:00',
252 $this->getCellByTableClass('table_results', 4, 7),
257 * Test search table
259 public function testSearchRecords(): void
261 $this->expandMore();
263 $this->byPartialLinkText('Search')->click();
264 $this->waitForElement('id', 'tbl_search_form');
266 $this->byId('fieldID_1')->sendKeys('abcd');
267 $this->selectByLabel(
268 $this->byName('criteriaColumnOperators[1]'),
269 'LIKE %...%',
272 $this->scrollToBottom();
273 $elem = $this->waitForElement('cssSelector', '.card-footer input[name=submit]');
274 $this->moveto($elem);
275 $elem->click();
277 $this->waitAjax();
278 $success = $this->waitForElement('className', 'alert-success');
279 self::assertStringContainsString('Showing rows', $success->getText());
281 self::assertSame(
282 '1',
283 $this->getCellByTableClass('table_results', 1, 5),
286 self::assertSame(
287 '3',
288 $this->getCellByTableClass('table_results', 2, 5),
293 * Test delete multiple records
295 public function testDeleteRecords(): void
297 $this->byId('id_rows_to_delete1_left')->click();
298 $this->byId('id_rows_to_delete2_left')->click();
300 $this->byCssSelector('button[value=delete]')->click();
302 $this->waitForElement('id', 'buttonYes')->click();
304 $this->waitAjax();
306 $success = $this->waitForElement(
307 'cssSelector',
308 '.sqlqueryresults > .result_query:nth-child(1) > .alert-success',
310 self::assertStringContainsString('Your SQL query has been executed successfully.', $success->getText());
311 $success = $this->waitForElement(
312 'cssSelector',
313 '.sqlqueryresults > .result_query:nth-child(2) > .alert-success',
315 self::assertStringContainsString('Showing rows', $success->getText());
317 self::assertFalse(
318 $this->isElementPresent(
319 'cssSelector',
320 'table.table_results tbody tr:nth-child(2)',