Welcome to mirror list, hosted at ThFree Co, Russian Federation.

TableSpacesTest.php « Server « testcase « simpletest « tests - github.com/HuasoFoundries/phpPgAdmin6.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 76601c9ac2f56e6d13104246c78d52b12718f288 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
<?php

/**
 * PHPPgAdmin v6.0.0-beta.51
 */

// Import the precondition class.
if (is_dir('../Public')) {
    require_once '../Public/SetPrecondition.php';
}

/**
 * This class is to test the tablespace management.
 * It includes create/drop/alter/list tablespaces.
 *
 * @coversNothing
 */
class TableSpacesTest extends PreconditionSet
{
    // Declare member variables for the table space name and location.
    private $_tableSpaceName = 'TestTableSpace';
    private $_location;

    public function setUp()
    {
        global $webUrl;
        global $SUPER_USER_NAME;
        global $SUPER_USER_PASSWORD;
        global $lang;

        $this->login($SUPER_USER_NAME, $SUPER_USER_PASSWORD, "${webUrl}/login");

        return true;
    }

    public function tearDown()
    {
        $this->logout();

        return true;
    }

    /*
     * TestCaseID: SCT01
     * Test to create tablespace.
     * XXX: Your PgSQL admin user must own data/TableSpace
     */
    public function testCreate()
    {
        global $webUrl;
        global $POWER_USER_NAME;
        global $lang, $SERVER;
        $this->_location = getcwd().'/data/TableSpace';

        // Turn to the create tablespace page.
        $this->assertTrue($this->get("${webUrl}/tablespaces", ['server' => $SERVER]));
        $this->assertTrue($this->clickLink($lang['strcreatetablespace']));

        // Enter information for creating a tablespace.
        $this->assertTrue($this->setField('formSpcname', $this->_tableSpaceName));
        $this->assertTrue($this->setField('formOwner', $POWER_USER_NAME));
        $this->assertTrue($this->setField('formLoc', $this->_location));

        // Then submit and verify it.
        $this->assertTrue($this->clickSubmit($lang['strcreate']));
        $this->assertText($lang['strtablespacecreated']);

        return true;
    }

    /*
     * TestCaseID: SAT01
     * Test to alter existing tablespace's properties.
     */
    public function testAlter()
    {
        global $webUrl;
        global $NORMAL_USER_NAME;
        global $lang, $SERVER;

        // Turn to the alter tablespace page.
        $this->assertTrue($this->get("${webUrl}/tablespaces", ['server' => $SERVER]));
        $this->assertTrue(
            $this->get("${webUrl}/tablespaces", [
                'server'     => $SERVER,
                'action'     => 'edit',
                'tablespace' => $this->_tableSpaceName, ])
        );

        // Enter information for altering the tableSpace's properties.
        $this->assertTrue($this->setField('name', $this->_tableSpaceName));
        $this->assertTrue($this->setField('owner', $NORMAL_USER_NAME));

        // Then submit and verify it.
        $this->assertTrue($this->clickSubmit($lang['stralter']));
        $this->assertText($lang['strtablespacealtered']);

        return true;
    }

    /*
     * TestCaseID: SPT01
     * Test to grant privileges for tablespace.
     */
    public function testGrantPrivilege()
    {
        global $webUrl;
        global $NORMAL_USER_NAME;
        global $lang, $SERVER;

        // Turn to the privileges page.
        $this->assertTrue($this->get("${webUrl}/privileges", ['server' => $SERVER]));
        $this->assertTrue(
            $this->get("${webUrl}/privileges", [
                'server'     => $SERVER,
                'subject'    => 'tablespace',
                'tablespace' => $this->_tableSpaceName, ])
        );

        // Grant with no privileges selected.
        $this->assertTrue($this->clickLink($lang['strgrant']));
        $this->assertTrue($this->setField('username[]', [$NORMAL_USER_NAME]));
        $this->assertTrue($this->setField('privilege[CREATE]', true));
        $this->assertTrue($this->setField('privilege[ALL PRIVILEGES]', true));
        $this->assertTrue($this->setField('grantoption', true));

        // Then submit and verifiy it.
        $this->assertTrue($this->clickSubmit($lang['strgrant']));
        $this->assertText($lang['strgranted']);
        $this->assertText($NORMAL_USER_NAME);

        return true;
    }

