Passed
Push — master ( edcd19...7b8e38 )
by Felipe
05:02
created

ColumnTest   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 302
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 302
rs 10
c 0
b 0
f 0
wmc 11
1
<?php
2
 /**
3
  * Function area:       Table
4
  * Subfunction area:    Column
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 COLUMN feature in phpPgAdmin, including
18
 * cases for adding, altering and dropping columns in a table.
19
 */
20
class ColumnTest extends PreconditionSet{
21
    
22
    /**
23
     * Set up the preconditon. 
24
     */
25
    function setUp()
26
    {
27
        global $webUrl;
28
        global $POWER_USER_NAME;
29
        global $POWER_USER_PASSWORD;
30
        
31
        $this->login($POWER_USER_NAME, $POWER_USER_PASSWORD, 
32
                     "$webUrl/login.php"); 
33
34
        return TRUE;
35
    }
36
37
    /**
38
     * Clean up all the result. 
39
     */ 
40
    function tearDown(){
41
        $this->logout(); 
42
43
        return TRUE;
44
    }    
45
46
    /**
47
     * TestCaseID: TNC01
48
     * Add a column to the table
49
     */ 
50
    function testAddColumn()
51
    {
52
        global $webUrl;
53
        global $lang, $SERVER, $DATABASE;
54
        
55
        // Go to the Columns page
56
		$this->assertTrue($this->get("$webUrl/tblproperties.php",
57
			array('action' => 'add_column',
58
				'database' => $DATABASE,
59
				'schema' => 'public',
60
				'table' => 'student',
61
				'server' => $SERVER))
62
		);
63
        
64
        // Set properties for the new column    
65
        $this->assertTrue($this->setField('field', 'sid'));        
66
        $this->assertTrue($this->setField('type', 'integer'));                
67
        $this->assertTrue($this->clickSubmit($lang['stradd']));
68
        
69
        // Verify if the column is created correctly.
70
		$this->assertTrue($this->assertWantedText($lang['strcolumnadded'])); 
71
        
72
        return TRUE;             
73
    }
74
    
75
    
76
    /**
77
     * TestCaseID: TNC02
78
     * Add a column with the same name as the existing one
79
     */ 
80
    function testAddColumnWithExistingName()
81
    {
82
        global $webUrl;
83
        global $lang, $SERVER, $DATABASE;
84
85
        // Go to the Columns page
86
		$this->assertTrue($this->get("$webUrl/tblproperties.php", array(
87
			'server' => $SERVER,
88
			'action' => 'add_column',
89
			'database' => $DATABASE,
90
			'schema' => 'public',
91
			'table' => 'student'))
92
		);
93
94
        // Set properties for the new column    
95
        $this->assertTrue($this->setField('field', 'sid'));        
96
        $this->assertTrue($this->setField('type', 'integer'));                
97
        $this->assertTrue($this->clickSubmit($lang['stradd']));
98
99
        // Make sure the operation failed
100
        $this->assertTrue($this->assertWantedText($lang['strcolumnaddedbad']));
101
102
        return TRUE;               
103
    }    
104
    
105
    /**
106
     * TestCaseID: TNC03
107
     * Cancel the add column operation
108
     */ 
109
    function testCancelAddColumn()
110
    {
111
        global $webUrl;
112
        global $lang, $SERVER, $DATABASE;
113
        
114
        // Go to the Columns page
115
		$this->assertTrue($this->get("$webUrl/tblproperties.php", array(
116
			'server' => $SERVER,
117
			'action' => 'add_column',
118
			'database' => $DATABASE,
119
			'schema' => 'public',
120
			'table' => 'student'))
121
		);
122
        
123
        // Set properties for the new column    
124
        $this->assertTrue($this->setField('field', 'sid'));        
125
        $this->assertTrue($this->setField('type', 'integer'));                
126
        $this->assertTrue($this->clickSubmit($lang['strcancel'])); 
127
        
128
        return TRUE;             
129
    }
130
    
131
    
132
    /**
133
     * TestCaseID: TAC01
134
     * Alter a column of the table
135
     */ 
136
    function testAlterColumn()
137
    {
138
        global $webUrl;
139
        global $lang, $SERVER, $DATABASE;
140
        
141
        // Go to the Columns page
142
		$this->assertTrue($this->get("$webUrl/colproperties.php", array(
143
			'server' => $SERVER,
144
			'action' => 'properties',
145
			'database' => $DATABASE,
146
			'schema' => 'public',
147
			'table' => 'student',
148
			'column' => 'sid'))
149
		);
150
        
151
        // Set properties for the new column    
152
        $this->assertTrue($this->setField('field', 'sid'));        
153
        $this->assertTrue($this->setField('type', 'character')); 
154
        $this->assertTrue($this->setField('length', '18'));                
155
        $this->assertTrue($this->clickSubmit($lang['stralter']));
156
        
157
        // Verify if the column is altered correctly.
158
        $this->assertTrue($this->assertWantedText($lang['strcolumnaltered']));
159
        
160
        return TRUE;  
161
    }
162
    
163
    
164
    /**
165
     * TestCaseID: TAC02
166
     * Alter a column to be of negative length
167
     */ 
168
    function testNegativeLengthColumn()
169
    {
170
        global $webUrl;
171
        global $lang, $SERVER, $DATABASE;
172
        
173
        // Go to the Columns page
174
		$this->assertTrue($this->get("$webUrl/colproperties.php", array(
175
			'server' => $SERVER,
176
			'action' => 'properties',
177
			'database' => $DATABASE,
178
			'schema' => 'public',
179
			'table' => 'student',
180
			'column' => 'sid'))
181
		);
182
        
183
        // Set properties for the new column    
184
        $this->assertTrue($this->setField('field', 'sid'));        
185
        $this->assertTrue($this->setField('type', 'character')); 
186
        $this->assertTrue($this->setField('length', '-2'));                
187
        $this->assertTrue($this->clickSubmit($lang['stralter']));
188
        
189
        // Make sure the alteration failed.
190
        $this->assertTrue($this->assertWantedText($lang['strcolumnalteredbad'])); 
191
        
192
        return TRUE; 
193
    }
194
    
195
    
196
    /**
197
     * TestCaseID: TAC03
198
     * Cancel the alter column operation
199
     */ 
200
    function testCancelAlterColumn()
201
    {
202
        global $webUrl;
203
        global $lang, $SERVER, $DATABASE;
204
        
205
        // Go to the Columns page
206
		$this->assertTrue($this->get("$webUrl/colproperties.php", array(
207
			'server' => $SERVER,
208
			'action' => 'properties',
209
			'database' => $DATABASE,
210
			'schema' => 'public',
211
			'table' => 'student',
212
			'column' => 'sid'))
213
		);
214
        
215
        // Set properties for the new column    
216
        $this->assertTrue($this->setField('field', 'sid'));        
217
        $this->assertTrue($this->setField('type', 'character')); 
218
        $this->assertTrue($this->setField('length', '18'));                
219
        $this->assertTrue($this->clickSubmit($lang['strcancel']));
220
        
221
        return TRUE; 
222
    }
223
    
224
    
225
    /**
226
     * TestCaseID: TDC03
227
     * Cancel the drop column operation
228
     */ 
229
    function testCancelDropColumn()
230
    {
231
        global $webUrl;
232
        global $lang, $SERVER, $DATABASE;
233
        
234
        // Drop the column
235
		$this->assertTrue($this->get("$webUrl/tblproperties.php", array(
236
			'server' => $SERVER,
237
			'action' => 'confirm_drop',
238
			'database' => $DATABASE, 
239
			'schema' => 'public',
240
			'table' => 'student',
241
			'column' => 'sid'))
242
		);
243
        $this->assertTrue($this->clickSubmit($lang['strcancel']));
244
        
245
        return TRUE; 
246
    } 
247
    
248
    
249
    /**
250
     * TestCaseID: TDC01
251
     * Drop a column from the table
252
     */ 
253
    function testDropColumn()
254
    {
255
        global $webUrl;
256
        global $lang, $SERVER, $DATABASE;
257
        
258
        // Drop the column
259
		$this->assertTrue($this->get("$webUrl/tblproperties.php", array(
260
			'server' => $SERVER,
261
			'action' => 'confirm_drop',
262
			'database' => $DATABASE,
263
			'schema' => 'public',
264
			'table' => 'student',
265
			'column' => 'sid'))
266
		);
267
        $this->assertTrue($this->clickSubmit($lang['strdrop']));
268
        // Verify if the column is dropped correctly.
269
        $this->assertTrue($this->assertWantedText($lang['strcolumndropped']));
270
        
271
        return TRUE;          
272
    } 
273
    
274
    
275
    /**
276
     * TestCaseID: TDC02
277
     * Drop a column wich "CASCADE" checked
278
     */ 
279
    function testDropColumnWithCascade()
280
    {
281
        global $webUrl;
282
        global $lang, $SERVER, $DATABASE;
283
        global $POWER_USER_NAME;
284
        global $POWER_USER_PASSWORD;        
285
        
286
        // Go to the Columns page
287
		$this->assertTrue($this->get("$webUrl/tblproperties.php", array(
288
			'server' => $SERVER,
289
			'action' => 'add_column',
290
			'database' => $DATABASE,
291
			'schema' => 'public',
292
			'table' => 'student'))
293
		);
294
        
295
        // Set properties for the new column    
296
        $this->assertTrue($this->setField('field', 'sid'));        
297
        $this->assertTrue($this->setField('type', 'integer'));                
298
        $this->assertTrue($this->clickSubmit($lang['stradd']));
299
        
300
        // Verify if the column is created correctly.
301
        $this->assertTrue($this->assertWantedText($lang['strcolumnadded'])); 
302
        
303
        $this->logout();        
304
        $this->login($POWER_USER_NAME, $POWER_USER_PASSWORD, 
305
                     "$webUrl/login.php");        
306
        
307
        // Drop the column with CASCADE checked
308
		$this->assertTrue($this->get("$webUrl/tblproperties.php" , array(
309
			'server' => $SERVER,
310
			'action' => 'confirm_drop',
311
			'database' => $DATABASE,
312
			'schema' => 'public',
313
			'table' => 'student',
314
			'column' => 'sid'))
315
		);
316
        $this->assertTrue($this->setField('cascade', TRUE));
317
        $this->assertTrue($this->clickSubmit($lang['strdrop']));
318
        // Verify if the column is dropped correctly.
319
        $this->assertTrue($this->assertWantedText($lang['strcolumndropped']));
320
        
321
        return TRUE;  
322
    }                       
323
}
324
?>
325