Welcome to mirror list, hosted at ThFree Co, Russian Federation.

OperationsTest.php « Table « selenium « test - github.com/phpmyadmin/phpmyadmin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 57750af91d2c714aea0554fc552b444d9f0ab39b (plain)
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
<?php

declare(strict_types=1);

namespace PhpMyAdmin\Tests\Selenium\Table;

use PhpMyAdmin\Tests\Selenium\TestBase;

use function sleep;

/**
 * @coversNothing
 */
class OperationsTest extends TestBase
{
    /**
     * Setup the browser environment to run the selenium test case
     */
    protected function setUp(): void
    {
        parent::setUp();

        // MYISAM ENGINE to allow for column-based order selection
        // while table also has a PRIMARY key
        $this->dbQuery(
            'USE `' . $this->databaseName . '`;'
            . 'CREATE TABLE `test_table` ('
            . ' `id` int(11) NOT NULL AUTO_INCREMENT,'
            . ' `val` int(11) NOT NULL,'
            . ' `val2` int(11) NOT NULL,'
            . ' PRIMARY KEY (`id`)'
            . ') ENGINE=MYISAM;'
            . 'INSERT INTO test_table (val, val2) VALUES (22, 33);'
            . 'INSERT INTO test_table (val, val2) VALUES (33, 44);'
        );

        $this->login();
        $this->navigateTable('test_table');

        $this->waitAjax();

        $this->expandMore();
        $this->byXPath("//a[contains(., 'Operations')]")->click();

        $this->waitAjax();
        $this->waitForElement('xpath', "//div[contains(., 'Table maintenance')]");
        $this->reloadPage();
        $this->waitForElement('xpath', "//div[contains(., 'Table maintenance')]");
    }

    /**
     * Test for changing a table order
     *
     * @group large
     */
    public function testChangeTableOrder(): void
    {
        $this->selectByLabel(
            $this->byName('order_field'),
            'val'
        );

        $this->byId('tableOrderDescRadio')->click();
        $this->byCssSelector("form#alterTableOrderby input[type='submit']")->click();

        $this->waitAjax();

        $this->waitForElement(
            'xpath',
            "//div[@class='alert alert-success' and "
            . "contains(., 'Your SQL query has been executed successfully')]"
        );

        $this->byPartialLinkText('Browse')->click();

        $this->waitAjax();
        $this->waitForElement('cssSelector', 'table.table_results');

        $this->assertEquals(
            '2',
            $this->getCellByTableClass('table_results', 1, 5)
        );
    }

    /**
     * Test for moving a table
     *
     * @group large
     */
    public function testMoveTable(): void
    {
        $this->byCssSelector("form#moveTableForm input[name='new_name']")
            ->sendKeys('2');

        $this->byCssSelector("form#moveTableForm input[type='submit']")->click();
        $this->waitAjax();

        $this->waitForElement(
            'xpath',
            "//div[@class='alert alert-success' and "
            . "contains(., 'Table `" . $this->databaseName
            . '`.`test_table` has been '
            . 'moved to `' . $this->databaseName . "`.`test_table2`.')]"
        );

        $this->dbQuery(
            'USE `' . $this->databaseName . '`;'
            . 'SHOW TABLES LIKE \'test_table2\'',
            function (): void {
                $this->assertTrue($this->isElementPresent('className', 'table_results'));
                $this->assertEquals('test_table2', $this->getCellByTableClass('table_results', 1, 1));
            }
        );
    }

    /**
     * Test for renaming a table
     *
     * @group large
     */
    public function testRenameTable(): void
    {
        $this->byCssSelector("form#tableOptionsForm input[name='new_name']")
            ->sendKeys('2');

        $this->byName('comment')->sendKeys('foobar');

        $this->scrollIntoView('tableOptionsForm');
        sleep(1);
        $this->scrollIntoView('tableOptionsForm');
        $this->waitUntilElementIsVisible('cssSelector', 'form#tableOptionsForm', 30);
        $this->byCssSelector("form#tableOptionsForm input[type='submit']")->click();
        $this->waitAjax();

        $this->waitForElement(
            'xpath',
            "//div[@class='alert alert-success' and "
            . "contains(., 'Table test_table has been renamed to test_table2')]"
        );

        $this->dbQuery(
            'USE `' . $this->databaseName . '`;'
            . 'SHOW TABLES LIKE \'test_table2\'',
            function (): void {
                $this->assertTrue($this->isElementPresent('className', 'table_results'));
                $this->assertEquals('test_table2', $this->getCellByTableClass('table_results', 1, 1));
            }
        );
    }

    /**
     * Test for copying a table
     *
     * @group large
     */
    public function testCopyTable(): void
    {
        $this->scrollIntoView('copyTable');
        sleep(1);
        $this->scrollIntoView('copyTable');
        $this->waitUntilElementIsVisible('cssSelector', 'form#copyTable', 30);
        $this->byCssSelector("form#copyTable input[name='new_name']")->sendKeys('2');
        $this->byCssSelector('label[for="whatRadio2"]')->click();
        $this->byCssSelector("form#copyTable input[type='submit']")->click();
        $this->waitAjax();

        $this->waitForElement(
            'xpath',
            "//div[@class='alert alert-success' and "
            . "contains(., 'Table `" . $this->databaseName
            . '`.`test_table` has been '
            . 'copied to `' . $this->databaseName . "`.`test_table2`.')]"
        );

        $this->dbQuery(
            'SELECT COUNT(*) as c FROM `' . $this->databaseName . '`.test_table2',
            function (): void {
                $this->assertTrue($this->isElementPresent('className', 'table_results'));
                $this->assertEquals('2', $this->getCellByTableClass('table_results', 1, 1));
            }
        );
    }

    /**
     * Test for truncating a table
     *
     * @group large
     */
    public function testTruncateTable(): void
    {
        $this->scrollToBottom();
        sleep(1);
        $this->scrollToBottom();
        $this->waitUntilElementIsVisible('id', 'drop_tbl_anchor', 30);
        $this->byId('truncate_tbl_anchor')->click();
        $this->byCssSelector('button.submitOK')->click();
        $this->waitAjax();

        $this->waitForElement(
            'xpath',
            "//div[@class='alert alert-success' and "
            . "contains(., 'MySQL returned an empty result set')]"
        );

        $this->dbQuery(
            'SELECT CONCAT("Count: ", COUNT(*)) as c FROM `' . $this->databaseName . '`.test_table',
            function (): void {
                $this->assertTrue($this->isElementPresent('className', 'table_results'));
                $this->assertEquals('Count: 0', $this->getCellByTableClass('table_results', 1, 1));
            }
        );
    }

    /**
     * Test for dropping a table
     *
     * @group large
     */
    public function testDropTable(): void
    {
        $dropLink = $this->waitUntilElementIsVisible('partialLinkText', 'Delete the table (DROP)', 30);
        $this->scrollToBottom();
        sleep(1);
        $this->scrollToBottom();
        $dropLink->click();
        $this->byCssSelector('button.submitOK')->click();
        $this->waitAjax();

        $this->waitForElement(
            'xpath',
            "//div[@class='alert alert-success' and "
            . "contains(., 'MySQL returned an empty result set')]"
        );

        $this->waitForElement('xpath', "//a[@class='nav-link text-nowrap' and contains(., 'Structure')]");

        $this->dbQuery(
            'USE `' . $this->databaseName . '`;'
            . 'SHOW TABLES',
            function (): void {
                $this->assertFalse($this->isElementPresent('className', 'table_results'));
            }
        );
    }
}