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

OperationsTest.php « classes « test - github.com/phpmyadmin/phpmyadmin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 948c595aafe2bc0752d0dd339aea125c2b838108 (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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
<?php
/**
 * tests for operations
 *
 * @package PhpMyAdmin-test
 */
declare(strict_types=1);

namespace PhpMyAdmin\Tests;

use PhpMyAdmin\Operations;
use PhpMyAdmin\Relation;
use PhpMyAdmin\Theme;
use PHPUnit\Framework\TestCase;
use ReflectionMethod;

/**
 * tests for operations
 *
 * @package PhpMyAdmin-test
 */
class OperationsTest extends TestCase
{
    /**
     * @var Operations
     */
    private $operations;

    /**
     * Set up global environment.
     *
     * @return void
     */
    protected function setUp(): void
    {
        $GLOBALS['server'] = 1;
        $GLOBALS['table'] = 'table';
        $GLOBALS['db'] = 'db';
        $GLOBALS['cfg'] = [
            'ServerDefault' => 1,
            'ActionLinksMode' => 'icons',
            'LinkLengthLimit' => 1000,
        ];
        $GLOBALS['cfg']['DBG']['sql'] = false;
        $GLOBALS['server'] = 1;

        $GLOBALS['db_priv'] = true;
        $GLOBALS['table_priv'] = true;
        $GLOBALS['col_priv'] = true;
        $GLOBALS['proc_priv'] = true;
        $GLOBALS['flush_priv'] = true;
        $GLOBALS['is_reload_priv'] = false;
        $GLOBALS['cfg']['Server']['DisableIS'] = false;

        $relation = new Relation($GLOBALS['dbi']);
        $this->operations = new Operations($GLOBALS['dbi'], $relation);
    }

    /**
     * Test for getHtmlForDatabaseComment
     *
     * @return void
     */
    public function testGetHtmlForDatabaseComment()
    {

        $this->assertRegExp(
            '/.*\/database\/operations(.|[\n])*Database comment.*name="comment"([\n]|.)*/m',
            $this->operations->getHtmlForDatabaseComment('pma')
        );
    }

    /**
     * Test for getHtmlForRenameDatabase
     *
     * @return void
     */
    public function testGetHtmlForRenameDatabase()
    {

        $db_collation = 'db1';
        $html = $this->operations->getHtmlForRenameDatabase('pma', $db_collation);
        $this->assertStringContainsString('index.php?route=/database/operations', $html);
        $this->assertRegExp(
            '/.*db_rename.*Rename database to.*/',
            $html
        );
    }

    /**
     * Test for getHtmlForDropDatabaseLink
     *
     * @return void
     */
    public function testGetHtmlForDropDatabaseLink()
    {

        $this->assertRegExp(
            '/.*DROP.DATABASE.*%2Fdatabase%2Foperations.*Drop the database.*/',
            $this->operations->getHtmlForDropDatabaseLink('pma')
        );
    }

    /**
     * Test for getHtmlForCopyDatabase
     *
     * @return void
     */
    public function testGetHtmlForCopyDatabase()
    {
        $db_collation = 'db1';
        $html = $this->operations->getHtmlForCopyDatabase('pma', $db_collation);
        $this->assertRegExp('/.*\/database\/operations.*/', $html);
        $this->assertRegExp('/.*db_copy.*/', $html);
        $this->assertRegExp('/.*Copy database to.*/', $html);
    }

    /**
     * Test for getHtmlForChangeDatabaseCharset
     *
     * @return void
     */
    public function testGetHtmlForChangeDatabaseCharset()
    {

        $db_collation = 'db1';
        $result = $this->operations->getHtmlForChangeDatabaseCharset('pma', $db_collation);
        $this->assertRegExp(
            '/.*select_db_collation.*Collation.*/m',
            $result
        );
        $this->assertRegExp(
            '/.*\/database\/operations.*/',
            $result
        );
    }

    /**
     * Test for getHtmlForOrderTheTable
     *
     * @return void
     */
    public function testGetHtmlForOrderTheTable()
    {
        $actual = $this->operations->getHtmlForOrderTheTable(
            [
                ['Field' => 'column1'],
                ['Field' => 'column2'],
            ]
        );
        $this->assertStringContainsString(
            'index.php?route=/table/operations',
            $actual
        );
        $this->assertStringContainsString(
            'Alter table order by',
            $actual
        );
        $this->assertStringContainsString(
            'order_order',
            $actual
        );
    }

    /**
     * Test for getHtmlForTableRow
     *
     * @return void
     */
    public function testGetHtmlForTableRow()
    {
        $method = new ReflectionMethod(Operations::class, 'getHtmlForTableRow');
        $method->setAccessible(true);
        $result = $method->invokeArgs($this->operations, ['name', 'lable', 'value']);

        $this->assertEquals(
            '<tr><td class="vmiddle"><label for="name">lable</label></td><td><input type="checkbox" name="name" id="name" value="1"></td></tr>',
            $result
        );
    }

    /**
     * Test for getMaintainActionlink
     *
     * @return void
     */
    public function testGetMaintainActionlink()
    {
        $method = new ReflectionMethod(Operations::class, 'getMaintainActionlink');
        $method->setAccessible(true);
        $result = $method->invokeArgs($this->operations, [
            'post',
            [
                'name' => 'foo',
                'value' => 'bar',
            ],
            [],
            'doclink',
        ]);
        $this->assertStringContainsString(
            'href="index.php?route=/sql&amp;name=foo&amp;value=bar',
            $result
        );
        $this->assertStringContainsString(
            'post',
            $result
        );
        $this->assertStringContainsString(
            'Documentation',
            $result
        );
    }

    /**
     * Test for getHtmlForDeleteDataOrTable
     *
     * @return void
     */
    public function testGetHtmlForDeleteDataOrTable()
    {

        $this->assertRegExp(
            '/.*Delete data or table.*Empty the table.*Delete the table.*/m',
            $this->operations->getHtmlForDeleteDataOrTable(
                ['truncate' => 'foo'],
                ['drop' => 'bar']
            )
        );
    }

    /**
     * Test for getDeleteDataOrTablelink
     *
     * @return void
     */
    public function testGetDeleteDataOrTablelink()
    {

        $this->assertRegExp(
            '/.*TRUNCATE.TABLE.foo.*id_truncate.*Truncate table.*/m',
            $this->operations->getDeleteDataOrTablelink(
                ['sql' => 'TRUNCATE TABLE foo'],
                'TRUNCATE_TABLE',
                'Truncate table',
                'id_truncate'
            )
        );
    }

    /**
     * Test for getHtmlForPartitionMaintenance
     *
     * @return void
     */
    public function testGetHtmlForPartitionMaintenance()
    {
        $html = $this->operations->getHtmlForPartitionMaintenance(
            [
                'partition1',
                'partion2',
            ],
            [
                'param1' => 'foo',
                'param2' => 'bar',
            ]
        );
        $this->assertStringContainsString(
            'action="index.php?route=/table/operations',
            $html
        );
        $this->assertRegExp('/.*ANALYZE.*/', $html);
        $this->assertRegExp('/.*REBUILD.*/', $html);
    }

    /**
     * Test for getHtmlForReferentialIntegrityCheck
     *
     * @return void
     */
    public function testGetHtmlForReferentialIntegrityCheck()
    {
        $GLOBALS['cfg']['blowfish_secret'] = '';
        $_SESSION[' HMAC_secret '] = hash('sha1', 'test');

        $actual = $this->operations->getHtmlForReferentialIntegrityCheck(
            [
                [
                    'foreign_db' => 'db1',
                    'foreign_table' => 'foreign1',
                    'foreign_field' => 'foreign2',
                ],
            ],
            [
                'param1' => 'a',
                'param2' => 'b',
            ]
        );
        $this->assertStringContainsString(
            'Check referential integrity',
            $actual
        );
        $this->assertStringContainsString(
            'href="index.php?route=/sql',
            $actual
        );
    }
}