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

SqlQueryTest.php « selenium « test - github.com/phpmyadmin/phpmyadmin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 892e95e5f8360da93e5c3bd7cac9723a2f61623a (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
<?php
/**
 * Selenium TestCase for typing and executing SQL query tests
 */

declare(strict_types=1);

namespace PhpMyAdmin\Tests\Selenium;

/**
 * SqlQueryTest class
 *
 * @group      selenium
 */
class SqlQueryTest 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,'
            . ' `val` int(11) NOT NULL,'
            . ' PRIMARY KEY (`id`)'
            . ');'
            . 'INSERT INTO `test_table` (val) VALUES (2), (3), (4), (5);'
        );
        $this->login();
    }

    /**
     * Test typing a SQL query on Server SQL page and submitting it
     */
    public function testServerSqlQuery(): void
    {
        $this->waitForElement('partialLinkText', 'SQL')->click();
        $this->waitAjax();

        $this->typeInTextArea(
            'SET @t1=1, @t2=2, @t3:=4;'
            . 'SELECT 1 as `id`,  @t1, @t2, @t3, @t4 := @t1+@t2+@t3;'
        );
        $this->byId('button_submit_query')->click();
        $this->waitAjax();

        $this->waitForElement('cssSelector', 'table.table_results');
        $this->assertEquals(
            1,
            $this->getCellByTableClass('table_results', 1, 1)
        );
        $this->assertEquals(
            1,
            $this->getCellByTableClass('table_results', 1, 2)
        );
        $this->assertEquals(
            2,
            $this->getCellByTableClass('table_results', 1, 3)
        );
        $this->assertEquals(
            4,
            $this->getCellByTableClass('table_results', 1, 4)
        );
        $this->assertEquals(
            7,
            $this->getCellByTableClass('table_results', 1, 5)
        );

        // test inline edit button
        $this->assertInlineEdit();
    }

    /**
     * Test typing a SQL query on Database SQL page and submitting it
     */
    public function testDatabaseSqlQuery(): void
    {
        $this->navigateDatabase($this->databaseName);

        $this->waitForElement('partialLinkText', 'SQL')->click();
        $this->waitAjax();

        $this->typeInTextArea('SHOW TABLE STATUS');
        $this->byId('button_submit_query')->click();
        $this->waitAjax();

        $this->waitForElement('cssSelector', 'table.table_results');
        $this->assertEquals(
            'test_table',
            $this->getCellByTableClass('table_results', 1, 1)
        );
        $this->assertEquals(
            'InnoDB',
            $this->getCellByTableClass('table_results', 1, 2)
        );
        $this->assertEquals(
            4,
            $this->getCellByTableClass('table_results', 1, 5)
        );

        // test inline edit button
        $this->assertInlineEdit();
    }

    /**
     * Test typing a SQL query on Table SQL page and submitting it
     */
    public function testTableSqlQuery(): void
    {
        $this->navigateTable('test_table');

        $this->waitForElement('partialLinkText', 'SQL')->click();
        $this->waitAjax();

        $this->typeInTextArea('SELECT * FROM `test_table` WHERE `val` NOT IN (2, 3);');
        $this->scrollToBottom();
        $this->byId('button_submit_query')->click();
        $this->waitAjax();

        $this->waitForElement('cssSelector', 'table.table_results');
        $this->assertEquals(
            3,
            $this->getCellByTableClass('table_results', 1, 5)
        );
        $this->assertEquals(
            4,
            $this->getCellByTableClass('table_results', 2, 5)
        );
        $this->assertEquals(
            4,
            $this->getCellByTableClass('table_results', 1, 6)
        );
        $this->assertEquals(
            5,
            $this->getCellByTableClass('table_results', 2, 6)
        );

        // test inline edit button
        $this->assertInlineEdit();
    }

    private function assertInlineEdit(): void
    {
        $this->waitForElement('cssSelector', 'a.inline_edit_sql')->click();
        // empty current query
        $this->typeInTextArea('', 1);

        // type in next sql query
        $this->typeInTextArea('SELECT 1', 1);

        $this->scrollIntoView('sql_query_edit_save');
        $this->byId('sql_query_edit_save')->click();
        $this->waitAjax();

        $this->waitForElement('cssSelector', 'table.table_results');
        $this->assertEquals(
            1,
            $this->getCellByTableClass('table_results', 1, 1)
        );
    }
}