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

TypeTest::testCreateType()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 14
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:    Type
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 TYPE feature in phpPgAdmin, including
17
 * cases for creating, dropping types and showing type's properties.
18
 */
19
class TypeTest 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: HCT01
52
     * Create a type.
53
     */
54
    function testCreateType()
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
        
59
        // Turn to "Types" page.
60
		$this->assertTrue($this->get("$webUrl/types.php", array(
61
			'server' => $SERVER,
62
			'database' => $DATABASE,
63
			'schema' => 'public',
64
			'subject' => 'schema'))
65
		);
66
        $this->assertTrue($this->clickLink($lang['strcreatetype']));
67
        
68
        // Enter the definition of the type.
69
        $this->assertTrue($this->setField('typname', 'complex')); 
70
        $this->assertTrue($this->setField('typin', 'abs')); 
71
        $this->assertTrue($this->setField('typout', 'abs')); 
72
        $this->assertTrue($this->setField('typlen', '2')); 
73
        
74
        // Click the "Create" button to create a type.  
75
        $this->assertTrue($this->clickSubmit($lang['strcreate']));
76
        
77
        return TRUE;
78
    } 
79
    
80
    
81
    /**
82
     * TestCaseID: HCT02
83
     * Create a composite type. 
84
     */
85
    function testCreateCompositeType()
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
        // Turn to "Types" page.
91
		$this->assertTrue($this->get("$webUrl/types.php", array(
92
			            'server' => $SERVER,
93
						'database' => $DATABASE,
94
						'schema' => 'public',
95
						'subject' => 'schema'))
96
					);
97
        $this->assertTrue($this->clickLink($lang['strcreatecomptype']));
98
99
        // Create without composite type name.
100
        //$this->assertTrue($this->clickSubmit($lang['strnext']));
101
        // If we do not hardcoded it here, it will cause fail. Encoding issue.
102
        $this->assertTrue($this->clickSubmit('Next >'));
103
        $this->assertTrue($this->assertWantedText($lang['strtypeneedsname'])); 
104
        
105
        // Enter the name of the new composite type.
106
        $this->assertTrue($this->setField('name', 'compositetype')); 
107
        
108
        // Create without composite type field.
109
        //$this->assertTrue($this->clickSubmit($lang['strnext']));
110
        // If we do not hardcoded it here, it will cause fail. Encoding issue.
111
        $this->assertTrue($this->clickSubmit('Next >'));
112
        $this->assertTrue($this->assertWantedText($lang['strtypeneedscols']));
113
                 
114
        $this->assertTrue($this->setField('fields', '2'));  
115
        $this->assertTrue($this->setField('typcomment', 'Create in testcase'));  
116
        $this->assertTrue($this->clickSubmit('Next >'));
117
        // If we do not hardcoded it here, it will cause fail. Encoding issue.
118
        //$this->assertTrue($this->clickSubmit('Next >'));
119
        
120
        // Create the composite type without the definition of fields.
121
        $this->assertTrue($this->clickSubmit($lang['strcreate']));
122
        $this->assertTrue($this->assertWantedText($lang['strtypeneedsfield']));
123
        
124
        // Enter the fields information.
125
        $this->assertTrue($this->setField('field[0]', 'firstfield'));  
126
        $this->assertTrue($this->setField('type[0]', 'bigint'));  
127
        $this->assertTrue($this->setField('field[1]', 'secondfield'));  
128
        $this->assertTrue($this->setField('type[1]', 'bigint'));
129
        
130
        // Click the "Create" button to create the composite type.  
131
        $this->assertTrue($this->clickSubmit($lang['strcreate']));
132
        // Verify if the type create correctly.
133
        $this->assertTrue($this->assertWantedText($lang['strtypecreated']));   
134
    
135
        return TRUE;    
136
    } 
137
    
138
    
139
    /**
140
     * TestCaseID: HTP01
141
     * Show the properties of the specified type.
142
     */
143
    function testShowProperty()
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...
144
    {
145
        global $webUrl;
146
        global $lang, $SERVER, $DATABASE;
147
        
148
        // Turn to "Types" page.
149
		$this->assertTrue($this->get("$webUrl/types.php", array(
150
			            'server' => $SERVER,
151
						'database' => $DATABASE,
152
						'schema' => 'pg_catalog',
153
						'subject' => 'schema'))
154
					);
155
                
156
        // Show the properties of general type.
157
        $this->assertTrue($this->clickLink('integer'));
158
        // Verify whether the properties are displayed correctly.
159
        $this->assertTrue($this->assertWantedText('int4'));  
160
        
161
        
162
        // Turn to "Types" page.
163
		$this->assertTrue($this->get("$webUrl/types.php", array(
164
			            'server' => $SERVER,
165
						'database' => $DATABASE,
166
						'schema' => 'public',
167
						'subject' => 'schema'))
168
					);
169
                
170
        // Show the properties of a composite type "compositetype".
171
        $this->assertTrue($this->clickLink('compositetype'));
172
        // Verify whether the properties are displayed correctly.
173
        $this->assertTrue($this->assertWantedText('firstfield'));     
174
        
175
        return TRUE;
176
    }
177
    
178
    
179
    /**
180
     * TestCaseID: HDT01
181
     * Drop the type.
182
     */
183
    function testDropType()
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...
184
    {
185
        global $webUrl;
186
        global $lang, $SERVER, $DATABASE;
187
        
188
        // Turn to type-dropped confirm page.
189
		$this->assertTrue($this->get("$webUrl/types.php", array(
190
			            'server' => $SERVER,
191
						'action' => 'confirm_drop',
192
						'database' => $DATABASE,
193
						'schema' => 'public',
194
						'type' => 'compositetype'))
195
					);
196
                
197
        $this->assertTrue($this->setField('cascade', TRUE));        
198
                
199
        // Click the "Drop" button to drop the type.  
200
        $this->assertTrue($this->clickSubmit($lang['strdrop']));
201
        // Verify whether the type is dropped correctly.
202
        $this->assertTrue($this->assertWantedText($lang['strtypedropped']));
203
        
204
        return TRUE;
205
    } 
206
}    
207
?>
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...
208