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

PreconditionSet::dropTable()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 14
nc 1
nop 3
dl 0
loc 25
rs 8.8571
c 0
b 0
f 0
1
<?php
2
/**
3
 *  Provides the precondition environment for the test. 
4
 *
5
  * @author     Augmentum SpikeSource Team 
6
  * @copyright  2005 by Augmentum, Inc.
7
  */
8
9
/**
10
 * Provides some base function here.
11
 * 
12
 * Function list now:  login
13
 *                     createDatabase
14
 *                     dropDatabase(can not be run correctly)
15
 *                     createTable
16
 *                     dropTable
17
 *                     logout
18
 */
19
class PreconditionSet extends WebTestCase
0 ignored issues
show
Bug introduced by
The type WebTestCase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
20
{
21
    /**
22
     * Logoin phpPgAdmin use the specify user name, password 
23
     * and login home page.
24
     * 
25
     * The user name and password can be replaced.
26
     * But the param $loginPageUrl always equals
27
     * http://localhost:8080/phpPgAdmin/index.php
28
     * 
29
     * @param string $userName  user name of the admin. 
30
     * @param string $password  password of the admin.
31
     * @param string $loginPageUrl  the login home page url.
32
     * 
33
     * @access public
34
     */
35
    function login($userName, $password, $loginPageUrl)
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...
36
    {
37
    	global $lang, $SERVER;
38
39
		$this->setCookie("PHPCOVERAGE_HOME", $PHP_SIMPLETEST_HOME);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $PHP_SIMPLETEST_HOME seems to be never defined.
Loading history...
40
		$this->get($loginPageUrl, array('server' => $SERVER));
41
		$this->setField('loginUsername', $userName);
42
		$this->setFieldById('loginPassword', $password);
43
		$this->submitFormByid('login_form');
44
		return TRUE;
45
    }
46
     
47
     
48
    /**
49
     * Create a new database by the giving database name and encoding.
50
     * 
51
     * @param string $databaseName The name of the new database.
52
     * @param string $enCoding The encoding mode.
53
     * 
54
     * @access public
55
     */
56
    function createDatabase($databaseName, $enCoding) 
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...
57
    {
58
        global $webUrl;
59
        global $lang, $SERVER;
60
        global $SUPER_USER_NAME;
61
        global $SUPER_USER_PASSWORD;
62
		
63
        $this->login($SUPER_USER_NAME, $SUPER_USER_PASSWORD, 
64
		             "$webUrl/login.php");
65
        $this->get("$webUrl/all_db.php", array('server' => $SERVER));	
66
        $this->clickLink('Create database');
67
         
68
        $this->setField('formName', $databaseName);
69
        $this->setField('formEncoding', $enCoding);
70
        
71
        // Click the button "Create" for creating a database 
72
        // use the specifid name.
73
        $this->clickSubmit($lang['strcreate']);
74
        
75
        return TRUE;
76
    }   
77
     
78
79
    /**
80
     * Drop a exist database by the specify database name.
81
     *
82
     * @param string $databaseName The specify database name which be droped.
83
     * 
84
     * @access public
85
     */
86
    function dropDatabase($databaseName)
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...
87
    {
88
        global $webUrl;
89
        global $lang, $SERVER;
90
        global $SUPER_USER_NAME;
91
        global $SUPER_USER_PASSWORD;
92
		
93
        $this->login($SUPER_USER_NAME, $SUPER_USER_PASSWORD, 
94
                     "$webUrl/login.php");
95
        
96
        $this->get("$webUrl/all_db.php", array('server' => $SERVER));
97
		$this->get("$webUrl/all_db.php", array(
98
			'server' => $SERVER,
99
			'action' => 'confirm_drop',
100
			'subject' => 'database',
101
			'database' => $databaseName,
102
			'dropdatabase' => $databaseName)
103
		);
104
		$this->clickSubmit($lang['strdrop']);
105
        
106
        return TRUE;		
107
    }
108
    
109
    
110
    /**
111
     * Create a new table by the specified conditions.
112
     * 
113
     * Notice: 
114
     * If the value of $fieldNumber equals 3, it would be create a
115
     * table with 3 field like(field name, field type):(field0, text), 
116
     * (field1, text), (field2, text). 
117
     * 
118
     * @param string $databaseName Owner of the new table. paramname.
119
     * @param string $schema the Schema which the new table belong to.
120
     * @param string $tablename The name of the new table.
121
     * @param string $fieldNumber The field number of the new table.
122
     */
123
    function createTable($databaseName, $schema, $tableName, $fieldNumber)
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...
124
    {
125
        global $webUrl;
126
        global $lang, $SERVER;
127
        global $SUPER_USER_NAME;
128
        global $SUPER_USER_PASSWORD;
129
		
130
        $this->login($SUPER_USER_NAME, $SUPER_USER_PASSWORD, 
131
                     "$webUrl/login.php");
132
		
133
		$this->get("$webUrl/tables.php", array(
134
			'server' => $SERVER,
135
			'action' => 'create',
136
			'database' => $databaseName,
137
			'schema' => $schema)
138
		);
139
140
        $this->setField('name', $tableName);
141
        $this->setField('fields', $fieldNumber);
142
        $this->assertTrue($this->setField('spcname', 'pg_default'));
143
        $this->setField('tblcomment', 'Create auto!');
144
145
        // Clicks the button "next >" for inputing the detail information. 
146
        //$this->assertTrue($this->ClickSubmit($lang['strnext']));
147
        // If we do not hardcoded it here, it will cause fail. Encoding issue.
148
		$this->assertTrue($this->ClickSubmit('Next >'));
149
150
        for($ii = 0 ; $ii < $fieldNumber; $ii++) 
151
        {
152
            $field = 'field[' . $ii .']';
153
            $type = 'type[' . $ii . ']';
154
            $array = 'array[' . $ii . ']';
155
            $fieldName = 'field' . $ii;
156
            
157
            // Enter the detail information of the table. 
158
            $this->setField($field, $fieldName);	
159
            $this->setField($type, 'text');
160
            $this->setField($array, '');
161
        }
162
163
        // Click the button "Create" for creating the
164
        // table use the specify conditions.
165
        $this->clickSubmit($lang['strcreate']); 
166
167
        return TRUE;
168
    }
169
    
170
    
171
    /**
172
     * Drop a exist table by the specified table name in a database.
173
     * 
174
     * @param string $databaseName the database which the table content.
175
     * @param string $tableName the table name which wants to delete.
176
     * @param string $schema the schema the table belong.
177
     * 
178
     * @access public
179
     */
180
    function dropTable($databaseName, $tableName, $schema)
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...
181
    {
182
        // Import the global variable.
183
        global $webUrl;
184
        global $lang, $SERVER;
185
        global $SUPER_USER_NAME;
186
        global $SUPER_USER_PASSWORD;
187
		
188
        // Login and trun to the page which list all the 
189
        // table in the database.
190
        $this->login($SUPER_USER_NAME, $SUPER_USER_PASSWORD, 
191
                     "$webUrl/login.php");
192
		
193
		$this->get("$webUrl/tables.php", array(
194
			'server' => $SERVER,
195
			'action' => 'confirm_drop',
196
			'database' => $databaseName,
197
			'schema' => $schema,
198
			'table'	=> $tableName )
199
		); 
200
		           
201
        // Click the button "Drop" for dropping the table from the database.           
202
        $this->clickSubmit($lang['strdrop']);  
203
        
204
        return TRUE;               
205
    }
206
    
207
    
208
    /**
209
     * Logout the system.
210
     */
211
    function logout()
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...
212
    {
213
        global $webUrl;
214
        global $lang;
215
        $this->get("$webUrl/index.php");
216
        
217
        // Select the frame and logout.
218
        $this->setFrameFocus('topbar');
219
        $this->clickLink($lang['strlogout']);
220
        
221
        return TRUE;
222
    }
223
}
224
?>
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...
225