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

UsersTest   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 215
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 215
rs 10
c 0
b 0
f 0
wmc 9
1
<?php
2
/**
3
 * Function area: Server
4
 * Sub function area: Users
5
 *
6
 * @author     Augmentum SpikeSource Team 
7
 * @copyright  2005 by Augmentum, Inc.
8
 */
9
10
// Import the precondition class.
11
require_once('Public/SetPrecondition.php');
12
13
/**
14
 * This class is to test the user management.
15
 * It includes create/drop/alter/list users.
16
 */
17
class UsersTest extends PreconditionSet 
18
{
19
    // Declare the user names which are created, altered and dropped in the class.
20
    private $_superUserName = "superuser";
21
    private $_powerUserName = "poweruser";
22
23
    function setUp()
24
    {
25
        global $webUrl, $SUPER_USER_NAME, $SUPER_USER_PASSWORD, $SERVER;
26
27
        $this->login($SUPER_USER_NAME, $SUPER_USER_PASSWORD, "$webUrl/login.php");
28
 
29
        return TRUE;
30
    }
31
32
    function tearDown()
33
    {
34
        $this->logout();
35
        
36
        return TRUE;
37
    }
38
39
    /*
40
     * TestCaseID: SCU01
41
     * Test to create super user.
42
     */
43
    function testCreateSuper() 
44
    {
45
        global $webUrl;
46
        global $lang, $SERVER;
47
48
        // Turn to the "Create user" page.
49
		$this->assertTrue($this->get("$webUrl/users.php", array('server' => $SERVER)));
50
51
		$this->assertTrue($this->clickLink($lang['strcreateuser']));
52
53
        // Enter information for creating a user.
54
        $this->assertTrue($this->setField('formUsername', $this->_superUserName));
55
        $this->assertTrue($this->setField('formPassword', '123456'));
56
        $this->assertTrue($this->setField('formConfirm', '123456'));
57
        $this->assertTrue($this->setField('formSuper', TRUE));
58
        $this->assertTrue($this->setField('formCreateDB', TRUE));
59
       
60
        // Then submit and verify it.
61
        $this->assertTrue($this->clickSubmit($lang['strcreate']));
62
        $this->assertWantedText($this->_superUserName);
63
        
64
        return TRUE;
65
    }
66
    
67
    /*
68
     * TestCaseID: SCU02
69
     * Test to create power user.
70
     */
71
    function testCreatePower() 
72
    {
73
        global $webUrl;
74
        global $lang, $SERVER;
75
        
76
        // Turn to the "Create user" page.
77
        $this->assertTrue($this->get("$webUrl/users.php", array('server' => $SERVER)));
78
        $this->assertTrue($this->clickLink($lang['strcreateuser']));
79
80
        // Enter information for creating a user.
81
        $this->assertTrue($this->setField('formUsername', $this->_powerUserName));
82
        $this->assertTrue($this->setField('formPassword', '123456'));
83
        $this->assertTrue($this->setField('formConfirm', '123456'));
84
        $this->assertTrue($this->setField('formCreateDB', TRUE));
85
86
        //Then submit and verify it.
87
        $this->assertTrue($this->clickSubmit($lang['strcreate']));
88
        $this->assertWantedText($this->_powerUserName);
89
90
        return TRUE;
91
    }
92
    
93
    /*
94
     * TestCaseID: SLU01
95
     * Test to list all the users.
96
     */ 
97
    function testListUsers() 
98
    {
99
        global $webUrl;
100
        global $SUPER_USER_NAME;
101
        global $POWER_USER_NAME;
102
        global $NORMAL_USER_NAME;
103
        global $lang, $SERVER;
104
        
105
        // Get the users list page and verify it.
106
        $this->assertTrue($this->get("$webUrl/users.php", array('server' => $SERVER)));
107
        $this->assertWantedText($SUPER_USER_NAME);
108
        $this->assertWantedText($POWER_USER_NAME);
109
        $this->assertWantedText($NORMAL_USER_NAME);
110
        
111
        return TRUE;
112
    }
113
    
114
    
115
    /*
116
     * TestCaseID: SAU01
117
     * Test to alter existing user's properties.
118
     */
119
    function testAlter() 
120
    {
121
        global $webUrl;
122
        global $lang, $SERVER;
123
        
124
        // Turn to the "alter user" page.
125
        $this->assertTrue($this->get("$webUrl/users.php"));
126
		$this->assertTrue($this->get("$webUrl/users.php", array(
127
					'action' => 'edit',
128
					'username' => $this->_superUserName,
129
					'server' => $SERVER))
130
		);
131
132
        // Enter the information for altering the user's properties.
133
        $this->assertTrue($this->setField('newname', $this->_superUserName));
134
        $this->assertTrue($this->setField('formPassword', '56789'));
135
        $this->assertTrue($this->setField('formConfirm', '56789'));
136
        $this->assertTrue($this->setField('formSuper', TRUE));
137
        $this->assertTrue($this->setField('formCreateDB', FALSE));
138
139
        // Then submit and verify it.
140
        $this->assertTrue($this->clickSubmit($lang['stralter']));
141
        $this->assertWantedText($this->_superUserName);
142
143
        return TRUE;
144
    }    
145
146
    /*
147
     * TestCaseID: SDU01
148
     * Test to drop existing user.
149
     */
150
    function testDrop() 
151
    {
152
        global $webUrl;
153
        global $lang, $SERVER;
154
        
155
        // Turn to the drop user page..
156
        $this->assertTrue($this->get("$webUrl/users.php", array('server' => $SERVER)));
157
		$this->assertTrue($this->get("$webUrl/users.php", array(
158
				'action' => 'confirm_drop',
159
				'username' => $this->_superUserName,
160
				'server' => $SERVER))
161
		);
162
163
        // Confirm to drop the user and verify it.        
164
        $this->assertTrue($this->clickSubmit($lang['strdrop']));
165
        $this->assertNoUnWantedText($this->_superUserName);
166
167
        return TRUE;
168
    }
169
170
    /*
171
     * TestCaseID: SDU02
172
     * Test to drop existing user when the user is login.
173
     */
174
    function testDropLogin() 
175
    {
176
        global $webUrl;
177
        global $lang, $SERVER;
178
179
        // Create a new browser to login the power user which we want to drop.
180
        $newBrowser = $this->createBrowser();
181
		$newBrowser->get("$webUrl/login.php", array('server' => $SERVER));
182
        $this->assertTrue($newBrowser->setField('loginUsername', $this->_powerUserName));
183
        $this->assertTrue($newBrowser->setFieldById('loginPassword', '123456'));
184
        $this->assertTrue($newBrowser->clickSubmit('Login'));
185
        $this->assertTrue($newBrowser->get("$webUrl/all_db.php", array('server' => $SERVER)));
186
187
        // Turn to the old browser which we login with super user at very beginning.
188
        $this->assertTrue($this->get("$webUrl/users.php", array('server' => $SERVER)));
189
		$this->assertTrue($this->get("$webUrl/users.php", array('action' => 'confirm_drop',
190
				'username' => $this->_powerUserName,
191
				'server' => $SERVER))
192
		);
193
194
        // Confirm to drop the user and verify it.      
195
        $this->assertTrue($this->clickSubmit($lang['strdrop']));
196
        $this->assertNoUnWantedText($this->_powerUserName);
197
198
        // Go back to the power user browser and try to create the database. 
199
        // It will log out and $lang['strloginfailed'] will be displayed in the page.
200
		$this->setBrowser($newBrowser);
201
202
        $this->assertTrue($this->clickLink($lang['strcreatedatabase']));
203
        $this->assertWantedText($lang['strloginfailed']);
204
        
205
        return TRUE;
206
    }
207
208
    /*
209
     * TestCaseID: SDU03
210
     * Test to drop the user self.
211
     */
212
    function testDropSelf() 
213
    {
214
        global $webUrl;
215
        global $SUPER_USER_NAME;
216
        global $lang, $SERVER;
217
        
218
        // Turn to the drop user page..
219
        $this->assertTrue($this->get("$webUrl/users.php", array('server' => $SERVER)));
220
		$this->assertTrue($this->get("$webUrl/users.php", array(
221
				'action' => 'confirm_drop',
222
				'username' => $SUPER_USER_NAME,
223
				'server' => $SERVER	))
224
		);
225
226
        // Confirm to drop the user and verify it.        
227
        $this->assertTrue($this->clickSubmit($lang['strdrop']));
228
        $this->assertWantedText($SUPER_USER_NAME);
229
        $this->assertWantedText($lang['struserdroppedbad']);
230
231
        return TRUE;
232
    }
233
}
234
?>
235