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

TriggersTest   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 193
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 193
rs 10
c 0
b 0
f 0
wmc 8

8 Methods

Rating   Name   Duplication   Size   Complexity  
A testCancelDropTrigger() 0 17 1
A tearDown() 0 4 1
A setUp() 0 10 1
B testAddTrigger() 0 28 1
A testCancelAlterTrigger() 0 18 1
A testAlterTrigger() 0 20 1
B testCancelAddTrigger() 0 25 1
A testDropTrigger() 0 20 1
1
<?php
2
 /**
3
  * Function area:       Table
4
  * Subfunction area:    Trigger
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
 * A test case suite for testing TRIGGER feature in phpPgAdmin, including cases
17
 * for creating, altering and dropping triggers.
18
 */
19
class TriggersTest extends PreconditionSet{
20
    
21
    
22
    /**
23
     * Set up the preconditon. 
24
     */
25
    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...
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(){
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...
41
        $this->logout(); 
42
        
43
        return TRUE;
44
    }    
45
    
46
    /**
47
     * TestCaseID: TCT01
48
     * Add a trigger to the table
49
     */ 
50
    function testAddTrigger()
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...
51
    {
52
        global $webUrl;
53
        global $lang, $SERVER, $DATABASE;
54
        
55
        // Go to the Triggers page
56
		$this->assertTrue($this->get("$webUrl/triggers.php", array(
57
			            'server' => $SERVER,
58
						'action' => 'create',
59
						'database' => $DATABASE,
60
						'schema' => 'public',
61
						'table' => 'student'))
62
					);
63
        
64
        // Set properties for the new trigger    
65
        $this->assertTrue($this->setField('formTriggerName', 
66
                                          'insert_stu_trigger'));        
67
        $this->assertTrue($this->setField('formExecTime', 'AFTER'));      
68
        $this->assertTrue($this->setField('formEvent', 'INSERT')); 
69
        $this->assertTrue($this->setField('formFunction', 
70
                                          'RI_FKey_check_ins'));      
71
        $this->assertTrue($this->setField('formTriggerArgs', ''));         
72
        
73
        $this->assertTrue($this->clickSubmit($lang['strcreate']));    
74
        // Verify if the trigger is created correctly.
75
        $this->assertTrue($this->assertWantedText($lang['strtriggercreated']));
76
        
77
        return TRUE;              
78
    }   
79
    
80
    
81
    /**
82
     * TestCaseID: TCT02
83
     * Cancel adding a trigger to the table
84
     */ 
85
    function testCancelAddTrigger()
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...
86
    {
87
        global $webUrl;
88
        global $lang, $SERVER, $DATABASE;
89
        
90
        // Go to the Triggers page
91
		$this->assertTrue($this->get("$webUrl/triggers.php", array(
92
			            'server' => $SERVER,
93
						'action' => 'create',
94
						'database' => $DATABASE,
95
						'schema' => 'public',
96
						'table' => 'student'))
97
					);
98
        
99
        // Set properties for the new trigger    
100
        $this->assertTrue($this->setField('formTriggerName', 
101
                                          'insert_stu_trigger'));        
102
        $this->assertTrue($this->setField('formExecTime', 'AFTER'));      
103
        $this->assertTrue($this->setField('formEvent', 'INSERT')); 
104
        $this->assertTrue($this->setField('formFunction', 
105
                                          'RI_FKey_check_ins'));      
106
        $this->assertTrue($this->setField('formTriggerArgs', ''));         
107
        $this->assertTrue($this->clickSubmit($lang['strcancel'])); 
108
        
109
        return TRUE;             
110
    }
111
    
112
    
113
    /**
114
     * TestCaseID: TAT02
115
     * Alter a trigger of the table
116
     */ 
117
    function testAlterTrigger()
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...
118
    {
119
        global $webUrl;
120
        global $lang, $SERVER, $DATABASE;
121
        
122
        // Alter the trigger
123
		$this->assertTrue($this->get("$webUrl/triggers.php" , array(
124
			            'server' => $SERVER,
125
						'action' => 'confirm_alter',
126
						'database' => $DATABASE,
127
						'schema' => 'public',
128
						'table' => 'student',
129
						'trigger' => 'insert_stu_trigger'))
130
					);
131
        $this->assertTrue($this->setField('name', 'changed_trigger'));
132
        $this->assertTrue($this->clickSubmit($lang['strok']));
133
        // Verify if the trigger is altered correctly.
134
        $this->assertTrue($this->assertWantedText($lang['strtriggeraltered']));
135
        
136
        return TRUE;  
137
    }
138
    
139
    
140
    /**
141
     * TestCaseID: TAT01
142
     * Cancel altering a trigger of the table
143
     */ 
144
    function testCancelAlterTrigger()
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...
145
    {
146
        global $webUrl;
147
        global $lang, $SERVER, $DATABASE;
148
        
149
        // Alter the trigger
150
		$this->assertTrue($this->get("$webUrl/triggers.php", array(
151
			            'server' => $SERVER,
152
						'action' => 'confirm_alter',
153
						'database' => $DATABASE,
154
						'schema' => 'public',
155
						'table' => 'student',
156
						'trigger' => 'changed_trigger'))
157
					);
158
        $this->assertTrue($this->setField('name', 'changed_trigger_changed'));
159
        $this->assertTrue($this->clickSubmit($lang['strcancel']));
160
161
        return TRUE;
162
    }     
163
164
    /**
165
     * TestCaseID: TDT01
166
     * Cancel dropping a trigger from the table
167
     */ 
168
    function testCancelDropTrigger()
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...
169
    {
170
        global $webUrl;
171
        global $lang, $SERVER, $DATABASE;
172
        
173
        // Drop the trigger
174
		$this->assertTrue($this->get("$webUrl/triggers.php", array(
175
		               'server' => $SERVER,
176
					   'action' => 'confirm_drop',
177
					   'database' => $DATABASE,
178
					   'schema' => 'public',
179
					   'table' => 'student',
180
					   'trigger' => 'changed_trigger'))
181
				   );
182
        $this->assertTrue($this->clickSubmit($lang['strno']));
183
        
184
        return TRUE;
185
    }
186
    
187
    
188
    /**
189
     * TestCaseID: TDT02
190
     * Drop a trigger from the table
191
     */ 
192
    function testDropTrigger()
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...
193
    {
194
        global $webUrl;
195
        global $lang, $SERVER, $DATABASE;
196
        
197
        // Drop the trigger
198
		$this->assertTrue($this->get("$webUrl/triggers.php", array(
199
			            'server' => $SERVER,
200
						'action' => 'confirm_drop',
201
						'database' => $DATABASE,
202
						'schema' => 'public',
203
						'table' => 'student',
204
						'trigger' => 'changed_trigger'))
205
					);
206
        $this->assertTrue($this->setField('cascade', TRUE));
207
        $this->assertTrue($this->clickSubmit($lang['stryes']));
208
        // Verify if the trigger is dropped correctly.
209
        $this->assertTrue($this->assertWantedText($lang['strtriggerdropped']));
210
        
211
        return TRUE; 
212
    }                          
213
}
214
?>
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...
215