|
1
|
|
|
<?php
|
|
2
|
|
|
/**
|
|
3
|
|
|
* Function area : Database.
|
|
4
|
|
|
* Sub Function area : Sql.
|
|
5
|
|
|
*
|
|
6
|
|
|
* @author Augmentum SpikeSource Team
|
|
7
|
|
|
* @copyright Copyright (c) 2005 by Augmentum, Inc.
|
|
8
|
|
|
*/
|
|
9
|
|
|
|
|
10
|
|
|
// Import the precondition class.
|
|
11
|
|
|
if (is_dir('../Public')) {
|
|
12
|
|
|
require_once('../Public/SetPrecondition.php');
|
|
13
|
|
|
}
|
|
14
|
|
|
|
|
15
|
|
|
/**
|
|
16
|
|
|
* This class is to test the Sql implementation.
|
|
17
|
|
|
*/
|
|
18
|
|
|
class SqlTest extends PreconditionSet
|
|
19
|
|
|
{
|
|
20
|
|
|
/**
|
|
21
|
|
|
* Set up the preconditon.
|
|
22
|
|
|
*/
|
|
23
|
|
|
function setUp()
|
|
24
|
|
|
{
|
|
25
|
|
|
global $webUrl;
|
|
26
|
|
|
global $SUPER_USER_NAME;
|
|
27
|
|
|
global $SUPER_USER_PASSWORD;
|
|
28
|
|
|
|
|
29
|
|
|
$this->login($SUPER_USER_NAME, $SUPER_USER_PASSWORD,
|
|
30
|
|
|
"$webUrl/login.php");
|
|
31
|
|
|
|
|
32
|
|
|
return TRUE;
|
|
33
|
|
|
}
|
|
34
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
/**
|
|
37
|
|
|
* Release the relational resource.
|
|
38
|
|
|
*/
|
|
39
|
|
|
function tearDown()
|
|
40
|
|
|
{
|
|
41
|
|
|
// Logout this system.
|
|
42
|
|
|
$this->logout();
|
|
43
|
|
|
|
|
44
|
|
|
return TRUE;
|
|
45
|
|
|
}
|
|
46
|
|
|
|
|
47
|
|
|
|
|
48
|
|
|
/**
|
|
49
|
|
|
* TestCaseId: DES001
|
|
50
|
|
|
* This test is used to send the "select" sql script to phpPgAdmin for
|
|
51
|
|
|
* implementation.
|
|
52
|
|
|
*/
|
|
53
|
|
|
function testSimpleSelectSql()
|
|
54
|
|
|
{
|
|
55
|
|
|
global $webUrl;
|
|
56
|
|
|
global $lang, $SERVER, $DATABASE;
|
|
57
|
|
|
|
|
58
|
|
|
$this->assertTrue($this->get("$webUrl/database.php",
|
|
59
|
|
|
array('database' => $DATABASE,
|
|
60
|
|
|
'subject' => 'database',
|
|
61
|
|
|
'action' => 'sql',
|
|
62
|
|
|
'server' => $SERVER))
|
|
63
|
|
|
);
|
|
64
|
|
|
$this->assertTrue($this->setFieldById(0, "select id from student;"));
|
|
65
|
|
|
|
|
66
|
|
|
$this->assertTrue($this->clickSubmit($lang['strexecute']));
|
|
67
|
|
|
|
|
68
|
|
|
return TRUE;
|
|
69
|
|
|
}
|
|
70
|
|
|
|
|
71
|
|
|
|
|
72
|
|
|
/**
|
|
73
|
|
|
* TestCaseId: DES003
|
|
74
|
|
|
* This test is used to send the "delete" sql script to phpPgAdmin for
|
|
75
|
|
|
* implementation.
|
|
76
|
|
|
*/
|
|
77
|
|
|
function testSimpleDeleteSql()
|
|
78
|
|
|
{
|
|
79
|
|
|
global $webUrl;
|
|
80
|
|
|
global $lang, $SERVER, $DATABASE;
|
|
81
|
|
|
|
|
82
|
|
|
$this->assertTrue($this->get("$webUrl/database.php", array(
|
|
83
|
|
|
'server' => $SERVER,
|
|
84
|
|
|
'database' => $DATABASE,
|
|
85
|
|
|
'subject' => 'database',
|
|
86
|
|
|
'action' => 'sql'))
|
|
87
|
|
|
);
|
|
88
|
|
|
$this->assertTrue($this->setField('query', 'delete from "student";'));
|
|
89
|
|
|
|
|
90
|
|
|
$this->assertTrue($this->clickSubmit($lang['strexecute']));
|
|
91
|
|
|
|
|
92
|
|
|
return TRUE;
|
|
93
|
|
|
}
|
|
94
|
|
|
|
|
95
|
|
|
|
|
96
|
|
|
/**
|
|
97
|
|
|
* TestCaseId: DES002
|
|
98
|
|
|
* This test is used to send the "insert" sql script to phpPgAdmin for implement.
|
|
99
|
|
|
*/
|
|
100
|
|
|
function testSimpleInsertSql()
|
|
101
|
|
|
{
|
|
102
|
|
|
global $webUrl;
|
|
103
|
|
|
global $lang, $SERVER, $DATABASE;
|
|
104
|
|
|
|
|
105
|
|
|
$this->assertTrue($this->get("$webUrl/database.php", array(
|
|
106
|
|
|
'server' => $SERVER,
|
|
107
|
|
|
'database' => $DATABASE,
|
|
108
|
|
|
'subject' => 'database',
|
|
109
|
|
|
'action' => 'sql'))
|
|
110
|
|
|
);
|
|
111
|
|
|
$this->assertTrue($this->setField('query',
|
|
112
|
|
|
"insert into studen t values " .
|
|
113
|
|
|
"(nextval('public.student_id_seq'::text)" .
|
|
114
|
|
|
", 'test2', now(), 'test2 is a student.');"));
|
|
115
|
|
|
|
|
116
|
|
|
$this->assertTrue($this->clickSubmit($lang['strexecute']));
|
|
117
|
|
|
|
|
118
|
|
|
return true;
|
|
119
|
|
|
}
|
|
120
|
|
|
|
|
121
|
|
|
|
|
122
|
|
|
/**
|
|
123
|
|
|
* TestCaseId: DES004
|
|
124
|
|
|
* This test is used to send the "update" sql script to phpPgAdmin
|
|
125
|
|
|
* for implementation.
|
|
126
|
|
|
*/
|
|
127
|
|
|
function testSimpleUpdateSql()
|
|
128
|
|
|
{
|
|
129
|
|
|
global $webUrl;
|
|
130
|
|
|
global $lang, $SERVER, $DATABASE;
|
|
131
|
|
|
|
|
132
|
|
|
$this->assertTrue($this->get("$webUrl/database.php", array(
|
|
133
|
|
|
'database' => $DATABASE,
|
|
134
|
|
|
'server' => $SERVER,
|
|
135
|
|
|
'subject' => 'database',
|
|
136
|
|
|
'action' => 'sql'))
|
|
137
|
|
|
);
|
|
138
|
|
|
$this->assertTrue($this->setField('query',
|
|
139
|
|
|
'update public."student" ' .
|
|
140
|
|
|
'set "birthday" = now();'));
|
|
141
|
|
|
|
|
142
|
|
|
$this->assertTrue($this->clickSubmit($lang['strexecute']));
|
|
143
|
|
|
|
|
144
|
|
|
return TRUE;
|
|
145
|
|
|
}
|
|
146
|
|
|
|
|
147
|
|
|
|
|
148
|
|
|
/**
|
|
149
|
|
|
* TestCaseId: DES005
|
|
150
|
|
|
* This test is used to send the "select"" sql script to PostgreSQL
|
|
151
|
|
|
* for implementation about "Explain".
|
|
152
|
|
|
*/
|
|
153
|
|
|
function testExplain()
|
|
154
|
|
|
{
|
|
155
|
|
|
global $webUrl;
|
|
156
|
|
|
global $lang, $SERVER, $DATABASE;
|
|
157
|
|
|
|
|
158
|
|
|
$this->assertTrue($this->get("$webUrl/database.php", array(
|
|
159
|
|
|
'server' => $SERVER,
|
|
160
|
|
|
'database' => $DATABASE,
|
|
161
|
|
|
'subject' => 'database',
|
|
162
|
|
|
'action' => 'sql'))
|
|
163
|
|
|
);
|
|
164
|
|
|
|
|
165
|
|
|
$this->assertTrue($this->setField('query',
|
|
166
|
|
|
'select "id" from "student";'));
|
|
167
|
|
|
|
|
168
|
|
|
$this->assertTrue($this->setField('paginate', TRUE));
|
|
169
|
|
|
|
|
170
|
|
|
$this->assertTrue($this->clickSubmit($lang['strexplain']));
|
|
171
|
|
|
|
|
172
|
|
|
// Here $lang['strsqlexecuted'] is not fit for this situation. Because the "%s"
|
|
173
|
|
|
// make the assertion failed.
|
|
174
|
|
|
$this->assertWantedText('Total runtime');
|
|
175
|
|
|
|
|
176
|
|
|
return TRUE;
|
|
177
|
|
|
}
|
|
178
|
|
|
|
|
179
|
|
|
|
|
180
|
|
|
/**
|
|
181
|
|
|
* TestCaseId: DES006
|
|
182
|
|
|
* This test is used to send the "select" sql script to phpPgAdmin
|
|
183
|
|
|
* for implementation about "Explain Analyze".
|
|
184
|
|
|
*/
|
|
185
|
|
|
function testExplainAnalyze()
|
|
186
|
|
|
{
|
|
187
|
|
|
global $webUrl;
|
|
188
|
|
|
global $lang, $SERVER, $DATABASE;
|
|
189
|
|
|
|
|
190
|
|
|
$this->assertTrue($this->get("$webUrl/database.php", array(
|
|
191
|
|
|
'database' => $DATABASE,
|
|
192
|
|
|
'server' => $SERVER,
|
|
193
|
|
|
'subject' => 'database',
|
|
194
|
|
|
'action' => 'sql'))
|
|
195
|
|
|
);
|
|
196
|
|
|
$this->assertTrue($this->setField('query',
|
|
197
|
|
|
'select "id" from "student";'));
|
|
198
|
|
|
|
|
199
|
|
|
$this->assertTrue($this->setField('paginate', TRUE));
|
|
200
|
|
|
|
|
201
|
|
|
$this->assertTrue($this->clickSubmit($lang['strexplainanalyze']));
|
|
202
|
|
|
|
|
203
|
|
|
// Here $lang['strsqlexecuted'] is not fit for this situation. Because the "%s"
|
|
204
|
|
|
// make the assertion failed.
|
|
205
|
|
|
$this->assertWantedText('Total runtime');
|
|
206
|
|
|
|
|
207
|
|
|
return TRUE;
|
|
208
|
|
|
}
|
|
209
|
|
|
|
|
210
|
|
|
|
|
211
|
|
|
/**
|
|
212
|
|
|
* TestCaseId: DES007
|
|
213
|
|
|
* This test is used to send the "select" sql script file to phpPgAdmin
|
|
214
|
|
|
* for implementation about "upload" sql script.
|
|
215
|
|
|
*
|
|
216
|
|
|
* Note: The SimpleTest doesn't support this yet currently.
|
|
217
|
|
|
* So this failed.
|
|
218
|
|
|
*/
|
|
219
|
|
|
function testUploadSQLFile()
|
|
220
|
|
|
{
|
|
221
|
|
|
|
|
222
|
|
|
global $webUrl;
|
|
223
|
|
|
global $lang, $SERVER, $DATABASE;
|
|
224
|
|
|
|
|
225
|
|
|
$this->assertTrue($this->get("$webUrl/database.php", array(
|
|
226
|
|
|
'server' => $SERVER,
|
|
227
|
|
|
'database' => $DATABASE,
|
|
228
|
|
|
'subject' => 'database',
|
|
229
|
|
|
'action' => 'sql'))
|
|
230
|
|
|
);
|
|
231
|
|
|
|
|
232
|
|
|
$webServerUrl = getcwd();
|
|
233
|
|
|
$sqlScriptUrl = getcwd() . "/data/select.sql";
|
|
234
|
|
|
|
|
235
|
|
|
$this->assertTrue ($this->setField('script', $sqlScriptUrl));
|
|
236
|
|
|
|
|
237
|
|
|
$this->assertTrue($this->clickSubmit($lang['strexecute']));
|
|
238
|
|
|
|
|
239
|
|
|
$this->assertWantedText($lang['strsqlexecuted']);
|
|
240
|
|
|
|
|
241
|
|
|
return TRUE;
|
|
242
|
|
|
}
|
|
243
|
|
|
|
|
244
|
|
|
|
|
245
|
|
|
/**
|
|
246
|
|
|
* TestCaseId: DES009
|
|
247
|
|
|
* This test is used to send the "select" sql script to the topbar link
|
|
248
|
|
|
* in phpPgAdmin for implementation.
|
|
249
|
|
|
*/
|
|
250
|
|
|
function testSelectTopSQL()
|
|
251
|
|
|
{
|
|
252
|
|
|
global $webUrl;
|
|
253
|
|
|
global $lang, $SERVER, $DATABASE;
|
|
254
|
|
|
|
|
255
|
|
|
$this->get("$webUrl/sqledit.php", array('action' => 'sql', 'server' => $SERVER));
|
|
256
|
|
|
|
|
257
|
|
|
$this->assertTrue($this->setField('database', $DATABASE));
|
|
258
|
|
|
$this->assertTrue($this->setField('query', 'select * from student;'));
|
|
259
|
|
|
|
|
260
|
|
|
$this->assertTrue($this->clickSubmit($lang['strexecute']));
|
|
261
|
|
|
|
|
262
|
|
|
$this->assertWantedText($lang['strsqlexecuted']);
|
|
263
|
|
|
|
|
264
|
|
|
return true;
|
|
265
|
|
|
}
|
|
266
|
|
|
|
|
267
|
|
|
|
|
268
|
|
|
/**
|
|
269
|
|
|
* TestCaseId: DES010;
|
|
270
|
|
|
* This test is used to send the "select" sql script to the topbar link
|
|
271
|
|
|
* in phpPgAdmin for implementation.
|
|
272
|
|
|
*/
|
|
273
|
|
|
function testResultFromSelectTopSQL()
|
|
274
|
|
|
{
|
|
275
|
|
|
global $webUrl;
|
|
276
|
|
|
global $lang, $SERVER, $DATABASE;
|
|
277
|
|
|
|
|
278
|
|
|
$this->get("$webUrl/sqledit.php", array('action' => 'sql', 'server' => $SERVER));
|
|
279
|
|
|
|
|
280
|
|
|
$this->assertTrue($this->setField('database', $DATABASE));
|
|
281
|
|
|
$this->assertTrue($this->setField('query', 'select * from student;'));
|
|
282
|
|
|
$this->assertTrue($this->setField('paginate', TRUE));
|
|
283
|
|
|
$this->assertTrue($this->clickSubmit($lang['strexecute']));
|
|
284
|
|
|
|
|
285
|
|
|
$this->assertTrue($this->clickLink($lang['strexpand']));
|
|
286
|
|
|
$this->assertWantedText($lang['strnodata']);
|
|
287
|
|
|
|
|
288
|
|
|
$this->assertTrue($this->clickLink($lang['strcollapse']));
|
|
289
|
|
|
$this->assertWantedText($lang['strnodata']);
|
|
290
|
|
|
|
|
291
|
|
|
$this->assertTrue($this->clickLink($lang['strrefresh']));
|
|
292
|
|
|
|
|
293
|
|
|
return TRUE;
|
|
294
|
|
|
}
|
|
295
|
|
|
|
|
296
|
|
|
|
|
297
|
|
|
/**
|
|
298
|
|
|
* TestCaseId: DES011
|
|
299
|
|
|
* This test is used to generate the report by the sql in topbar
|
|
300
|
|
|
* in phpPgAdmin for implementation.
|
|
301
|
|
|
*/
|
|
302
|
|
|
function testReportByTopSql()
|
|
303
|
|
|
{
|
|
304
|
|
|
global $webUrl;
|
|
305
|
|
|
global $lang, $SERVER, $DATABASE;
|
|
306
|
|
|
|
|
307
|
|
|
$this->assertTrue($this->get("$webUrl/reports.php", array(
|
|
308
|
|
|
'action' => 'create',
|
|
309
|
|
|
'server' => $SERVER,
|
|
310
|
|
|
'db_name' => $DATABASE,
|
|
311
|
|
|
'report_sql' => 'select id from student;')
|
|
312
|
|
|
));
|
|
313
|
|
|
|
|
314
|
|
|
$this->assertTrue($this->setField('report_name', 'ppasimpletestreport'));
|
|
315
|
|
|
$this->assertTrue($this->setField('descr', 'ppasimpletest tests'));
|
|
316
|
|
|
|
|
317
|
|
|
$this->assertTrue($this->clickSubmit($lang['strsave']));
|
|
318
|
|
|
|
|
319
|
|
|
$this->assertWantedText($lang['strreportcreated']);
|
|
320
|
|
|
}
|
|
321
|
|
|
|
|
322
|
|
|
|
|
323
|
|
|
/**
|
|
324
|
|
|
* TestCaseId: DES012
|
|
325
|
|
|
* This test is used to download the specified format of
|
|
326
|
|
|
* report by the sql in topbar in phpPgAdmin for implementation.
|
|
327
|
|
|
*/
|
|
328
|
|
|
function testDownloadTopSql()
|
|
329
|
|
|
{
|
|
330
|
|
|
global $webUrl;
|
|
331
|
|
|
global $lang, $SERVER, $DATABASE;
|
|
332
|
|
|
|
|
333
|
|
|
$this->assertTrue($this->get("$webUrl/dataexport.php", array(
|
|
334
|
|
|
'server' => $SERVER,
|
|
335
|
|
|
'query' => 'select+id+from+student%3B',
|
|
336
|
|
|
'database' => $DATABASE))
|
|
337
|
|
|
);
|
|
338
|
|
|
|
|
339
|
|
|
$this->assertTrue($this->setField('d_format', 'XML'));
|
|
340
|
|
|
$this->assertTrue($this->setField('output', 'show'));
|
|
341
|
|
|
|
|
342
|
|
|
$this->assertTrue($this->clickSubmit($lang['strexport']));
|
|
343
|
|
|
|
|
344
|
|
|
// Here anything about xml cannot be found in English.php so hard code.
|
|
345
|
|
|
$this->assertWantedPattern('/<?xml/');
|
|
346
|
|
|
}
|
|
347
|
|
|
}
|
|
348
|
|
|
|
|
349
|
|
|
?>
|
|
350
|
|
|
|