Merge pull request #19552 from kamil-tekiela/Fix-default-values
[phpmyadmin.git] / tests / end-to-end / Table / CreateTest.php
blob38db82ce81527ed82ef5f659ccb2833f3e1350a5
1 <?php
3 declare(strict_types=1);
5 namespace PhpMyAdmin\Tests\Selenium\Table;
7 use PhpMyAdmin\Tests\Selenium\TestBase;
8 use PHPUnit\Framework\Attributes\CoversNothing;
9 use PHPUnit\Framework\Attributes\Large;
11 use function sleep;
13 #[CoversNothing]
14 #[Large]
15 class CreateTest extends TestBase
17 protected function setUp(): void
19 parent::setUp();
21 $this->login();
22 $this->navigateDatabase($this->databaseName);
25 /**
26 * Creates a table
28 public function testCreateTable(): void
30 $this->waitAjax();
31 $this->waitAjax();
33 $this->waitForElement('id', 'createTableMinimalForm');
34 $this->byId('createTableNameInput')->sendKeys('test_table');
35 $numFieldsInput = $this->byId('createTableNumFieldsInput');
36 $numFieldsInput->clear();
37 $numFieldsInput->sendKeys('4');
38 $this->byCssSelector('#createTableMinimalForm input[value=Create]')->click();
40 $this->waitAjax();
41 $this->waitForElement('name', 'do_save_data');
43 $this->waitForElement('id', 'field_1_7')->click(); // null
44 $this->waitForElement('id', 'field_0_9')->click(); // auto increment
46 // column details
47 $columnTextDetails = [
48 'field_0_1' => 'test_id',
49 'field_0_3' => '14',
50 'field_0_10' => 'comm1',
51 'field_1_1' => 'test_column',
52 'field_1_3' => '10',
53 'field_1_10' => 'comm2',
56 foreach ($columnTextDetails as $field => $val) {
57 $this->byId($field)->sendKeys($val);
60 $columnDropdownDetails = [
61 'field_0_6' => 'UNSIGNED',
62 'field_1_2' => 'VARCHAR',
63 'field_1_5' => 'utf8mb4_general_ci',
64 'field_1_4' => 'As defined:',
67 foreach ($columnDropdownDetails as $selector => $value) {
68 $this->waitForElement(
69 'xpath',
70 '//select[@id=\'' . $selector . '\']//option[contains(text(), \'' . $value . '\')]',
71 )->click();
74 $this->byName('field_default_value[1]')->sendKeys('def');
76 $this->scrollToBottom();
77 $ele = $this->waitForElement('name', 'do_save_data');
78 $this->moveto($ele);
79 // post
80 $ele->click();
81 $this->waitForElement('cssSelector', 'li.last.nav_node_table');
83 $this->waitAjax();
85 $this->waitForElement('partialLinkText', 'test_table');
86 sleep(1);
87 $this->tableStructureAssertions();
90 /**
91 * Make assertions for table structure
93 private function tableStructureAssertions(): void
95 $this->navigateTable('test_table', true);
97 $this->waitAjax();
99 // go to structure page
100 $this->waitForElement('partialLinkText', 'Structure')->click();
102 $this->waitForElement('id', 'tablestructure');
103 $this->waitForElement('id', 'table_structure_id');
105 // make assertions for first row
106 self::assertStringContainsString(
107 'test_id',
108 $this->byCssSelector('label[for=checkbox_row_1]')->getText(),
111 self::assertSame(
112 'int(14)',
113 $this->getCellByTableId('tablestructure', 1, 4),
116 self::assertSame(
117 'UNSIGNED',
118 $this->getCellByTableId('tablestructure', 1, 6),
121 self::assertSame(
122 'No',
123 $this->getCellByTableId('tablestructure', 1, 7),
126 self::assertSame(
127 'None',
128 $this->getCellByTableId('tablestructure', 1, 8),
130 self::assertSame(
131 'comm1',
132 $this->getCellByTableId('tablestructure', 1, 9),
135 self::assertSame(
136 'AUTO_INCREMENT',
137 $this->getCellByTableId('tablestructure', 1, 10),
140 self::assertFalse($this->isElementPresent(
141 'cssSelector',
142 'table#tablestructure tbody tr:nth-child(1) ul li.primary a',
145 // make assertions for second row
146 self::assertStringContainsString(
147 'test_column',
148 $this->byCssSelector('label[for=checkbox_row_2]')->getText(),
151 self::assertSame(
152 'varchar(10)',
153 $this->getCellByTableId('tablestructure', 2, 4),
156 self::assertSame(
157 'utf8mb4_general_ci',
158 $this->getCellByTableId('tablestructure', 2, 5),
161 self::assertSame(
162 'Yes',
163 $this->getCellByTableId('tablestructure', 2, 7),
166 self::assertSame(
167 'def',
168 $this->getCellByTableId('tablestructure', 2, 8),
171 self::assertTrue($this->isElementPresent(
172 'cssSelector',
173 'table#tablestructure tbody tr:nth-child(2) ul li.primary a',