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

TypeTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 186
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 186
rs 10
c 0
b 0
f 0
wmc 6
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()
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()
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()
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()
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()
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()
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
?>
208