Passed
Branch develop (7ff7f1)
by Felipe
10:16 queued 06:26
created

DatabaseTest::testCreateLATIN1DBInSPT()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 34
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 13
nc 1
nop 0
dl 0
loc 34
rs 8.8571
c 0
b 0
f 0
1
<?php
2
/**
3
 * Function area     : Database.
4
 * Sub Function area : DatabaseManagement.
5
 * 
6
 * @author     Augmentum SpikeSource Team
7
 * @copyright  Copyright (c) 2005 by Augmentum, Inc.
8
 */
9
 
10
// Import the precondition class.
11
if (is_dir('../Public'))
12
{
13
    require_once('../Public/SetPrecondition.php');
14
} 
15
16
/**
17
 * This class is to test the Database management.
18
 */
19
class DatabaseTest extends PreconditionSet
20
{
21
    /**
22
     * Set up the preconditon.
23
     */
24
    function setUp()
25
    {
26
        global $webUrl;
27
        global $SUPER_USER_NAME;
28
        global $SUPER_USER_PASSWORD;
29
        
30
        $this->login($SUPER_USER_NAME, $SUPER_USER_PASSWORD,
31
                     "$webUrl/login.php");
32
                     
33
        return TRUE;                     
34
    } 
35
36
37
    /**
38
     * Release the relational resource.
39
     */
40
    function tearDown()
41
    {
42
        // Logout this system.
43
        $this->logout();
44
45
        return TRUE;
46
    }
47
48
49
    /**
50
     * TestCaseId: DCD001
51
     * This test is used to create a default database with
52
     * "LATIN1" character set.
53
     * 
54
     * Note:  The open database cannot delete by phpPgAdmin,  so this case
55
     * can be run only one time.  It needs to change name of database for 
56
     * next time.
57
     */
58
    function testCreateLATIN1DBInSPT()
59
    {
60
        global $webUrl;
61
        global $lang, $SERVER;
62
63
        // Locate the list page of databases.
64
        $this->assertTrue($this->get("$webUrl/all_db.php"));
65
66
        // Click the hyperlink of "Create Database".
67
		$this->assertTrue($this->get("$webUrl/all_db.php", array(
68
			            'server' => $SERVER,
69
						'action' => 'create'))
70
					);
71
72
        // Fill the form about creating database.
73
        $this->assertTrue($this->setfield('formName', 'spikesource1'));
74
        $this->assertTrue($this->setfield('formEncoding', 'LATIN1'));        
75
        $this->assertTrue($this->setfield('formSpc', 'pg_default'));
76
        
77
        // Click the submit button.
78
        $this->assertTrue($this->clickSubmit($lang['strcreate']));
79
80
        // Verify weather the database has been created.
81
        // Because the phpPgAdmin cannot drop the currently open database.
82
        // this test case may be failed 
83
        // when runing the testcase second time without removing the databases.
84
        $this->assertWantedText($lang['strdatabasecreated']);
85
86
        // Release the resource. 
87
		// XXX In fact, this line doesnot work because of phpPgAdmin's bug.
88
		// "cannot delete opened database"
89
        $this->dropDatabase('spikesource1');
90
91
        return TRUE;
92
    }
93
94
95
    /**
96
     * TestCaseId: DCD002
97
     * This test is used to create a defined database with other
98
     * character set "UNICODE".
99
     * 
100
     * Note:  The open database cannot delete by phpPgAdmin,  so this case
101
     * can be run only one time.  It needs to change name of database for 
102
     * next time.
103
     */
104
    function testCreateUNICODEDBInTester()
105
    {
106
        global $webUrl;
107
        global $lang, $SERVER;
108
        
109
        // Sleep for a while to wait for the template1 to be available
110
        sleep(20);
111
        // Locate the list page of databases.
112
        $this->assertTrue($this->get("$webUrl/all_db.php"));
113
114
        // Click the hyperlink of "Create Database".
115
		$this->assertTrue($this->get("$webUrl/all_db.php", array(
116
			            'server' => $SERVER,
117
						'action' => 'create'))
118
					);
119
120
        // Fill the form about creating database.
121
        $this->assertTrue($this->setfield('formName', 'spikesource2'));
122
        $this->assertTrue($this->setfield('formEncoding', 'UTF8'));
123
        $this->assertTrue($this->setfield('formSpc', 'pg_default'));
124
        
125
        // Click the submit button.
126
        $this->assertTrue($this->clickSubmit($lang['strcreate']));        
127
128
        // Verify weather the database has been created.
129
        // Because the phpPgAdmin cannot drop the currently open database,
130
        // this test case may be failed 
131
        // when runing the testcase second time without removing the databases.
132
        $this->assertWantedText($lang['strdatabasecreated']);
133
134
        // Release the resource.
135
		// XXX In fact, this line doesnot work because of phpPgAdmin's bug (?)
136
		// "cannot delete opened database"
137
        $this->dropDatabase('spikesource2');
138
139
        return TRUE;
140
    }
141
142
143
    /**
144
     * TestCaseId: DDD001
145
     * This test is used to drop a defined database.
146
     *
147
     * This test is faild, because the PostgreSQL cannot support deleteing
148
     * an open database currently.
149
     */
150
    function testDropDatabase()
151
    {
152
        global $webUrl;
153
        global $lang, $SERVER, $DATABASE;
154
155
        // Click the hyperlink of "Create Database".
156
		$this->assertTrue($this->get("$webUrl/all_db.php", array(
157
			            'server' => $SERVER,
158
						'action' => 'confirm_drop',
159
						'subject' => 'database',
160
						'database' => $DATABASE,
161
						'dropdatabase' => $DATABASE ))
162
					);
163
164
        // Click the submit button "Drop" next page.
165
        $this->assertTrue($this->clickSubmit($lang['strdrop']));
166
167
        // Verify weather the database has been droped.
168
        // There is an issue about PostgreSQL.  So let me difine the displayed text.
169
        $this->assertWantedText($lang['strdatabasedropped']);
170
171
        // XXX Release the resource.  The lines below failed in deed. (can't delete opened db)
172
        $this->dropDatabase('SpikeSource1');
173
        $this->dropDatabase('SpikeSource2');
174
175
        return TRUE;
176
    }
177
}
178
179
?>
180