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

DBIMysql_test.php « dbi « classes « test - github.com/phpmyadmin/phpmyadmin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9183165a6686f1ac86c136c5ccaf4b84554f5efd (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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
<?php
/**
 * Tests for PMA_DBI_Mysql class
 *
 * @package PhpMyAdmin-test
 */

/*
 * Include to test.
 */
require_once 'libraries/Util.class.php';
require_once 'libraries/relation.lib.php';
require_once 'libraries/url_generating.lib.php';
require_once 'libraries/php-gettext/gettext.inc';
require_once 'libraries/Index.class.php';
require_once 'libraries/database_interface.inc.php';
require_once 'libraries/dbi/DBIMysql.class.php';

/**
 * Tests for PMA_DBI_Mysql class
 *
 * @package PhpMyAdmin-test
 */
class PMA_DBI_Mysql_Test extends PHPUnit_Framework_TestCase
{
    /**
     * @access protected
     */
    protected $object;

    /**
     * Sets up the fixture, for example, opens a network connection.
     * This method is called before a test is executed.
     *
     * @access protected
     * @return void
     */
    protected function setUp()
    {
        if (! extension_loaded('mysql')) {
            $this->markTestSkipped('The MySQL extension is not available.');
        }
        $GLOBALS['cfg']['Server']['ssl'] = true;
        $GLOBALS['cfg']['PersistentConnections'] = false;
        $GLOBALS['cfg']['Server']['compress'] = true;
        $this->object = new PMA_DBI_Mysql();
    }

    /**
     * Tears down the fixture, for example, closes a network connection.
     * This method is called after a test is executed.
     *
     * @access protected
     * @return void
     */
    protected function tearDown()
    {
        unset($this->object);
    }

    /**
     * Test for realMultiQuery
     *
     * @return void
     *
     * @group medium
     */
    public function testRealMultiQuery()
    {
        //PHP's 'mysql' extension does not support multi_queries
        $this->assertEquals(
            false,
            $this->object->realMultiQuery(null, "select * from PMA")
        );
    }

    /**
     * Test for mysql related functions, using runkit_function_redefine
     *
     * @return void
     *
     * @group medium
     */
    public function testMysqlDBI()
    {
        if (! PMA_HAS_RUNKIT) {
            $this->markTestSkipped("Cannot redefine function");
        }
        //FOR UT, we just test the right mysql client API is called
        runkit_function_redefine('mysql_pconnect', '', 'return "mysql_pconnect";');
        runkit_function_redefine('mysql_connect', '', 'return "mysql_connect";');
        runkit_function_redefine('mysql_query', '', 'return "mysql_query";');
        runkit_function_redefine(
            'mysql_fetch_array', '', 'return "mysql_fetch_array";'
        );
        runkit_function_redefine(
            'mysql_data_seek', '', 'return "mysql_data_seek";'
        );
        runkit_function_redefine(
            'mysql_get_host_info', '', 'return "mysql_get_host_info";'
        );
        runkit_function_redefine(
            'mysql_get_proto_info', '', 'return "mysql_get_proto_info";'
        );
        runkit_function_redefine(
            'mysql_field_flags', '', 'return "mysql_field_flags";'
        );
        runkit_function_redefine(
            'mysql_field_name', '', 'return "mysql_field_name";'
        );
        runkit_function_redefine(
            'mysql_field_len', '', 'return "mysql_field_len";'
        );
        runkit_function_redefine(
            'mysql_num_fields', '', 'return "mysql_num_fields";'
        );
        runkit_function_redefine(
            'mysql_affected_rows', '', 'return "mysql_affected_rows";'
        );

        //test for fieldFlags
        $result = array("table1", "table2");
        $ret = $this->object->numFields($result);
        $this->assertEquals(
            'mysql_num_fields',
            $ret
        );

        //test for fetchRow
        $result = array("table1", "table2");
        $ret = $this->object->fetchRow($result);
        $this->assertEquals(
            'mysql_fetch_array',
            $ret
        );

        //test for fetchRow
        $result = array("table1", "table2");
        $ret = $this->object->fetchAssoc($result);
        $this->assertEquals(
            'mysql_fetch_array',
            $ret
        );

        //test for affectedRows
        $link = "PMA_link";
        $get_from_cache = false;
        $ret = $this->object->affectedRows($link, $get_from_cache);
        $this->assertEquals(
            "mysql_affected_rows",
            $ret
        );

        //test for connect
        $user = 'PMA_user';
        $password = 'PMA_password';
        $is_controluser = false;
        $server = array(
            'port' => 8080,
            'socket' => 123,
            'host' => 'locahost',
        );
        $auxiliary_connection = true;

        //test for connect
        $ret = $this->object->connect(
            $user, $password, $is_controluser,
            $server, $auxiliary_connection
        );
        $this->assertEquals(
            'mysql_connect',
            $ret
        );

        $GLOBALS['cfg']['PersistentConnections'] = true;
        $ret = $this->object->connect(
            $user, $password, $is_controluser,
            $server, $auxiliary_connection
        );
        $this->assertEquals(
            'mysql_pconnect',
            $ret
        );

        //test for realQuery
        $query = 'select * from DBI';
        $link = $ret;
        $options = 0;
        $ret = $this->object->realQuery($query, $link, $options);
        $this->assertEquals(
            'mysql_query',
            $ret
        );

        //test for fetchArray
        $result = $ret;
        $ret = $this->object->fetchArray($result);
        $this->assertEquals(
            'mysql_fetch_array',
            $ret
        );

        //test for dataSeek
        $result = $ret;
        $offset = 12;
        $ret = $this->object->dataSeek($result, $offset);
        $this->assertEquals(
            'mysql_data_seek',
            $ret
        );

        //test for getHostInfo
        $ret = $this->object->getHostInfo($ret);
        $this->assertEquals(
            'mysql_get_host_info',
            $ret
        );

        //test for getProtoInfo
        $ret = $this->object->getProtoInfo($ret);
        $this->assertEquals(
            'mysql_get_proto_info',
            $ret
        );

        //test for fieldLen
        $ret = $this->object->fieldLen($ret, $offset);
        $this->assertEquals(
            'mysql_field_len',
            $ret
        );

        //test for fieldName
        $ret = $this->object->fieldName($ret, $offset);
        $this->assertEquals(
            'mysql_field_name',
            $ret
        );

        //test for fieldFlags
        $ret = $this->object->fieldFlags($ret, $offset);
        $this->assertEquals(
            'mysql_field_flags',
            $ret
        );
    }

    /**
     * Test for selectDb
     *
     * @return void
     *
     * @group medium
     */
    public function testSelectDb()
    {
        $this->markTestIncomplete('Not testing anything');
        //$link is empty
        $GLOBALS['userlink'] = null;
        $this->assertEquals(
            false,
            $this->object->selectDb("PMA", null)
        );
    }

    /**
     * Test for moreResults
     *
     * @return void
     *
     * @group medium
     */
    public function testMoreResults()
    {
        //PHP's 'mysql' extension does not support multi_queries
        $this->assertEquals(
            false,
            $this->object->moreResults(null)
        );
        //PHP's 'mysql' extension does not support multi_queries
        $this->assertEquals(
            false,
            $this->object->nextResult(null)
        );
    }

    /**
     * Test for getClientInfo
     *
     * @return void
     *
     * @group medium
     */
    public function testGetClientInfo()
    {
        $this->assertEquals(
            mysql_get_client_info(),
            $this->object->getClientInfo()
        );
    }

    /**
     * Test for numRows
     *
     * @return void
     *
     * @group medium
     */
    public function testNumRows()
    {
        $this->assertEquals(
            false,
            $this->object->numRows(true)
        );
    }

    /**
     * Test for storeResult
     *
     * @return void
     *
     * @group medium
     */
    public function testStoreResult()
    {
        $this->assertEquals(
            false,
            $this->object->storeResult(null)
        );
    }
}