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

DBIDrizzle_test.php « dbi « classes « test - github.com/phpmyadmin/phpmyadmin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3236667320910cb8f9e4b65f73244fff3c8f39b7 (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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
<?php
/**
 * Tests for PMA_DBI_Drizzle class
 *
 * @package PhpMyAdmin-test
 */

/*
 * Include to test and mock Drizzle class.
 */
/**
 * Drizzle for Mock drizzle class
 *
 * this class is for Mock Drizzle
 *
 * @package PhpMyAdmin-test
 */
if (!defined("DRIZZLE_CAPABILITIES_COMPRESS")) {
    define("DRIZZLE_CAPABILITIES_COMPRESS", 2);
}

/**
 * function to return drizzle_version
 *
 * @return string
 */
function drizzle_version()
{
    return "1.0.0";
}

require_once 'libraries/Util.class.php';
require_once 'libraries/relation.lib.php';
require_once 'libraries/url_generating.lib.php';
require_once 'libraries/sqlparser.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/DBIDrizzle.class.php';
require_once 'libraries/Theme.class.php';

/**
 * Tests for PMA_DBI_Drizzle class
 *
 * @package PhpMyAdmin-test
 */
class PMA_DBI_Drizzle_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()
    {
        $GLOBALS['cfg']['Server']['host'] = "localhost";
        $GLOBALS['cfg']['Server']['socket'] = "socket";
        $GLOBALS['cfg']['Server']['port'] = 4080;
        $GLOBALS['cfg']['Server']['connect_type'] = "http";
        $GLOBALS['cfg']['PersistentConnections'] = false;
        $GLOBALS['cfg']['Server']['compress'] = true;
        $GLOBALS['cfg']['Server']['ssl'] = false;
        $GLOBALS['cfg']['MaxCharactersInDisplayedSQL'] = 1000;
        $GLOBALS['cfg']['ActionLinksMode'] = "both";
        $GLOBALS['cfg']['DefaultTabDatabase'] = 'db_structure.php';
        $GLOBALS['pmaThemeImage'] = 'image';

        //$_SESSION
        $_SESSION['PMA_Theme'] = PMA_Theme::load('./themes/pmahomme');
        $_SESSION['PMA_Theme'] = new PMA_Theme();

        $this->object = new PMA_DBI_Drizzle();
    }

    /**
     * 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()
    {
        //does not support multi_queries
        $this->assertEquals(
            false,
            $this->object->realMultiQuery(null, "select * from PMA")
        );
    }

    /**
     * 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 testrMoreResults()
    {
        //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 testrGetClientInfo()
    {
        $drizzle_info = 'libdrizzle (Drizzle ' . drizzle_version() . ')';
        $this->assertEquals(
            $drizzle_info,
            $this->object->getClientInfo()
        );
    }

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

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

    /**
     * Test for connect
     *
     * @return void
     *
     * @group medium
     */
    public function testDBIFunction()
    {
        $user = "PMA_user";
        $password = "pma_password";
        $server = null;

        //$server = null;
        $link = $this->object->connect($user, $password);
        $this->assertEquals(
            "DrizzleCon_addUds",
            $link->getType()
        );

        //$server['host'] = 'host'
        $server['host'] = 'host';
        $link = $this->object->connect($user, $password);
        $this->assertEquals(
            "DrizzleCon_addUds",
            $link->getType()
        );

        //selectDb
        $dbname = "dbname";
        $this->assertEquals(
            "selectDb" . $dbname,
            $this->object->selectDb($dbname, $link)
        );

        //realQuery
        $query = "query";
        $options = false;
        $this->assertEquals(
            "query" . $query,
            $this->object->realQuery($query, $link, $options)
        );

        //fetchArray
        $result = $link;
        $this->assertEquals(
            "fetchRow " . PMA_Drizzle::FETCH_BOTH,
            $this->object->fetchArray($result)
        );

        //fetchAssoc
        $result = $link;
        $this->assertEquals(
            "fetchRow " . PMA_Drizzle::FETCH_ASSOC,
            $this->object->fetchAssoc($result)
        );

        //fetchRow
        $result = $link;
        $this->assertEquals(
            "fetchRow " . PMA_Drizzle::FETCH_NUM,
            $this->object->fetchRow($result)
        );

        //dataSeek
        $result = $link;
        $offset = 10;
        $this->assertEquals(
            "seek" . $offset,
            $this->object->dataSeek($result, 10)
        );

        //numRows
        $result = $link;
        $this->assertEquals(
            "numRows",
            $this->object->numRows($result)
        );

        //numFields
        $result = $link;
        $this->assertEquals(
            "numColumns",
            $this->object->numFields($result)
        );

    }
}

/**
 * Mock class for Drizzle
 *
 * @package PhpMyAdmin-test
 */
class Drizzle
{
    /**
     * Constructor
     */
    public function __construct()
    {

    }

    /**
     * Creates a new connection using unix domain socket
     *
     * @param string  $uds      socket
     * @param string  $user     username
     * @param string  $password password
     * @param string  $db       database name
     * @param integer $options  connection options
     *
     * @return Mock_Con
     */
    public function addUds($uds, $user, $password, $db, $options)
    {
        return new Mock_Con("DrizzleCon_addUds");
    }

    /**
     * Creates a new database connection using TCP
     *
     * @param string  $host     Drizzle host
     * @param integer $port     Drizzle port
     * @param string  $user     username
     * @param string  $password password
     * @param string  $db       database name
     * @param integer $options  connection options
     *
     * @return Mock_Con
     */
    public function addTcp($host, $port, $user, $password, $db, $options)
    {
        return new Mock_Con("DrizzleCon_addTcp");
    }

}

/**
 * Mock class for Mock_Connection
 *
 * @package PhpMyAdmin-test
 */
class Mock_Con
{
    var $type;

    /**
     * Constructor
     *
     * @param string $type type
     */
    public function __construct($type)
    {
        $this->type = $type;
    }


    /**
     * Creates a new database connection using TCP
     *
     * @return Mock_Con
     */
    public function getType()
    {
        return $this->type;
    }

    /**
     * selectDb
     *
     * @param string $dbname database name
     *
     * @return string
     */
    public function selectDb($dbname)
    {
        return "selectDb" . $dbname;
    }

    /**
     * query
     *
     * @param string $query       query string
     * @param int    $buffer_mode buffer mode
     *
     * @return string
     */
    public function query($query, $buffer_mode)
    {
        return "query" . $query;
    }

    /**
     * fetchRow
     *
     * @param string $mode fetch mode
     *
     * @return string
     */
    public function fetchRow($mode)
    {
        return "fetchRow " . $mode;
    }

    /**
     * $offset
     *
     * @param int $offset offset
     *
     * @return string
     */
    public function seek($offset)
    {
        return "seek" . $offset;
    }

    /**
     * numRows
     *
     * @return string
     */
    public function numRows()
    {
        return "numRows";
    }

    /**
     * numColumns
     *
     * @return string
     */
    public function numColumns()
    {
        return "numColumns";
    }
}