Passed
Push — develop ( db5506...7ff7f1 )
by Felipe
06:26 queued 02:43
created

ConstraintsTest::testAddForeignKey()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 29
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 17
nc 1
nop 0
dl 0
loc 29
rs 8.8571
c 0
b 0
f 0
1
<?php
2
 /**
3
  * Function area:       Table
4
  * Subfunction area:    Constraint
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 CONSTRAINT feature in phpPgAdmin, including cases
18
 * for adding and dropping check, foreign key, unique key and primary key.
19
 */
20
class ConstraintsTest extends PreconditionSet{
21
    
22
    /**
23
     * Set up the preconditon. 
24
     */
25
    function setUp()
26
    {
27
        global $webUrl;
28
        global $SUPER_USER_NAME;
29
        global $SUPER_USER_PASSWORD;
30
        
31
        $this->login($SUPER_USER_NAME, $SUPER_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: TAC01
48
     * Test creating a check constraint in a table
49
     */
50
    function testAddCheck(){
51
        global $webUrl;
52
        global $lang, $SERVER, $DATABASE;
53
        
54
        // Go to the constraints page
55
		$this->assertTrue($this->get("$webUrl/constraints.php", array(
56
			'server' => $SERVER,
57
			'action' => 'add_check',
58
			'database' => $DATABASE,
59
			'schema' => 'public',
60
			'table' => 'student'))
61
		);
62
        
63
        // Set properties for the new constraint    
64
        $this->assertTrue($this->setField('name', 'id_check'));
65
        $this->assertTrue($this->setField('definition', 'id > 0'));               
66
        
67
        $this->assertTrue($this->clickSubmit($lang['stradd']));
68
        
69
        // Verify if the constraint is created correctly.
70
        $this->assertTrue($this->assertWantedText($lang['strcheckadded']));
71
        
72
        return TRUE;  
73
    }    
74
    
75
        
76
    /**
77
     * TestCaseID: TDC02
78
     * Test dropping a check constraint in a table
79
     */
80
    function testDropCheckKey()
81
    {
82
        global $webUrl;
83
        global $lang, $SERVER, $DATABASE;
84
        
85
		$this->assertTrue($this->get("$webUrl/constraints.php", array(
86
			'server' => $SERVER,
87
			'action' => 'confirm_drop',
88
			'database' => $DATABASE,
89
			'schema' => 'public',
90
			'table' => 'student',
91
			'constraint' => 'id_check',
92
			'type' => 'c'))
93
		);
94
        $this->assertTrue($this->clickSubmit($lang['strdrop']));
95
        // Verify if the constraint is dropped correctly.
96
        $this->assertTrue($this->assertWantedText($lang['strconstraintdropped']));
97
        
98
        return TRUE;  
99
    }
100
    
101
    
102
    /**
103
     * TestCaseID: TAC02
104
     * Test adding a unique key to a table
105
     */
106
    function testAddUniqueKey(){
107
        global $webUrl;
108
        global $lang, $SERVER, $DATABASE;
109
        
110
        // Go to the constraints page
111
		$this->assertTrue($this->get("$webUrl/constraints.php", array(
112
			'server' => $SERVER,
113
			'action' => 'add_unique_key',
114
			'database' => $DATABASE,
115
			'schema' => 'public',
116
			'table' => 'student'))
117
		);
118
        
119
        // Set properties for the new constraint    
120
        $this->assertTrue($this->setField('name', 'unique_name'));
121
        $this->assertTrue($this->setField('TableColumnList', array('name')));  
122
        $this->assertTrue($this->setField('tablespace', 'pg_default'));
123
        $this->assertTrue($this->setField('IndexColumnList[]', 'name')); 
124
        
125
        $this->assertTrue($this->clickSubmit($lang['stradd']));
126
        // Verify if the constraint is created correctly.
127
        $this->assertTrue($this->assertWantedText($lang['struniqadded']));
128
        
129
        return TRUE; 
130
    }
131
    
132
    
133
    /**
134
     * TestCaseID: TDC01
135
     * Test dropping a unique constraint in a table
136
     */
137
    function testDropUniqueKey()
138
    {
139
        global $webUrl;
140
        global $lang, $SERVER, $DATABASE;
141
        
142
		$this->assertTrue($this->get("$webUrl/constraints.php", array(
143
			'server' => $SERVER, 'action' => 'confirm_drop',
144
			'database' => $DATABASE, 'schema' => 'public',
145
			'table' => 'student', 'constraint' => 'unique_name'))
146
		);
147
148
        $this->assertTrue($this->clickSubmit($lang['strdrop']));
149
        // Verify if the constraint is dropped correctly.
150
        $this->assertTrue($this->assertWantedText($lang['strconstraintdropped']));
151
        
152
        return TRUE;  
153
    }
154
    
155
    
156
    /**
157
     * TestCaseID: TAC03
158
     * Test adding a primary key to a table
159
     */
160
    function testAddPrimaryKey(){
161
        global $webUrl;
162
        global $lang, $SERVER, $DATABASE;
163
        
164
        // Go to the constraints page
165
		$this->assertTrue($this->get("$webUrl/constraints.php", array(
166
			'server' => $SERVER, 'action' => 'add_primary_key',
167
			'database' => $DATABASE, 'schema' => 'public',
168
			'table' => 'college_student'))
169
		);
170
        
171
        // Set properties for the new constraint    
172
        $this->assertTrue($this->setField('name', 'primary_id'));
173
        $this->assertTrue($this->setField('TableColumnList', array('id'))); 
174
        $this->assertTrue($this->setField('tablespace', 'pg_default')); 
175
        $this->assertTrue($this->setField('IndexColumnList[]', 'id'));           
176
        
177
        $this->assertTrue($this->clickSubmit($lang['stradd']));
178
        
179
        // Verify if the constraint is created correctly.
180
        $this->assertTrue($this->assertWantedText($lang['strpkadded']));
181
        
182
        return TRUE;                 
183
    }
184
    
185
186
    /**
187
     * TestCaseID: TDC03
188
     * Test dropping a primary key constraint in a table
189
     */
190
    function testDropPrimaryKey()
191
    {
192
        global $webUrl;
193
        global $lang, $SERVER, $DATABASE;
194
        
195
        // Remove the primary key
196
		$this->assertTrue($this->get("$webUrl/constraints.php", array(
197
			'server' => $SERVER, 'action' => 'confirm_drop', 'database' => $DATABASE,
198
			'schema' => 'public', 'table' => 'college_student', 'constraint' => 'primary_id',
199
			'type' => 'p'))
200
		);
201
        $this->assertTrue($this->clickSubmit($lang['strdrop']));
202
        $this->assertTrue($this->assertWantedText($lang['strconstraintdropped']));
203
        
204
        return TRUE;  
205
    }
206
    
207
    
208
    /**
209
     * TestCaseID: TAC03
210
     * Test adding a foreign key to a table
211
     */
212
    function testAddForeignKey(){
213
        global $webUrl;
214
        global $lang, $SERVER, $DATABASE;
215
        
216
        // Go to the constraints page
217
		$this->assertTrue($this->get("$webUrl/constraints.php", array(
218
			'server' => $SERVER, 'action' => 'add_foreign_key', 'database' => $DATABASE,
219
			'schema' => 'public', 'table' => 'student'))
220
		);
221
        
222
        // Set properties for the new constraint    
223
        $this->assertTrue($this->setField('name', 'foreign_id'));
224
        $this->assertTrue($this->setField('TableColumnList', array('id')));
225
        $this->assertTrue($this->setField('IndexColumnList[]', 'id')); 
226
        $this->assertTrue($this->setField('target', 'department'));           
227
        
228
        $this->assertTrue($this->clickSubmit($lang['stradd']));
229
        
230
        $this->assertTrue($this->setField('TableColumnList', array('id'))); 
231
        
232
        $this->assertTrue($this->setFieldById('IndexColumnList', 'id'));
233
        $this->assertTrue($this->setField('upd_action', 'RESTRICT'));
234
        $this->assertTrue($this->setField('del_action', 'RESTRICT'));
235
        $this->assertTrue($this->clickSubmit($lang['stradd']));
236
        
237
        // Verify if the constraint is created correctly.
238
        $this->assertTrue($this->assertWantedText($lang['strfkadded']));
239
        
240
        return TRUE;          
241
    }
242
    
243
    
244
    /**
245
     * TestCaseID: TDC04
246
     * Test dropping a foreign key constraint in a table
247
     */
248
    function testDropForeignKey()
249
    {
250
        global $webUrl;
251
        global $lang, $SERVER, $DATABASE;
252
        
253
        // Remove the foreign key
254
		$this->assertTrue($this->get("$webUrl/constraints.php", array(
255
			'server' => $SERVER, 'action' => 'confirm_drop', 'database' => $DATABASE,
256
			'schema' => 'public', 'table' => 'student', 'constraint' => 'foreign_id',
257
			'type' => 'f'))
258
		);
259
        $this->assertTrue($this->clickSubmit($lang['strdrop']));
260
        $this->assertTrue($this->assertWantedText($lang['strconstraintdropped']));
261
        
262
        return TRUE; 
263
    }
264
}
265
?>
266