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 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
|
<?php
declare(strict_types=1);
namespace PhpMyAdmin\Tests\Selenium\Table;
use Facebook\WebDriver\WebDriverKeys;
use PhpMyAdmin\Tests\Selenium\TestBase;
/**
* @coversNothing
*/
#[\PHPUnit\Framework\Attributes\CoversNothing]
class BrowseTest 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,'
. ' `name` varchar(20) NOT NULL,'
. ' `datetimefield` datetime NOT NULL,'
. ' PRIMARY KEY (`id`)'
. ');'
. 'INSERT INTO `test_table` (`id`, `name`, `datetimefield`) VALUES'
. " (1, 'abcd', '2011-01-20 02:00:02'),"
. " (2, 'foo', '2010-01-20 02:00:02'),"
. " (3, 'Abcd', '2012-01-20 02:00:02');"
);
$this->login();
$this->navigateTable('test_table');
$this->waitAjax();
}
/**
* Test sorting of records in browse table
*
* @group large
*/
#[\PHPUnit\Framework\Attributes\Group('large-group')]
public function testSortRecords(): void
{
// case 1
$this->byPartialLinkText('name')->click();
$this->waitAjax();
self::assertEquals('1', $this->getCellByTableClass('table_results', 1, 5));
self::assertEquals('3', $this->getCellByTableClass('table_results', 2, 5));
self::assertEquals('2', $this->getCellByTableClass('table_results', 3, 5));
// case 2
$this->byPartialLinkText('name')->click();
$this->waitAjax();
self::assertEquals('2', $this->getCellByTableClass('table_results', 1, 5));
self::assertEquals('1', $this->getCellByTableClass('table_results', 2, 5));
self::assertEquals('3', $this->getCellByTableClass('table_results', 3, 5));
// case 2
$this->byLinkText('datetimefield')->click();
$this->waitAjax();
$this->getCellByTableClass('table_results', 1, 5);
self::assertEquals('3', $this->getCellByTableClass('table_results', 1, 5));
self::assertEquals('1', $this->getCellByTableClass('table_results', 2, 5));
self::assertEquals('2', $this->getCellByTableClass('table_results', 3, 5));
// case 4
$this->byPartialLinkText('datetimefield')->click();
$this->waitAjax();
self::assertEquals('2', $this->getCellByTableClass('table_results', 1, 5));
self::assertEquals('1', $this->getCellByTableClass('table_results', 2, 5));
self::assertEquals('3', $this->getCellByTableClass('table_results', 3, 5));
}
/**
* Test Edit Record
*
* @group large
*/
#[\PHPUnit\Framework\Attributes\Group('large-group')]
public function testChangeRecords(): void
{
$ele = $this->byCssSelector('table.table_results tbody tr:nth-child(2) td:nth-child(2)');
$this->moveto($ele);
$this->click();
$this->waitForElement('id', 'insertForm');
$this->waitAjax();
$this->waitForElement('id', 'insertForm');
self::assertEquals('2', $this->byId('field_1_3')->getAttribute('value'));
self::assertEquals('foo', $this->byId('field_2_3')->getAttribute('value'));
self::assertEquals('2010-01-20 02:00:02', $this->byId('field_3_3')->getAttribute('value'));
$this->byId('field_3_3')->clear();
$this->byId('field_3_3')->sendKeys('2009-01-2');
// shorter date to prevent error,
// automatically gets appended with 00:00:00
$this->byId('field_2_3')->clear();
$this->byId('field_2_3')->sendKeys('foobar');
$this->byId('buttonYes')->click();
$this->waitAjax();
$success = $this->waitForElement('className', 'alert-success');
self::assertStringContainsString('1 row affected', $success->getText());
self::assertEquals('foobar', $this->getCellByTableClass('table_results', 2, 6));
self::assertEquals('2009-01-02 00:00:00', $this->getCellByTableClass('table_results', 2, 7));
}
/**
* Test edit record by double click
*
* @group large
*/
#[\PHPUnit\Framework\Attributes\Group('large-group')]
public function testChangeRecordsByDoubleClick(): void
{
$element = $this->byCssSelector('table.table_results tbody tr:nth-child(1) td:nth-child(6)');
$this->moveto($element);
$this->doubleclick();
self::assertEquals($this->waitForElement(
'xpath',
"//div[not(contains(@style,'display: none;'))]//textarea[contains(@class, 'edit_box')]"
)->getAttribute('value'), 'abcd');
$this->byCssSelector('textarea.edit_box')->clear();
$this->byCssSelector('textarea.edit_box')->sendKeys('abcde');
$this->keys(WebDriverKeys::RETURN_KEY);
$this->waitAjax();
$success = $this->waitForElement('cssSelector', 'span.ajax_notification .alert-success');
self::assertStringContainsString('1 row affected', $success->getText());
self::assertEquals('abcde', $this->getCellByTableClass('table_results', 1, 6));
}
/**
* Test copy and insert record
*
* @group large
*/
#[\PHPUnit\Framework\Attributes\Group('large-group')]
public function testCopyRecords(): void
{
$ele = $this->byCssSelector('table.table_results tbody tr:nth-child(3) td:nth-child(3)');
$this->moveto($ele);
$this->click();
$this->waitForElement('id', 'insertForm');
self::assertEquals('Abcd', $this->byId('field_2_3')->getAttribute('value'));
self::assertEquals('2012-01-20 02:00:02', $this->byId('field_3_3')->getAttribute('value'));
$this->byId('field_2_3')->clear();
$this->byId('field_2_3')->sendKeys('ABCDEFG');
$this->byId('field_3_3')->clear();
$this->byId('field_3_3')->sendKeys('2012-01-02');
$this->waitForElement('id', 'buttonYes')->click();
$this->waitAjax();
$success = $this->waitForElement('className', 'alert-success');
self::assertStringContainsString('1 row inserted', $success->getText());
self::assertEquals('ABCDEFG', $this->getCellByTableClass('table_results', 4, 6));
self::assertEquals('2012-01-02 00:00:00', $this->getCellByTableClass('table_results', 4, 7));
}
/**
* Test search table
*
* @group large
*/
#[\PHPUnit\Framework\Attributes\Group('large-group')]
public function testSearchRecords(): void
{
$this->expandMore();
$this->byPartialLinkText('Search')->click();
$this->waitForElement('id', 'tbl_search_form');
$this->byId('fieldID_1')->sendKeys('abcd');
$this->selectByLabel(
$this->byName('criteriaColumnOperators[1]'),
'LIKE %...%'
);
$this->scrollToBottom();
$elem = $this->waitForElement('cssSelector', '.card-footer input[name=submit]');
$this->moveto($elem);
$elem->click();
$this->waitAjax();
$success = $this->waitForElement('className', 'alert-success');
self::assertStringContainsString('Showing rows', $success->getText());
self::assertEquals('1', $this->getCellByTableClass('table_results', 1, 5));
self::assertEquals('3', $this->getCellByTableClass('table_results', 2, 5));
}
/**
* Test delete multiple records
*
* @group large
*/
#[\PHPUnit\Framework\Attributes\Group('large-group')]
public function testDeleteRecords(): void
{
$this->byId('id_rows_to_delete1_left')->click();
$this->byId('id_rows_to_delete2_left')->click();
$this->byCssSelector('button[value=delete]')->click();
$this->waitForElement('cssSelector', 'fieldset.confirmation');
$this->byId('buttonYes')->click();
$this->waitAjax();
$success = $this->waitForElement('className', 'alert-success');
self::assertStringContainsString('Showing rows', $success->getText());
self::assertFalse($this->isElementPresent(
'cssSelector',
'table.table_results tbody tr:nth-child(2)'
));
}
}
|