forked from phpmyadmin/phpmyadmin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPmaSeleniumDbProceduresTest.php
211 lines (178 loc) · 5.57 KB
/
PmaSeleniumDbProceduresTest.php
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
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Selenium TestCase for table related tests
*
* @package PhpMyAdmin-test
* @subpackage Selenium
*/
require_once 'TestBase.php';
/**
* PmaSeleniumDbProceduresTest class
*
* @package PhpMyAdmin-test
* @subpackage Selenium
* @group selenium
*/
class PMA_SeleniumDbProceduresTest extends PMA_SeleniumBase
{
/**
* Setup the browser environment to run the selenium test case
*
* @return void
*/
public function setUp()
{
parent::setUp();
$this->dbQuery(
"CREATE TABLE `test_table` ("
. " `id` int(11) NOT NULL AUTO_INCREMENT,"
. " `name` varchar(20) NOT NULL,"
. " `datetimefield` datetime NOT NULL,"
. " PRIMARY KEY (`id`)"
. ")"
);
}
/**
* setUp function that can use the selenium session (called before each test)
*
* @return void
*/
public function setUpPage()
{
parent::setUpPage();
$this->login();
$this->navigateDatabase($this->database_name);
$this->expandMore();
}
/**
* Creates procedure for tests
*
* @return void
*/
private function _procedureSQL()
{
$this->dbQuery(
"CREATE PROCEDURE `test_procedure`(IN `inp` VARCHAR(10), OUT `outp` INT)"
. " NOT DETERMINISTIC READS SQL DATA SQL SECURITY DEFINER SELECT char_"
. "length(inp) + count(*) FROM test_table INTO outp"
);
}
/**
* Create a procedure
*
* @return void
*
* @group large
*/
public function testAddProcedure()
{
$this->waitForElement("byPartialLinkText", "Routines")->click();
$this->waitAjax();
$this->waitForElement("byPartialLinkText", "Add routine")->click();
$this->waitForElement("byClassName", "rte_form");
$this->byName("item_name")->value("test_procedure");
$this->byName("item_param_name[0]")->value("inp");
$this->select(
$this->byName("item_param_type[0]")
)->selectOptionByLabel("VARCHAR");
$this->byName("item_param_length[0]")->value("10");
$this->byCssSelector("input[value='Add parameter']")->click();
$this->select(
$this->byName("item_param_dir[1]")
)->selectOptionByLabel("OUT");
$ele = $this->waitForElement("byName", "item_param_name[1]");
$ele->value("outp");
$proc = "SELECT char_length(inp) + count(*) FROM test_table INTO outp";
$this->typeInTextArea($proc);
$this->select(
$this->byName("item_sqldataaccess")
)->selectOptionByLabel("READS SQL DATA");
$this->byXPath("//button[contains(., 'Go')]")->click();
$ele = $this->waitForElement(
"byXPath",
"//div[@class='success' and contains(., "
. "'Routine `test_procedure` has been created')]"
);
$result = $this->dbQuery(
"SHOW PROCEDURE STATUS WHERE Db='" . $this->database_name . "'"
);
$this->assertEquals(1, $result->num_rows);
$this->_executeProcedure("test_procedure", 10);
}
/**
* Test for editing procedure
*
* @return void
*
* @group large
*/
public function testEditProcedure()
{
$this->_procedureSQL();
$this->waitForElement("byPartialLinkText", "Routines")->click();
$this->waitAjax();
$this->waitForElement(
"byXPath",
"//legend[contains(., 'Routines')]"
);
$this->byPartialLinkText("Edit")->click();
$this->waitForElement("byClassName", "rte_form");
$this->byName("item_param_length[0]")->clear();
$this->byName("item_param_length[0]")->value("12");
$this->byXPath("//button[contains(., 'Go')]")->click();
$ele = $this->waitForElement(
"byXPath",
"//div[@class='success' and contains(., "
. "'Routine `test_procedure` has been modified')]"
);
$this->_executeProcedure("test_procedure", 12);
}
/**
* Test for dropping procedure
*
* @return void
*
* @group large
*/
public function testDropProcedure()
{
$this->_procedureSQL();
$this->waitForElement("byPartialLinkText", "Routines")->click();
$this->waitAjax();
$this->waitForElement(
"byXPath",
"//legend[contains(., 'Routines')]"
);
$this->byPartialLinkText("Drop")->click();
$this->waitForElement(
"byCssSelector", "button.submitOK"
)->click();
$this->waitAjaxMessage();
$result = $this->dbQuery(
"SHOW PROCEDURE STATUS WHERE Db='" . $this->database_name . "'"
);
$this->assertEquals(0, $result->num_rows);
}
/**
* Execute procedure
*
* @param string $text String to pass as inp param
* @param int $length Expected output length
*
* @return void
*/
private function _executeProcedure($text, $length)
{
$this->waitForElement("byPartialLinkText", "Execute")->click();
$this->waitForElement("byName", "params[inp]")->value($text);
$this->byCssSelector("div.ui-dialog-buttonset button:nth-child(1)")->click();
$this->waitAjax();
$this->waitForElement(
"byCssSelector",
"span#PMA_slidingMessage table tbody"
);
$head = $this->byCssSelector("span#PMA_slidingMessage table tbody")->text();
$this->assertEquals("outp\n$length", $head);
}
}