Passed
Pull Request — develop (#92)
by Felipe
06:21
created

ViewTest::testDropView()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 13
nc 1
nop 0
dl 0
loc 24
rs 8.9713
c 0
b 0
f 0
1
<?php
2
 /**
3
  * Function area:       Schemas
4
  * Subfunction area:    View
5
  * @author     Augmentum SpikeSource Team 
6
  * @copyright  2005 by Augmentum, Inc.
7
  */
8
 
9
// Import the precondition class.
10
if(is_dir('../Public')) {
11
    require_once('../Public/SetPrecondition.php');
12
}
13
14
15
/**
16
 * A test case suite for testing VIEW feature in phpPgAdmin, including
17
 * cases for creating, altering, browsing and dropping views.
18
 */
19
class ViewTest extends PreconditionSet
20
{
21
    /**
22
     * Set up the precondition. 
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
        global $webUrl;
27
        global $SUPER_USER_NAME;
28
        global $SUPER_USER_PASSWORD;
29
        
30
        // Login the system.
31
        $this->login($SUPER_USER_NAME, $SUPER_USER_PASSWORD, 
32
                     "$webUrl/login.php"); 
33
        
34
        return TRUE;
35
    }
36
    
37
    
38
    /**
39
     * Clean up all the result. 
40
     */
41
    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...
42
    {
43
        // Logout from the system.
44
        $this->logout(); 
45
        
46
        return TRUE;
47
    }
48
    
49
    
50
    /**
51
     * TestCaseID: HCV01
52
     * Test creating a view in an existing table directly.
53
     */
54
    function testCreateViewDirectly()
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
    	
57
        global $webUrl;
58
        global $lang, $SERVER, $DATABASE;
59
        
60
        $this->createTable($DATABASE, 'public', 'viewtest', '3');       
61
62
        // Turn to the "Create view" page.
63
		$this->assertTrue($this->get("$webUrl/views.php", array(
64
			            'server' => $SERVER,
65
						'action' => 'create',
66
						'database' => $DATABASE,
67
						'schema' => 'public'))
68
					);
69
70
        // Enter the definition of the view.        
71
        $this->assertTrue($this->setField('formView', 'createviewdirectly'));        
72
        $this->assertTrue($this->setField('formDefinition', 
73
                                          'select field0, field1 from viewtest'));
74
        $this->assertTrue($this->setField('formComment',  'Create View Directly.'));
75
         
76
        // Click "Create" button to create the view.
77
        $this->assertTrue($this->clickSubmit($lang['strcreate']));    
78
         
79
        // Verify whether the view is created correctly.
80
        $this->assertTrue($this->assertWantedText($lang['strviewcreated']));
81
        
82
        return TRUE;   
83
    }
84
     
85
     
86
    /** 
87
     * TestCaseID: HCV02
88
     * This test case test for creating a view in an existing table with wizard.
89
     */
90
    function testCreateViewWithWizard()
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...
91
    {
92
        global $webUrl;
93
        global $lang, $SERVER, $DATABASE;
94
         
95
        // Turn to the "Create view with wizard" page.
96
		$this->assertTrue($this->get("$webUrl/views.php", array(
97
			            'server' => $SERVER,
98
						'action' => 'wiz_create',
99
						'database' => $DATABASE,
100
						'schema' => 'public'))
101
					);
102
103
        // Select the table.        
104
        $this->assertTrue($this->setField('formTables[]',  array('public.viewtest')));    
105
       
106
        //$this->assertTrue($this->clickSubmit($lang['strnext']));
107
        // If we do not hardcoded it here, it will cause fail. Encoding issue.
108
        $this->assertTrue($this->clickSubmit('Next >'));
109
110
        $this->assertTrue($this->setField('formView', 'createwitwizard'));
111
        $this->assertTrue($this->setField('formComment',
112
                                          'Create the view with wizard.'));        
113
        
114
        // Click "Create" button for creating the view.
115
        $this->assertTrue($this->clickSubmit($lang['strcreate'])); 
116
        
117
        return TRUE;   
118
    }
119
     
120
     
121
    /**
122
     * TestCaseID: HCV03
123
     * Test creating a view in an existing table directly.
124
     * But in this test case, some illegal data will be input.
125
     */
126
    function testCreateViewDirectlyNegative()
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...
127
    {
128
        global $webUrl;
129
        global $lang, $SERVER, $DATABASE;
130
        
131
        // Turn to the "Create view" page.
132
		$this->assertTrue($this->get("$webUrl/views.php", array(
133
			            'server' => $SERVER,
134
						'action' => 'create',
135
						'database' => $DATABASE,
136
						'schema' => 'public'))
137
					);
138
         
139
        // Enter the definition of the view.        
140
        $this->assertTrue($this->setField('formView', 'createviewdirectly'));        
141
        $this->assertTrue($this->setField('formDefinition', 
142
                                          'select firstfield, secondfield from noexisttable'));
143
        $this->assertTrue($this->setField('formComment', 
144
                                          'Create view directly use illegal definition.'));        
145
         
146
        // Click "Create" button to create the view.
147
        $this->assertTrue($this->clickSubmit($lang['strcreate']));    
148
         
149
        // Verify whether the view is created correctly.
150
        $this->assertTrue($this->assertWantedText($lang['strviewcreatedbad']));
151
        
152
        return TRUE;   
153
    } 
154
     
155
     
156
    /**
157
     * TestCaseID: HCV04
158
     * Test creating a view in an existing table with wizard.
159
     * But in this test case, some illegal data will be input.
160
     */
161
    function  testCreateViewWithWizardNegation()
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...
162
    {
163
        global $webUrl;
164
        global $lang, $SERVER, $DATABASE;
165
         
166
        // Turn to the "Create view with wizard" page.
167
		$this->assertTrue($this->get("$webUrl/views.php", array(
168
			            'server' => $SERVER,
169
						'action' => 'wiz_create',
170
						'database' => $DATABASE,
171
						'schema' => 'public'))
172
					);
173
                 
174
        // Select the table.        
175
        $this->assertTrue($this->setField('formTables[]', array('public.viewtest')));
176
        //$this->assertTrue($this->clickSubmit($lang['strnext']));
177
        // If we do not hardcoded it here, it will cause fail. Encoding issue.
178
        $this->assertTrue($this->clickSubmit('Next >'));
179
         
180
        $this->assertTrue($this->setField('formView', 'createwitwizard'));
181
        $this->assertTrue($this->setField('formComment',
182
                                          'Create the view do not select any field with wizard.'));        
183
184
        // Click "Create" button for creating the view.
185
        $this->assertTrue($this->clickSubmit($lang['strcreate']));
186
        $this->assertTrue($this->assertWantedText($lang['strviewneedsfields']));
187
                
188
        return TRUE;   
189
    }
190
     
191
     
192
    /**
193
     * TestCaseID: HBV01
194
     * Test browsing an existing view with illegal data.
195
     */
196
    function testBrowseView()
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...
197
    {
198
        global $webUrl;
199
        global $lang, $SERVER, $DATABASE;
200
         
201
        // Browse the view "createviewdirectly" created just now.
202
		$this->assertTrue($this->get("$webUrl/display.php", array(
203
			            'server' => $SERVER,
204
						'database' => $DATABASE,
205
						'schema' => 'public',
206
						'subject' => 'view',
207
						'return_url' => 'views.php%3Fdatabase%3Dtest%26amp%3Bschema%3Dpublic',
208
						'return_desc' => 'Back',
209
						'view' => 'createviewdirectly'))
210
					); 
211
                  
212
        // Click the links in the view-display page.
213
        $this->assertTrue($this->clickLink($lang['strexpand']));
214
        $this->assertTrue($this->clickLink($lang['strcollapse']));
215
        $this->assertTrue($this->clickLink($lang['strrefresh']));
216
        $this->assertTrue($this->clickLink($lang['strback']));
217
        
218
        return TRUE;   
219
    } 
220
     
221
     
222
    /**
223
     * TestCaseID: HSV01
224
     * Test selecting rows from an existing view.
225
     */
226
    function testSelectView()
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...
227
    {
228
        global $webUrl;
229
        global $lang, $SERVER, $DATABASE;
230
        
231
		$this->assertTrue($this->get("$webUrl/views.php", array(
232
			            'server' => $SERVER,
233
						'action' => 'confselectrows',
234
						'database' => $DATABASE,
235
						'schema' => 'public',
236
						'view' => 'createviewdirectly'))
237
					); 
238
     
239
        // Enter the query conditions.
240
        $this->assertTrue($this->setField('show[field0]', TRUE)); 
241
        $this->assertTrue($this->setField('show[field1]', TRUE)); 
242
        $this->assertTrue($this->setField('values[field0]', 'yes'));
243
        $this->assertTrue($this->setField('values[field1]', 'no'));
244
                    
245
        $this->assertTrue($this->clickSubmit($lang['strselect']));
246
        $this->assertTrue($this->assertWantedText($lang['strnodata']));
247
        
248
        return TRUE;   
249
    } 
250
     
251
    
252
    /**
253
     * TestCaseID: HAV01
254
     * Alter the properties of an existing view.
255
     */ 
256
    function testAlterView()
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...
257
     {
258
         global $webUrl;
259
        global $lang, $SERVER, $DATABASE;
260
         
261
         // Turn to the view display page.
262
		 $this->assertTrue($this->get("$webUrl/views.php", array(
263
			             'server' => $SERVER,
264
						 'database' => $DATABASE,
265
						 'schema' => 'public',
266
						 'subject' => 'schema'))
267
					 );
268
         // Select a view.
269
         $this->assertTrue($this->clickLink('createviewdirectly'));
270
         // Select a column.
271
         $this->assertTrue($this->clickLink($lang['stralter']));  
272
         // Alter the properties of the view.
273
         $this->assertTrue($this->setField('field', 'newfield'));
274
         $this->assertTrue($this->setField('comment', 'alterintestcase')); 
275
        
276
         // Click the "Alter" button to alter the properties.  
277
         $this->assertTrue($this->clickSubmit($lang['stralter']));         
278
         // Verify whether the properties are altered.  
279
         $this->assertTrue($this->assertWantedText($lang['strcolumnaltered'])); 
280
        
281
         return TRUE;
282
     }
283
     
284
     
285
    /**
286
     * TestCaseID: HAD01
287
     * Alter the definiton of an existing view.
288
     */
289
    function testAlterDefinition()
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...
290
    {
291
        global $webUrl;
292
        global $lang, $SERVER, $DATABASE;
293
         
294
        // Turn to the view display page.
295
		$this->assertTrue($this->get("$webUrl/views.php", array(
296
			            'server' => $SERVER,
297
						'database' => $DATABASE,
298
						'schema' => 'public',
299
						'subject' => 'schema'))
300
					);
301
        // Select a view.
302
        $this->assertTrue($this->clickLink('createviewdirectly'));
303
        // Browse the definition of the view.
304
        $this->assertTrue($this->clickLink("{$lang['strdefinition']} {$lang['strdefinition']}"));
305
        $this->assertTrue($this->clickLink($lang['stralter']));
306
        
307
        // Alter the definition here.
308
        $this->assertTrue($this->setField('formDefinition', 
309
                                          'SELECT viewtest.field0 AS newfield, ' .
310
                                          'viewtest.field2 AS field1 FROM viewtest;'));
311
        $this->assertTrue($this->setField('formComment', 'The definition be altered.')); 
312
            
313
        // Click the "Alter" button.
314
        $this->assertTrue($this->clickSubmit($lang['stralter']));
315
        //Verify whether the definition is altered.
316
        $this->assertTrue($this->assertWantedText($lang['strviewupdated'])); 
317
318
        return TRUE;
319
    }
320
     
321
      
322
    /**
323
     * TestCaseID: HDV01
324
     * Test dropping a view.
325
     */
326
    function testDropView()
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...
327
    {
328
        global $webUrl;
329
        global $lang, $SERVER, $DATABASE;
330
         
331
        // Drop the view which was created in the last case.
332
		$this->assertTrue($this->get("$webUrl/views.php", array(
333
			            'server' => $SERVER,
334
						'action' => 'confirm_drop',
335
						'database' => $DATABASE,
336
						'schema' => 'public',
337
						'view' => 'createviewdirectly'))
338
					);
339
                
340
        $this->assertTrue($this->setField('cascade', TRUE));         
341
        $this->assertTrue($this->clickSubmit($lang['strdrop']));
342
         
343
        // Verify whether the view is dropped successfully.
344
        $this->assertTrue($this->assertWantedText($lang['strviewdropped']));
345
        
346
        // Drop the table which is created in setUp().
347
        $this->dropTable($DATABASE, 'viewtest', 'public');
348
        
349
        return TRUE;   
350
    } 
351
}
352
?>
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...
353