3 * Selenium TestCase for typing and executing SQL query tests
5 declare(strict_types
=1);
7 namespace PhpMyAdmin\Tests\Selenium
;
14 class SqlQueryTest
extends TestBase
17 * Setup the browser environment to run the selenium test case
19 protected function setUp(): void
24 'CREATE TABLE `test_table` ('
25 . ' `id` int(11) NOT NULL AUTO_INCREMENT,'
26 . ' `val` int(11) NOT NULL,'
27 . ' PRIMARY KEY (`id`)'
31 'INSERT INTO `test_table` (val) VALUES (2), (3), (4), (5);'
37 * Test typing a SQL query on Server SQL page and submitting it
41 public function testServerSqlQuery()
43 $this->waitForElement('partialLinkText', 'SQL')->click();
46 $this->typeInTextArea(
47 'SET @t1=1, @t2=2, @t3:=4;'
48 . 'SELECT 1 as `id`, @t1, @t2, @t3, @t4 := @t1+@t2+@t3;'
50 $this->byId('button_submit_query')->click();
53 $this->waitForElement('cssSelector', 'table.table_results');
56 $this->getCellByTableClass('table_results', 1, 1)
60 $this->getCellByTableClass('table_results', 1, 2)
64 $this->getCellByTableClass('table_results', 1, 3)
68 $this->getCellByTableClass('table_results', 1, 4)
72 $this->getCellByTableClass('table_results', 1, 5)
75 // test inline edit button
76 $this->_testInlineEdit();
80 * Test typing a SQL query on Database SQL page and submitting it
84 public function testDatabaseSqlQuery()
86 $this->navigateDatabase($this->database_name
);
88 $this->waitForElement('partialLinkText', 'SQL')->click();
91 $this->typeInTextArea('SHOW TABLE STATUS');
92 $this->byId('button_submit_query')->click();
95 $this->waitForElement('cssSelector', 'table.table_results');
98 $this->getCellByTableClass('table_results', 1, 1)
102 $this->getCellByTableClass('table_results', 1, 2)
106 $this->getCellByTableClass('table_results', 1, 5)
109 // test inline edit button
110 $this->_testInlineEdit();
114 * Test typing a SQL query on Table SQL page and submitting it
118 public function testTableSqlQuery()
120 $this->navigateTable('test_table');
122 $this->waitForElement('partialLinkText', 'SQL')->click();
125 $this->typeInTextArea('SELECT * FROM `test_table` WHERE `val` NOT IN (2, 3);');
126 $this->scrollToBottom();
127 $this->byId('button_submit_query')->click();
130 $this->waitForElement('cssSelector', 'table.table_results');
133 $this->getCellByTableClass('table_results', 1, 5)
137 $this->getCellByTableClass('table_results', 2, 5)
141 $this->getCellByTableClass('table_results', 1, 6)
145 $this->getCellByTableClass('table_results', 2, 6)
148 // test inline edit button
149 $this->_testInlineEdit();
155 private function _testInlineEdit()
157 $this->waitForElement('cssSelector', 'a.inline_edit_sql')->click();
158 // empty current query
159 $this->typeInTextArea('', 1);
161 // type in next sql query
162 $this->typeInTextArea('SELECT 1', 1);
164 $this->scrollIntoView('sql_query_edit_save');
165 $this->byId('sql_query_edit_save')->click();
168 $this->waitForElement('cssSelector', 'table.table_results');
171 $this->getCellByTableClass('table_results', 1, 1)