1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace PhpMyAdmin\Tests\Selenium; |
6
|
|
|
|
7
|
|
|
/** @coversNothing */ |
8
|
|
|
class TriggersTest extends TestBase |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* Setup the browser environment to run the selenium test case |
12
|
|
|
*/ |
13
|
|
|
protected function setUp(): void |
14
|
|
|
{ |
15
|
|
|
parent::setUp(); |
16
|
|
|
|
17
|
|
|
$this->dbQuery( |
18
|
|
|
'USE `' . $this->databaseName . '`;' |
19
|
|
|
. 'CREATE TABLE `test_table` (' |
20
|
|
|
. ' `id` int(11) NOT NULL AUTO_INCREMENT,' |
21
|
|
|
. ' `val` int(11) NOT NULL,' |
22
|
|
|
. ' PRIMARY KEY (`id`)' |
23
|
|
|
. ');' |
24
|
|
|
. 'CREATE TABLE `test_table2` (' |
25
|
|
|
. ' `id` int(11) NOT NULL AUTO_INCREMENT,' |
26
|
|
|
. ' `val` int(11) NOT NULL,' |
27
|
|
|
. ' PRIMARY KEY (`id`)' |
28
|
|
|
. ');' |
29
|
|
|
. 'INSERT INTO `test_table2` (val) VALUES (2);', |
30
|
|
|
); |
31
|
|
|
|
32
|
|
|
$this->login(); |
33
|
|
|
|
34
|
|
|
$this->navigateDatabase($this->databaseName); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Creates procedure for tests |
39
|
|
|
*/ |
40
|
|
|
private function triggerSQL(): void |
41
|
|
|
{ |
42
|
|
|
$this->dbQuery( |
43
|
|
|
'USE `' . $this->databaseName . '`;' |
44
|
|
|
. 'CREATE TRIGGER `test_trigger` ' |
45
|
|
|
. 'AFTER INSERT ON `test_table` FOR EACH ROW' |
46
|
|
|
. ' UPDATE `' . $this->databaseName |
47
|
|
|
. '`.`test_table2` SET val = val + 1', |
48
|
|
|
null, |
49
|
|
|
function (): void { |
50
|
|
|
// Do you really want to execute [..] |
51
|
|
|
$this->acceptAlert(); |
52
|
|
|
}, |
53
|
|
|
); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Create a Trigger |
58
|
|
|
* |
59
|
|
|
* @group large |
60
|
|
|
*/ |
61
|
|
|
public function testAddTrigger(): void |
62
|
|
|
{ |
63
|
|
|
$this->expandMore(); |
64
|
|
|
$this->waitForElement('partialLinkText', 'Triggers')->click(); |
65
|
|
|
$this->waitAjax(); |
66
|
|
|
|
67
|
|
|
$this->waitForElement('partialLinkText', 'Create new trigger')->click(); |
68
|
|
|
$this->waitAjax(); |
69
|
|
|
|
70
|
|
|
$this->waitForElement('className', 'rte_form'); |
71
|
|
|
|
72
|
|
|
$this->byName('item_name')->sendKeys('test_trigger'); |
73
|
|
|
|
74
|
|
|
$this->selectByLabel( |
75
|
|
|
$this->byName('item_table'), |
76
|
|
|
'test_table', |
77
|
|
|
); |
78
|
|
|
|
79
|
|
|
$this->selectByLabel( |
80
|
|
|
$this->byName('item_timing'), |
81
|
|
|
'AFTER', |
82
|
|
|
); |
83
|
|
|
|
84
|
|
|
$this->selectByLabel( |
85
|
|
|
$this->byName('item_event'), |
86
|
|
|
'INSERT', |
87
|
|
|
); |
88
|
|
|
|
89
|
|
|
$proc = 'UPDATE ' . $this->databaseName . '.`test_table2` SET val=val+1'; |
90
|
|
|
$this->typeInTextArea($proc); |
91
|
|
|
|
92
|
|
|
$this->byCssSelector('div.ui-dialog-buttonset button:nth-child(1)')->click(); |
93
|
|
|
|
94
|
|
|
$success = $this->waitForElement('cssSelector', '.alert-success'); |
95
|
|
|
$this->assertStringContainsString('Trigger `test_trigger` has been created', $success->getText()); |
96
|
|
|
|
97
|
|
|
$this->assertTrue( |
98
|
|
|
$this->isElementPresent( |
99
|
|
|
'xpath', |
100
|
|
|
"//td[contains(., 'test_trigger')]", |
101
|
|
|
), |
102
|
|
|
); |
103
|
|
|
|
104
|
|
|
$this->dbQuery( |
105
|
|
|
'SHOW TRIGGERS FROM `' . $this->databaseName . '`;', |
106
|
|
|
function (): void { |
107
|
|
|
$this->assertTrue($this->isElementPresent('className', 'table_results')); |
108
|
|
|
$this->assertEquals('test_trigger', $this->getCellByTableClass('table_results', 1, 1)); |
109
|
|
|
}, |
110
|
|
|
); |
111
|
|
|
|
112
|
|
|
// test trigger |
113
|
|
|
$this->dbQuery('USE `' . $this->databaseName . '`;INSERT INTO `test_table` (val) VALUES (1);'); |
114
|
|
|
$this->dbQuery( |
115
|
|
|
'SELECT val FROM `' . $this->databaseName . '`.`test_table2`;', |
116
|
|
|
function (): void { |
117
|
|
|
$this->assertTrue($this->isElementPresent('className', 'table_results')); |
118
|
|
|
// [ ] | Edit | Copy | Delete | 1 | 3 |
119
|
|
|
$this->assertEquals('3', $this->getCellByTableClass('table_results', 1, 5)); |
120
|
|
|
}, |
121
|
|
|
); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Test for editing Triggers |
126
|
|
|
* |
127
|
|
|
* @group large |
128
|
|
|
*/ |
129
|
|
|
public function testEditTriggers(): void |
130
|
|
|
{ |
131
|
|
|
$this->expandMore(); |
132
|
|
|
|
133
|
|
|
$this->triggerSQL(); |
134
|
|
|
$this->waitForElement('partialLinkText', 'Triggers')->click(); |
135
|
|
|
$this->waitAjax(); |
136
|
|
|
|
137
|
|
|
$this->waitForElement('id', 'checkAllCheckbox'); |
138
|
|
|
|
139
|
|
|
$this->byPartialLinkText('Edit')->click(); |
140
|
|
|
|
141
|
|
|
$this->waitForElement('className', 'rte_form'); |
142
|
|
|
$proc = 'UPDATE ' . $this->databaseName . '.`test_table2` SET val=val+10'; |
143
|
|
|
$this->typeInTextArea($proc); |
144
|
|
|
|
145
|
|
|
$this->byCssSelector('div.ui-dialog-buttonset button:nth-child(1)')->click(); |
146
|
|
|
|
147
|
|
|
$success = $this->waitForElement('cssSelector', '.alert-success'); |
148
|
|
|
$this->assertStringContainsString('Trigger `test_trigger` has been modified', $success->getText()); |
149
|
|
|
|
150
|
|
|
// test trigger |
151
|
|
|
$this->dbQuery('USE `' . $this->databaseName . '`;INSERT INTO `test_table` (val) VALUES (1);'); |
152
|
|
|
$this->dbQuery( |
153
|
|
|
'SELECT val FROM `' . $this->databaseName . '`.`test_table2`;', |
154
|
|
|
function (): void { |
155
|
|
|
$this->assertTrue($this->isElementPresent('className', 'table_results')); |
156
|
|
|
// [ ] | Edit | Copy | Delete | 1 | 12 |
157
|
|
|
$this->assertEquals('12', $this->getCellByTableClass('table_results', 1, 5)); |
158
|
|
|
}, |
159
|
|
|
); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* Test for dropping Trigger |
164
|
|
|
* |
165
|
|
|
* @group large |
166
|
|
|
*/ |
167
|
|
|
public function testDropTrigger(): void |
168
|
|
|
{ |
169
|
|
|
$this->expandMore(); |
170
|
|
|
|
171
|
|
|
$this->triggerSQL(); |
172
|
|
|
$ele = $this->waitForElement('partialLinkText', 'Triggers'); |
173
|
|
|
$ele->click(); |
174
|
|
|
|
175
|
|
|
$this->waitForElement('id', 'checkAllCheckbox'); |
176
|
|
|
|
177
|
|
|
$this->byPartialLinkText('Drop')->click(); |
178
|
|
|
$this->waitForElement('id', 'functionConfirmOkButton')->click(); |
179
|
|
|
|
180
|
|
|
$this->waitAjaxMessage(); |
181
|
|
|
|
182
|
|
|
// test trigger |
183
|
|
|
$this->dbQuery('USE `' . $this->databaseName . '`;INSERT INTO `test_table` (val) VALUES (1);'); |
184
|
|
|
$this->dbQuery( |
185
|
|
|
'SELECT val FROM `' . $this->databaseName . '`.`test_table2`;', |
186
|
|
|
function (): void { |
187
|
|
|
$this->assertTrue($this->isElementPresent('className', 'table_results')); |
188
|
|
|
// [ ] | Edit | Copy | Delete | 1 | 2 |
189
|
|
|
$this->assertEquals('2', $this->getCellByTableClass('table_results', 1, 5)); |
190
|
|
|
}, |
191
|
|
|
); |
192
|
|
|
|
193
|
|
|
$this->dbQuery( |
194
|
|
|
'SHOW TRIGGERS FROM `' . $this->databaseName . '`;', |
195
|
|
|
function (): void { |
196
|
|
|
$this->assertFalse($this->isElementPresent('className', 'table_results')); |
197
|
|
|
}, |
198
|
|
|
); |
199
|
|
|
} |
200
|
|
|
} |
201
|
|
|
|