    /*
     * TestCaseID: SPT02
     * Test to revoke privileges for tablespace.
     */
    public function testRevokePrivilege()
    {
        global $webUrl;
        global $NORMAL_USER_NAME;
        global $lang, $SERVER;

        // Turn to the privileges page.
        $this->assertTrue($this->get("${webUrl}/privileges", ['server' => $SERVER]));
        $this->assertTrue(
            $this->get("${webUrl}/privileges", [
                'server'     => $SERVER,
                'subject'    => 'tablespace',
                'tablespace' => $this->_tableSpaceName, ])
        );

        // Revoke with no users selected.
        $this->assertTrue($this->clickLink($lang['strrevoke']));
        $this->assertTrue($this->setField('username[]', [$NORMAL_USER_NAME]));
        $this->assertTrue($this->setField('privilege[ALL PRIVILEGES]', true));

        // Then submit and verify it.
        $this->assertTrue($this->clickSubmit($lang['strrevoke']));
        $this->assertText($lang['strgranted']);
        $this->assertNoText($NORMAL_USER_NAME);

        return true;
    }

    /*
     * TestCaseID: SPT03
     * Test to grant privilege with no privilege selected for tablespace.
     */
    public function testGrantNoPrivilege()
    {
        global $webUrl;
        global $NORMAL_USER_NAME;
        global $lang, $SERVER;

        // Turn to the privileges page.
        $this->assertTrue($this->get("${webUrl}/privileges", ['server' => $SERVER]));
        $this->assertTrue(
            $this->get("${webUrl}/privileges", [
                'server'     => $SERVER,
                'subject'    => 'tablespace',
                'tablespace' => $this->_tableSpaceName, ])
        );

        // Grant whit no privilege selected.
        $this->assertTrue($this->clickLink($lang['strgrant']));
        $this->assertTrue($this->setField('username[]', [$NORMAL_USER_NAME]));

        // Then submit and verify it.
        $this->assertTrue($this->clickSubmit($lang['strgrant']));
        $this->assertText($lang['strgrantbad']);

        return true;
    }

    /*
     * TestCaseID: SPT04
     * Test to revoke privileges with no user selected for tablespace.
     */
    public function testRevokeNoUser()
    {
        global $webUrl;
        global $NORMAL_USER_NAME;
        global $lang, $SERVER;

        // Turn to the privileges page.
        $this->assertTrue($this->get("${webUrl}/privileges", ['server' => $SERVER]));
        $this->assertTrue(
            $this->get("${webUrl}/privileges", [
                'server'     => $SERVER,
                'subject'    => 'tablespace',
                'tablespace' => $this->_tableSpaceName, ])
        );

        // Revoke whit no users selected.
        $this->assertTrue($this->clickLink($lang['strrevoke']));

        // Then submit and verify it.
        $this->assertTrue($this->clickSubmit($lang['strrevoke']));
        $this->assertText($lang['strgrantbad']);

        return true;
    }

    /*
     * TestCaseID: SDT01
     * Test to drop existing tablespace.
     */
    public function testDrop()
    {
        global $webUrl;
        global $lang, $SERVER;

        // Turn to the drop user page.
        $this->assertTrue($this->get("${webUrl}/tablespaces", ['server' => $SERVER]));
        $this->assertTrue(
            $this->get("${webUrl}/tablespaces", [
                'server'     => $SERVER,
                'action'     => 'confirm_drop',
                'tablespace' => $this->_tableSpaceName, ])
        );

        // Confirm to drop the user and verify it.
        $this->assertTrue($this->clickSubmit($lang['strdrop']));
        $this->assertText($lang['strtablespacedropped']);
        $this->assertNoText($this->_tableSpaceName);

        return true;
    }
}