Test Failed
Branch develop (db5506)
by Felipe
03:46
created

DeadlockTest::testQueryDroppedTable()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 89
Code Lines 52

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 52
nc 1
nop 0
dl 0
loc 89
rs 8.5731
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
 /**
3
  * Function area:       Table
4
  * Subfunction area:    Exception
5
  * @author     Augmentum SpikeSource Team 
6
  * @copyright  2005 by Augmentum, Inc.
7
  */
8
9
// Import the precondition class.
10
if(is_dir('../Public')) 
11
{
12
    require_once('../Public/SetPrecondition.php');
13
}
14
15
16
/**
17
 * A test case suite for testing exceptional scenarios in phpPgAdmin
18
 */
19
class DeadlockTest extends PreconditionSet{
20
    
21
    /**
22
     * Set up the preconditon. 
23
     */
24
    function setUp()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
25
    {       
26
        return TRUE;
27
    }
28
    
29
    /**
30
     * Clean up all the result. 
31
     */ 
32
    function tearDown()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
33
    {
34
        $this->logout(); 
35
        
36
        return TRUE;
37
    }
38
    
39
        
40
    /**
41
     * TestCaseID: TET03
42
     * 
43
     * Scenario:
44
     * 1. Open the first session, login as power user. Try to add a check 
45
     *    constraint: id_check (id > 0), without commit
46
     * 2. Open the second session, login as super user. Change the password 
47
     *    of the power user and commit the alteration.
48
     * 3. Turn to the first session and commit the add check operation.
49
     * 4. Rollback the changes, that's, change back the password for the 
50
     *    power user.
51
     * 
52
     * Expected result:  Login failed.
53
     */
54
    function testAddCheckScenario()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
55
    {
56
        global $webUrl;
57
        global $lang, $SERVER, $DATABASE;
58
        global $POWER_USER_PASSWORD;
59
        global $SUPER_USER_PASSWORD;
60
        global $SUPER_USER_NAME;
61
        global $POWER_USER_NAME;
62
        
63
64
        $this->login($POWER_USER_NAME, $POWER_USER_PASSWORD, 
65
                     "$webUrl/login.php");
66
        
67
        // Try to add a check constraint to the table student
68
        // Go to the constraints page
69
		$this->assertTrue($this->get("$webUrl/constraints.php", array(
70
			'server' => $SERVER,
71
			'action' => 'add_check',
72
			'database' => $DATABASE,
73
			'schema' => 'public',
74
			'table' => 'student'))
75
		);
76
        
77
        // Set properties for the new constraint    
78
        $this->assertTrue($this->setField('name', 'id_check'));
79
        $this->assertTrue($this->setField('definition', 'id > 0'));
80
        
81
        
82
        // Open the second session, login as superuser
83
        $newBrowser = $this->createBrowser();
84
        $newBrowser->get("$webUrl/login.php"); 
85
        $this->assertTrue($newBrowser->setField('formUsername', $SUPER_USER_NAME));
86
        $this->assertTrue($newBrowser->setField('formPassword', $SUPER_USER_PASSWORD));
87
        $this->assertTrue($newBrowser->setField('formLanguage', $lang['applang']));
88
        $this->assertTrue($newBrowser->clickSubmit('Login'));
89
                     
90
        // Alter the user's password
91
        $this->assertTrue($newBrowser->get("$webUrl/users.php"));
92
		$this->assertTrue($newBrowser->get("$webUrl/users.php", array(
93
			'server' => $SERVER,
94
			'action' => 'edit',
95
			'username' => $POWER_USER_NAME))
96
		);       
97
        // Enter the information for altering the user's properties.
98
        $this->assertTrue($newBrowser->setField('newname', $POWER_USER_NAME));
99
        $this->assertTrue($newBrowser->setField('formPassword', '56789'));
100
        $this->assertTrue($newBrowser->setField('formConfirm', '56789'));
101
        $this->assertTrue($newBrowser->setField('formSuper', FALSE));
102
        $this->assertTrue($newBrowser->setField('formCreateDB', TRUE));
103
        $this->assertTrue($newBrowser->clickSubmit($lang['stralter']));
104
        
105
106
        // Now turn to the first session, submit the "add check" operation
107
        $this->assertTrue($this->clickSubmit($lang['stradd']));      
108
        // Verify if the constraint is created correctly.
109
        $this->assertTrue($this->assertWantedText($lang['strloginfailed']));
110
        
111
        
112
        // Rollback the changes to return to the original state
113
        $this->assertTrue($newBrowser->get("$webUrl/users.php"));
114
		$this->assertTrue($newBrowser->get("$webUrl/users.php", array(
115
			'server' => $SERVER,
116
			'action' => 'edit',
117
			'username' => $POWER_USER_NAME))
118
		);
119
       
120
        // Change back the user's password
121
        $this->assertTrue($newBrowser->setField('newname', $POWER_USER_NAME));
122
        $this->assertTrue($newBrowser->setField('formPassword', $POWER_USER_PASSWORD));
123
        $this->assertTrue($newBrowser->setField('formConfirm', $POWER_USER_PASSWORD));
124
        $this->assertTrue($newBrowser->setField('formSuper', FALSE));
125
        $this->assertTrue($newBrowser->setField('formCreateDB', TRUE));      
126
        $this->assertTrue($newBrowser->clickSubmit($lang['stralter']));
127
        
128
        return TRUE; 
129
    }
130
    
131
    
132
    /**
133
     * TestCaseID: TET01
134
     * 
135
     * Scenario:
136
     * 1. Open the first session, login as power user. Try to create a 
137
     *    database, don't commit;
138
     * 2. Open the second session, login as super user. Revoke the power
139
     *    user's createdb privilege
140
     * 3. Turn to the first session and commit the create database operation.
141
     * 4. Rollback the changes, that's, grant the createdb privilege to the
142
     *    power user.
143
     * 
144
     * Expected result:  Failed to add database. Permission denied.
145
     */
146
    function testCreateDatabaseScenario()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
147
    {
148
        global $webUrl;
149
        global $lang, $SERVER;
150
        global $POWER_USER_PASSWORD;
151
        global $SUPER_USER_PASSWORD;
152
        global $SUPER_USER_NAME;
153
        global $POWER_USER_NAME;
154
        
155
        $this->login($POWER_USER_NAME, $POWER_USER_PASSWORD, 
156
                     "$webUrl/login.php");
157
        
158
        // Try to create a database 'newdb', without commit the operation                 
159
        $this->assertTrue ($this->get ("$webUrl/all_db.php"));              
160
		$this->assertTrue ($this->get ("$webUrl/all_db.php", array(
161
			'server' => $SERVER,
162
			'action' => 'create'))
163
		);       
164
        $this->assertTrue ($this->setfield('formName', 'newdb'));
165
        $this->assertTrue ($this->setfield('formEncoding', 'UNICODE'));                      
166
        
167
        
168
        // Open another session, login as superuser
169
        $newBrowser = $this->createBrowser();
170
        $newBrowser->get("$webUrl/login.php");
171
        $this->assertTrue($newBrowser->setField('formUsername', $SUPER_USER_NAME));
172
        $this->assertTrue($newBrowser->setField('formPassword', $SUPER_USER_PASSWORD));
173
        $this->assertTrue($newBrowser->setField('formLanguage', $lang['applang']));
174
        $this->assertTrue($newBrowser->clickSubmit('Login'));
175
                     
176
        // Revoke the user's createdb privilege
177
        $this->assertTrue($newBrowser->get("$webUrl/users.php"));
178
		$this->assertTrue($newBrowser->get("$webUrl/users.php", array(
179
			'server' => $SERVER,
180
			'action' => 'edit',
181
			'username' => $POWER_USER_NAME))
182
		);
183
        $this->assertTrue($newBrowser->setField('newname', $POWER_USER_NAME));
184
        $this->assertTrue($newBrowser->setField('formPassword', 'tester'));
185
        $this->assertTrue($newBrowser->setField('formConfirm', 'tester'));
186
        $this->assertTrue($newBrowser->setField('formSuper', FALSE));
187
        $this->assertTrue($newBrowser->setField('formCreateDB', FALSE));     
188
        $this->assertTrue($newBrowser->clickSubmit($lang['stralter']));
189
        
190
        
191
        // Now turn to the first session, submit the "create DB" operation
192
        $this->assertTrue ($this->clickSubmit($lang['strcreate']));       
193
        // Verify weather the database has been created.
194
        $this->assertTrue ($this->assertWantedText($lang['strdatabasecreatedbad']));
195
          
196
        // Rollback the changes to return to the original state
197
        $this->assertTrue($newBrowser->get("$webUrl/users.php"));
198
		$this->assertTrue($newBrowser->get("$webUrl/users.php", array(
199
			'server' => $SERVER,
200
			'action' => 'edit',
201
			'username' => $POWER_USER_NAME))
202
		);
203
204
        $this->assertTrue($newBrowser->setField('newname', $POWER_USER_NAME));
205
        $this->assertTrue($newBrowser->setField('formPassword', $POWER_USER_PASSWORD));
206
        $this->assertTrue($newBrowser->setField('formConfirm', $POWER_USER_PASSWORD));
207
        $this->assertTrue($newBrowser->setField('formSuper', FALSE));
208
        $this->assertTrue($newBrowser->setField('formCreateDB', TRUE));      
209
        $this->assertTrue($newBrowser->clickSubmit($lang['stralter']));
210
        
211
        return TRUE;
212
    }
213
    
214
    /**
215
     * TestCaseID: TET02
216
     * 
217
     * Scenario:
218
     * 1. Open the first session, login as power user. Create a column named 
219
     *    "sid". Then try to rename it as "ssid", don't commit;
220
     * 2. Open the second session, login as power user. Drop the column "sid";
221
     * 3. Turn to the first session and commit the alter column operation.
222
     * 
223
     * Expected result:  Failed to alter the column.
224
     */
225
    function testDropColumnScenario()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
226
    {
227
        global $webUrl;
228
        global $lang, $SERVER, $DATABASE;
229
        global $POWER_USER_PASSWORD;
230
        global $SUPER_USER_PASSWORD;
231
        global $SUPER_USER_NAME;
232
        global $POWER_USER_NAME;
233
        
234
        $this->login($POWER_USER_NAME, $POWER_USER_PASSWORD, 
235
                     "$webUrl/login.php");
236
        
237
        // Add a column "sid"
238
		$this->assertTrue($this->get("$webUrl/tblproperties.php", array(
239
			'server' => $SERVER,
240
			'action' => 'add_column',
241
			'database' => $DATABASE,
242
			'schema' => 'public',
243
			'table' => 'student'))
244
		);
245
        // Set properties for the new column    
246
        $this->assertTrue($this->setField('field', 'sid'));        
247
        $this->assertTrue($this->setField('type', 'integer'));                
248
        $this->assertTrue($this->clickSubmit($lang['stradd']));
249
        // Verify if the column is created correctly.
250
        $this->assertTrue($this->assertWantedText($lang['strcolumnadded']));
251
        
252
        
253
        // Try to alter the column as "ssid"
254
		$this->assertTrue($this->get("$webUrl/tblproperties.php", array(
255
			'server' => $SERVER,
256
			'action' => 'properties',
257
			'database' => $DATABASE,
258
			'schema' => 'public',
259
			'table' => 'student',
260
			'column' => 'sid'))
261
		);
262
        // Set properties for the new column    
263
        $this->assertTrue($this->setField('field', 'ssid'));        
264
        $this->assertTrue($this->setField('type', 'character')); 
265
        $this->assertTrue($this->setField('length', '18')); 
266
267
        
268
        // Open the second session, login as power user
269
        $newBrowser = $this->createBrowser();
270
        $newBrowser->get("$webUrl/login.php"); 
271
        $this->assertTrue($newBrowser->setField('formUsername', $POWER_USER_NAME));
272
        $this->assertTrue($newBrowser->setField('formPassword', $POWER_USER_PASSWORD));
273
        $this->assertTrue($newBrowser->setField('formLanguage', $lang['applang']));
274
        $this->assertTrue($newBrowser->clickSubmit('Login'));
275
276
        // Drop the column
277
		$this->assertTrue($newBrowser->get("$webUrl/tblproperties.php", array(
278
		    'server' => $SERVER,
279
			'action' => 'confirm_drop',
280
			'database' => $DATABASE,
281
			'schema' => 'public',
282
			'table' => 'student',
283
			'column' => 'sid'))
284
		);
285
        $this->assertTrue($newBrowser->clickSubmit($lang['strdrop']));
286
        
287
        
288
        // Now turn to the first session, submit the "create DB" operation
289
         $this->assertTrue($this->clickSubmit($lang['stralter']));
290
        // Verify if the column is altered correctly.
291
        $this->assertTrue($this->assertWantedText($lang['strcolumnalteredbad']));
292
        
293
        return TRUE;          
294
    }
295
    
296
    
297
    /**
298
     * TestCaseID: TET05
299
     * 
300
     * Scenario:
301
     * 1. Open the first session, login as power user. Create a table 
302
     *    named "newtable". Then issue a SELECT query without commit. 
303
     * 2. Open another session, login as power user. Drop the table "newtable";
304
     * 3. Turn to the first session and commit the SELECT query.
305
     * 
306
     * Expected result:  ERROR:  relation "public.newtable" does not exist.
307
     */
308
    function testQueryDroppedTable()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
309
    {
310
        global $webUrl;
311
        global $lang, $SERVER, $DATABASE;
312
        global $POWER_USER_PASSWORD;
313
        global $SUPER_USER_PASSWORD;
314
        global $SUPER_USER_NAME;
315
        global $POWER_USER_NAME;
316
317
        $this->login($SUPER_USER_NAME, $SUPER_USER_PASSWORD, 
318
                     "$webUrl/login.php");
319
        // Create a table.
320
		$this->assertTrue($this->get("$webUrl/tables.php", array(
321
			'server' => $SERVER,
322
			'action' => 'create',
323
			'database' => $DATABASE,
324
			'schema' => 'public'))
325
		);
326
        
327
        // Enter the table name and field number.
328
        $this->assertTrue($this->setField('name', 'newtable'));        
329
        $this->assertTrue($this->setField('fields', '2'));
330
        $this->assertTrue($this->setField('spcname', 'pg_default'));
331
        $this->assertTrue($this->setField('tblcomment', 'Create from SimpleTest!'));
332
                        
333
        // Click the button "next >" for inputing the detail information.                  
334
        //$this->assertTrue($this->clickSubmit($lang['strnext']));
335
        // If we do not hardcoded it here, it will cause fail. Encoding issue.
336
        $this->assertTrue($this->clickSubmit('Next >'));
337
          
338
        // Enter the detail information of the table. 
339
        $this->assertTrue($this->setField('field[0]', 'firstfield'));    
340
        $this->assertTrue($this->setField('type[0]', 'text'));
341
        $this->assertTrue($this->setField('array[0]', ''));
342
         
343
        $this->assertTrue($this->setField('field[1]', 'secondfield'));    
344
        $this->assertTrue($this->setField('type[1]', 'text'));
345
        $this->assertTrue($this->setField('array[1]', ''));
346
        
347
        // Click the button "Create" to create the table
348
        $this->assertTrue($this->clickSubmit($lang['strcreate']));
349
        // Verify if the table create correctly.
350
        $this->assertTrue($this->assertWantedText($lang['strtablecreated']));
351
        
352
        
353
        // Issue a SELECT query
354
        
355
        // Turn to the "tables" page.
356
		$this->assertTrue($this->get("$webUrl/tables.php", array(
357
		    'server' => $SERVER,
358
			'action' => 'confselectrows',
359
			'database' => $DATABASE,
360
			'schema' => 'public',
361
			'table' => 'newtable'))
362
		);
363
        
364
        // Select all the rows.
365
        $this->assertTrue($this->setField('show[firstfield]', TRUE));
366
        $this->assertTrue($this->setField('show[secondfield]', TRUE));
367
  
368
        
369
        // Open another session, login as super user, drop the table "newtable"
370
        $newBrowser = $this->createBrowser();
371
        $newBrowser->get("$webUrl/login.php");
372
        $this->assertTrue($newBrowser->setField('formUsername', $SUPER_USER_NAME));
373
        $this->assertTrue($newBrowser->setField('formPassword', $SUPER_USER_PASSWORD));
374
        $this->assertTrue($newBrowser->setField('formLanguage', $lang['applang']));
375
        $this->assertTrue($newBrowser->clickSubmit('Login'));
376
                     
377
        // Drop the table
378
		$newBrowser->get("$webUrl/tables.php", array(
379
			'server' => $SERVER,
380
			'action' => 'confirm_drop',
381
			'database' => $DATABASE,
382
			'schema' => 'public',
383
			'table' => 'newtable')
384
		); 
385
        $this->assertTrue($newBrowser->clickSubmit($lang['strdrop']));
386
        
387
        
388
        // Now turn to the first session, submit the SELECT query
389
        // Display all the rows.        
390
        $this->assertTrue($this->clickSubmit($lang['strselect']));
391
        // Verify whether select successful.       
392
        $this->assertTrue($this->assertWantedText($lang['strsqlerror']));
393
        $this->assertTrue($this->assertWantedText('public.newtable'));
394
        $this->assertTrue($this->assertWantedText('does not exist'));
395
        
396
        return TRUE;
397
    }
398
}
399
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
400