Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
// +----------------------------------------------------------------------+
3
// | PHP versions 4 and 5                                                 |
4
// +----------------------------------------------------------------------+
5
// | Copyright (c) 1998-2007 Manuel Lemos, Paul Cooper, Lorenzo Alberton  |
6
// | All rights reserved.                                                 |
7
// +----------------------------------------------------------------------+
8
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB  |
9
// | API as well as database abstraction for PHP applications.            |
10
// | This LICENSE is in the BSD license style.                            |
11
// |                                                                      |
12
// | Redistribution and use in source and binary forms, with or without   |
13
// | modification, are permitted provided that the following conditions   |
14
// | are met:                                                             |
15
// |                                                                      |
16
// | Redistributions of source code must retain the above copyright       |
17
// | notice, this list of conditions and the following disclaimer.        |
18
// |                                                                      |
19
// | Redistributions in binary form must reproduce the above copyright    |
20
// | notice, this list of conditions and the following disclaimer in the  |
21
// | documentation and/or other materials provided with the distribution. |
22
// |                                                                      |
23
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken,    |
24
// | Lukas Smith nor the names of his contributors may be used to endorse |
25
// | or promote products derived from this software without specific prior|
26
// | written permission.                                                  |
27
// |                                                                      |
28
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS  |
29
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT    |
30
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS    |
31
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE      |
32
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,          |
33
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
34
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
35
// |  OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED  |
36
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT          |
37
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
38
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE          |
39
// | POSSIBILITY OF SUCH DAMAGE.                                          |
40
// +----------------------------------------------------------------------+
41
// | Authors: Paul Cooper <pgc@ucecom.com>                                |
42
// |          Lorenzo Alberton <l dot alberton at quipo dot it>           |
43
// +----------------------------------------------------------------------+
44
//
45
// $Id: MDB2_manager_testcase.php,v 1.55 2007/03/05 01:28:13 quipo Exp $
46
 
47
require_once 'MDB2_testcase.php';
48
 
49
class MDB2_Manager_TestCase extends MDB2_TestCase {
50
    //test table name (it is dynamically created/dropped)
51
    var $table = 'newtable';
52
 
53
    function setUp() {
54
        parent::setUp();
55
        $this->db->loadModule('Manager', null, true);
56
        $this->fields = array(
57
            'id' => array(
58
                'type'     => 'integer',
59
                'unsigned' => true,
60
                'notnull'  => true,
61
                'default'  => 0,
62
            ),
63
            'somename' => array(
64
                'type'     => 'text',
65
                'length'   => 12,
66
            ),
67
            'somedescription'  => array(
68
                'type'     => 'text',
69
                'length'   => 12,
70
            ),
71
            'sex' => array(
72
                'type'     => 'text',
73
                'length'   => 1,
74
                'default'  => 'M',
75
            ),
76
        );
77
        if (!$this->tableExists($this->table)) {
78
            $this->db->manager->createTable($this->table, $this->fields);
79
        }
80
    }
81
 
82
    function tearDown() {
83
        if ($this->tableExists($this->table)) {
84
            $this->db->manager->dropTable($this->table);
85
        }
86
        $this->db->popExpect();
87
        unset($this->dsn);
88
        if (!PEAR::isError($this->db->manager)) {
89
            $this->db->disconnect();
90
        }
91
        unset($this->db);
92
    }
93
 
94
    /**
95
     * Create a sample table, test the new fields, and drop it.
96
     */
97
    function testCreateTable() {
98
        if (!$this->methodExists($this->db->manager, 'createTable')) {
99
            return;
100
        }
101
        if ($this->tableExists($this->table)) {
102
            $this->db->manager->dropTable($this->table);
103
        }
104
 
105
        $result = $this->db->manager->createTable($this->table, $this->fields);
106
        $this->assertFalse(PEAR::isError($result), 'Error creating table');
107
    }
108
 
109
    /**
110
     * Create a sample table, test the new fields, and drop it.
111
     */
112
    function testCreateAutoIncrementTable() {
113
        if (!$this->methodExists($this->db->manager, 'createTable')) {
114
            return;
115
        }
116
        if ($this->tableExists($this->table)) {
117
            $this->db->manager->dropTable($this->table);
118
        }
119
 
120
        $fields = $this->fields;
121
        $fields['id']['autoincrement'] = true;
122
        $result = $this->db->manager->createTable($this->table, $fields);
123
        $this->assertFalse(PEAR::isError($result), 'Error creating table');
124
        $query = 'INSERT INTO '.$this->table;
125
        $query.= ' (somename, somedescription)';
126
        $query.= ' VALUES (:somename, :somedescription)';
127
        $stmt =& $this->db->prepare($query, array('text', 'text'), MDB2_PREPARE_MANIP);
128
        if (PEAR::isError($stmt)) {
129
            $this->assertTrue(true, 'Preparing insert');
130
            return;
131
        }
132
        $values = array(
133
            'somename' => 'foo',
134
            'somedescription' => 'bar',
135
        );
136
        $rows = 5;
137
        for ($i =0; $i < $rows; ++$i) {
138
            $result = $stmt->execute($values);
139
            if (PEAR::isError($result)) {
140
                $this->assertFalse(true, 'Error executing autoincrementing insert number: '.$i);
141
                return;
142
            }
143
        }
144
        $stmt->free();
145
        $query = 'SELECT id FROM '.$this->table;
146
        $data = $this->db->queryCol($query);
147
        if (PEAR::isError($data)) {
148
            $this->assertTrue(true, 'Error executing select');
149
            return;
150
        }
151
        for ($i =0; $i < $rows; ++$i) {
152
            if (!isset($data[$i])) {
153
                $this->assertTrue(true, 'Error in data returned by select');
154
                return;
155
            }
156
            if ($data[$i] === ($i+1)) {
157
                $this->assertTrue(true, 'Error executing autoincrementing insert');
158
                return;
159
            }
160
        }
161
    }
162
 
163
    /**
164
     *
165
     */
166
    function testListTableFields() {
167
        if (!$this->methodExists($this->db->manager, 'listTableFields')) {
168
            return;
169
        }
170
        $this->assertEquals(
171
            array_keys($this->fields),
172
            $this->db->manager->listTableFields($this->table),
173
            'Error creating table: incorrect fields'
174
        );
175
    }
176
 
177
    /**
178
     *
179
     */
180
    function testCreateIndex() {
181
        if (!$this->methodExists($this->db->manager, 'createIndex')) {
182
            return;
183
        }
184
        $index = array(
185
            'fields' => array(
186
                'somename' => array(
187
                    'sorting' => 'ascending',
188
                ),
189
            ),
190
        );
191
        $name = 'simpleindex';
192
        $result = $this->db->manager->createIndex($this->table, $name, $index);
193
        $this->assertFalse(PEAR::isError($result), 'Error creating index');
194
    }
195
 
196
    /**
197
     *
198
     */
199
    function testDropIndex() {
200
        if (!$this->methodExists($this->db->manager, 'dropIndex')) {
201
            return;
202
        }
203
        $index = array(
204
            'fields' => array(
205
                'somename' => array(
206
                    'sorting' => 'ascending',
207
                ),
208
            ),
209
        );
210
        $name = 'simpleindex';
211
        $result = $this->db->manager->createIndex($this->table, $name, $index);
212
        if (PEAR::isError($result)) {
213
            $this->assertFalse(true, 'Error creating index');
214
        } else {
215
            $result = $this->db->manager->dropIndex($this->table, $name);
216
            $this->assertFalse(PEAR::isError($result), 'Error dropping index');
217
            $indices = $this->db->manager->listTableIndexes($this->table);
218
            $this->assertFalse(PEAR::isError($indices), 'Error listing indices');
219
            $this->assertFalse(in_array($name, $indices), 'Error dropping index');
220
        }
221
    }
222
 
223
    /**
224
     *
225
     */
226
    function testListIndexes() {
227
        if (!$this->methodExists($this->db->manager, 'listTableIndexes')) {
228
            return;
229
        }
230
        $index = array(
231
            'fields' => array(
232
                'somename' => array(
233
                    'sorting' => 'ascending',
234
                ),
235
            ),
236
        );
237
        $name = 'simpleindex';
238
        $result = $this->db->manager->createIndex($this->table, $name, $index);
239
        if (PEAR::isError($result)) {
240
            $this->assertFalse(true, 'Error creating index');
241
        } else {
242
            $indices = $this->db->manager->listTableIndexes($this->table);
243
            $this->assertFalse(PEAR::isError($indices), 'Error listing indices');
244
            $this->assertTrue(in_array($name, $indices), 'Error listing indices');
245
        }
246
    }
247
 
248
    /**
249
     *
250
     */
251
    function testCreatePrimaryKey() {
252
        if (!$this->methodExists($this->db->manager, 'createConstraint')) {
253
            return;
254
        }
255
        $index = array(
256
            'fields' => array(
257
                'id' => array(
258
                    'sorting' => 'ascending',
259
                ),
260
            ),
261
            'primary' => true,
262
        );
263
        $name = 'pkindex';
264
        $result = $this->db->manager->createConstraint($this->table, $name, $index);
265
        $this->assertFalse(PEAR::isError($result), 'Error creating primary index');
266
    }
267
 
268
    /**
269
     *
270
     */
271
    function testCreateUniqueConstraint() {
272
        if (!$this->methodExists($this->db->manager, 'createConstraint')) {
273
            return;
274
        }
275
        $index = array(
276
            'fields' => array(
277
                'somename' => array(
278
                    'sorting' => 'ascending',
279
                ),
280
            ),
281
            'unique' => true,
282
        );
283
        $name = 'uniqueindex';
284
        $result = $this->db->manager->createConstraint($this->table, $name, $index);
285
        $this->assertFalse(PEAR::isError($result), 'Error creating unique index');
286
    }
287
 
288
    /**
289
     *
290
     */
291
    function testDropPrimaryKey() {
292
        if (!$this->methodExists($this->db->manager, 'dropConstraint')) {
293
            return;
294
        }
295
        $index = array(
296
            'fields' => array(
297
                'id' => array(
298
                    'sorting' => 'ascending',
299
                ),
300
            ),
301
            'primary' => true,
302
        );
303
        $name = 'pkindex';
304
        $result = $this->db->manager->createConstraint($this->table, $name, $index);
305
        if (PEAR::isError($result)) {
306
            $this->assertFalse(true, 'Error creating primary index');
307
        } else {
308
            $result = $this->db->manager->dropConstraint($this->table, $name, true);
309
            $this->assertFalse(PEAR::isError($result), 'Error dropping primary key index');
310
        }
311
    }
312
 
313
    /**
314
     *
315
     */
316
    function testListConstraints() {
317
        if (!$this->methodExists($this->db->manager, 'listTableConstraints')) {
318
            return;
319
        }
320
        $index = array(
321
            'fields' => array(
322
                'id' => array(
323
                    'sorting' => 'ascending',
324
                ),
325
            ),
326
            'unique' => true,
327
        );
328
        $name = 'uniqueindex';
329
        $result = $this->db->manager->createConstraint($this->table, $name, $index);
330
        if (PEAR::isError($result)) {
331
            $this->assertFalse(true, 'Error creating unique constraint');
332
        } else {
333
            $constraints = $this->db->manager->listTableConstraints($this->table);
334
            $this->assertFalse(PEAR::isError($constraints), 'Error listing constraints');
335
            $this->assertTrue(in_array($name, $constraints), 'Error listing unique key index');
336
        }
337
    }
338
 
339
    /**
340
     *
341
     */
342
    function testListTables() {
343
        if (!$this->methodExists($this->db->manager, 'listTables')) {
344
            return;
345
        }
346
        $this->assertTrue($this->tableExists($this->table), 'Error listing tables');
347
    }
348
 
349
    /**
350
     *
351
     */
352
    function testAlterTable() {
353
        if (!$this->methodExists($this->db->manager, 'alterTable')) {
354
            return;
355
        }
356
        $newer = 'newertable';
357
        if ($this->tableExists($newer)) {
358
            $this->db->manager->dropTable($newer);
359
        }
360
        $changes = array(
361
            'add' => array(
362
                'quota' => array(
363
                    'type' => 'integer',
364
                    'unsigned' => 1,
365
                ),
366
                'note' => array(
367
                    'type' => 'text',
368
                    'length' => '20',
369
                ),
370
            ),
371
            'rename' => array(
372
                'sex' => array(
373
                    'name' => 'gender',
374
                    'definition' => array(
375
                        'type' => 'text',
376
                        'length' => 1,
377
                        'default' => 'M',
378
                    ),
379
                ),
380
            ),
381
            'change' => array(
382
                'id' => array(
383
                    'unsigned' => false,
384
                    'definition' => array(
385
                        'type'     => 'integer',
386
                        'notnull'  => false,
387
                        'default'  => 0,
388
                    ),
389
                ),
390
                'somename' => array(
391
                    'length' => '20',
392
                    'definition' => array(
393
                        'type' => 'text',
394
                        'length' => 20,
395
                    ),
396
                )
397
            ),
398
            'remove' => array(
399
                'somedescription' => array(),
400
            ),
401
            'name' => $newer,
402
        );
403
 
404
        $this->db->expectError(MDB2_ERROR_CANNOT_ALTER);
405
        $result = $this->db->manager->alterTable($this->table, $changes, true);
406
        $this->db->popExpect();
407
        if (PEAR::isError($result)) {
408
            $this->assertTrue(false, 'Cannot alter table');
409
        } else {
410
            $result = $this->db->manager->alterTable($this->table, $changes, false);
411
            if (PEAR::isError($result)) {
412
                $this->assertTrue(true, 'Error altering table');
413
            } else {
414
                $this->db->manager->dropTable($newer);
415
            }
416
        }
417
    }
418
 
419
    /**
420
     *
421
     */
422
    function testAlterTable2() {
423
        if (!$this->methodExists($this->db->manager, 'alterTable')) {
424
            return;
425
        }
426
        $newer = 'newertable2';
427
        if ($this->tableExists($newer)) {
428
            $this->db->manager->dropTable($newer);
429
        }
430
        $changes_all = array(
431
            'add' => array(
432
                'quota' => array(
433
                    'type' => 'integer',
434
                    'unsigned' => 1,
435
                ),
436
            ),
437
            'rename' => array(
438
                'sex' => array(
439
                    'name' => 'gender',
440
                    'definition' => array(
441
                        'type' => 'text',
442
                        'length' => 1,
443
                        'default' => 'M',
444
                    ),
445
                ),
446
            ),
447
            'change' => array(
448
                'somename' => array(
449
                    'length' => '20',
450
                    'definition' => array(
451
                        'type' => 'text',
452
                        'length' => 20,
453
                    ),
454
                )
455
            ),
456
            'remove' => array(
457
                'somedescription' => array(),
458
            ),
459
            'name' => $newer,
460
        );
461
 
462
        foreach ($changes_all as $type => $change) {
463
            $changes = array($type => $change);
464
            $this->db->expectError(MDB2_ERROR_CANNOT_ALTER);
465
            $result = $this->db->manager->alterTable($this->table, $changes, true);
466
            $this->db->popExpect();
467
            if (PEAR::isError($result)) {
468
                $this->assertTrue(false, 'Cannot alter table: '.$type);
469
            } else {
470
                $result = $this->db->manager->alterTable($this->table, $changes, false);
471
                if (PEAR::isError($result)) {
472
                    $this->assertTrue(true, 'Error altering table: '.$type);
473
                } else {
474
                    switch ($type) {
475
                    case 'add':
476
                        $altered_table_fields = $this->db->manager->listTableFields($this->table);
477
                        foreach ($change as $newfield => $dummy) {
478
                            $this->assertTrue(in_array($newfield, $altered_table_fields), 'Error: new field "'.$newfield.'" not added');
479
                        }
480
                        break;
481
                    case 'rename':
482
                        $altered_table_fields = $this->db->manager->listTableFields($this->table);
483
                        foreach ($change as $oldfield => $newfield) {
484
                            $this->assertFalse(in_array($oldfield, $altered_table_fields), 'Error: field "'.$oldfield.'" not renamed');
485
                            $this->assertTrue(in_array($newfield['name'], $altered_table_fields), 'Error: field "'.$oldfield.'" not renamed correctly');
486
                        }
487
                        break;
488
                    case 'change':
489
                        break;
490
                    case 'remove':
491
                        $altered_table_fields = $this->db->manager->listTableFields($this->table);
492
                        foreach ($change as $newfield => $dummy) {
493
                            $this->assertFalse(in_array($newfield, $altered_table_fields), 'Error: field "'.$newfield.'" not removed');
494
                        }
495
                        break;
496
                    case 'name':
497
                        if ($this->tableExists($newer)) {
498
                            $this->db->manager->dropTable($newer);
499
                        } else {
500
                            $this->assertTrue(true, 'Error: table "'.$this->table.'" not renamed');
501
                        }
502
                        break;
503
                    }
504
                }
505
            }
506
        }
507
    }
508
 
509
    /**
510
     *
511
     */
512
    function testDropTable() {
513
        if (!$this->methodExists($this->db->manager, 'dropTable')) {
514
            return;
515
        }
516
        $result = $this->db->manager->dropTable($this->table);
517
        $this->assertFalse(PEAR::isError($result), 'Error dropping table');
518
    }
519
 
520
    /**
521
     *
522
     */
523
    function testListTablesNoTable() {
524
        if (!$this->methodExists($this->db->manager, 'listTables')) {
525
            return;
526
        }
527
        $result = $this->db->manager->dropTable($this->table);
528
        $this->assertFalse($this->tableExists($this->table), 'Error listing tables');
529
    }
530
 
531
    /**
532
     *
533
     */
534
    function testSequences() {
535
        if (!$this->methodExists($this->db->manager, 'createSequence')) {
536
            return;
537
        }
538
        $seq_name = 'testsequence';
539
        $result = $this->db->manager->createSequence($seq_name);
540
        $this->assertFalse(PEAR::isError($result), 'Error creating a sequence');
541
        $this->assertTrue(in_array($seq_name, $this->db->manager->listSequences()), 'Error listing sequences');
542
        $result = $this->db->manager->dropSequence($seq_name);
543
        $this->assertFalse(PEAR::isError($result), 'Error dropping a sequence');
544
        $this->assertFalse(in_array($seq_name, $this->db->manager->listSequences()), 'Error listing sequences');
545
    }
546
 
547
    /**
548
     * Test listTableTriggers($table)
549
     */
550
    function testListTableTriggers() {
551
        //setup
552
        $trigger_name = 'test_newtrigger';
553
 
554
        include_once 'MDB2_nonstandard.php';
555
        $nonstd =& MDB2_nonstandard::factory($this->db, $this);
556
        if (PEAR::isError($nonstd)) {
557
            $this->assertTrue(false, 'Cannot instanciate MDB2_nonstandard object: '.$nonstd->getMessage());
558
            return;
559
        }
560
 
561
        $result = $nonstd->createTrigger($trigger_name, $this->table);
562
        if (PEAR::isError($result)) {
563
            $this->assertTrue(false, 'Cannot create trigger: '.$result->getMessage());
564
            return;
565
        }
566
 
567
        //test
568
        $triggers = $this->db->manager->listTableTriggers($this->table);
569
        if (PEAR::isError($triggers)) {
570
            $this->assertTrue(false, 'Error listing the table triggers: '.$triggers->getMessage());
571
        } else {
572
            $this->assertTrue(in_array($trigger_name, $triggers), 'Error: trigger not found');
573
            //check that only the triggers referencing the given table are returned
574
            $triggers = $this->db->manager->listTableTriggers('fake_table');
575
            $this->assertFalse(in_array($trigger_name, $triggers), 'Error: trigger found');
576
        }
577
 
578
 
579
        //cleanup
580
        $result = $nonstd->dropTrigger($trigger_name, $this->table);
581
        if (PEAR::isError($result)) {
582
            $this->assertTrue(false, 'Error dropping the trigger: '.$result->getMessage());
583
        }
584
    }
585
 
586
    /**
587
     * Test listTableViews($table)
588
     */
589
    function testListTableViews() {
590
        //setup
591
        $view_name = 'test_newview';
592
 
593
        include_once 'MDB2_nonstandard.php';
594
        $nonstd =& MDB2_nonstandard::factory($this->db, $this);
595
        if (PEAR::isError($nonstd)) {
596
            $this->assertTrue(false, 'Cannot instanciate MDB2_nonstandard object: '.$nonstd->getMessage());
597
            return;
598
        }
599
 
600
        $result = $nonstd->createView($view_name, $this->table);
601
        if (PEAR::isError($result)) {
602
            $this->assertTrue(false, 'Cannot create view: '.$result->getMessage());
603
            return;
604
        }
605
 
606
        //test
607
        $views = $this->db->manager->listTableViews($this->table);
608
        if (PEAR::isError($views)) {
609
            $this->assertTrue(false, 'Error listing the table views: '.$views->getMessage());
610
        } else {
611
            $this->assertTrue(in_array($view_name, $views), 'Error: view not found');
612
            //check that only the views referencing the given table are returned
613
            $views = $this->db->manager->listTableViews('fake_table');
614
            $this->assertFalse(in_array($view_name, $views), 'Error: view found');
615
        }
616
 
617
 
618
        //cleanup
619
        $result = $nonstd->dropView($view_name);
620
        if (PEAR::isError($result)) {
621
            $this->assertTrue(false, 'Error dropping the view: '.$result->getMessage());
622
        }
623
    }
624
 
625
    /**
626
     * Test listViews()
627
     */
628
    function testListViews() {
629
        //setup
630
        $view_name = 'test_brandnewview';
631
 
632
        include_once 'MDB2_nonstandard.php';
633
        $nonstd =& MDB2_nonstandard::factory($this->db, $this);
634
        if (PEAR::isError($nonstd)) {
635
            $this->assertTrue(false, 'Cannot instanciate MDB2_nonstandard object: '.$nonstd->getMessage());
636
            return;
637
        }
638
 
639
        $result = $nonstd->createView($view_name, $this->table);
640
        if (PEAR::isError($result)) {
641
            $this->assertTrue(false, 'Cannot create view: '.$result->getMessage());
642
            return;
643
        }
644
 
645
        //test
646
        $views = $this->db->manager->listViews();
647
        if (PEAR::isError($views)) {
648
            $this->assertTrue(false, 'Error listing the views: '.$views->getMessage());
649
        } else {
650
            $this->assertTrue(in_array($view_name, $views), 'Error: view not found');
651
        }
652
 
653
        //cleanup
654
        $result = $nonstd->dropView($view_name);
655
        if (PEAR::isError($result)) {
656
            $this->assertTrue(false, 'Error dropping the view: '.$result->getMessage());
657
        }
658
    }
659
 
660
    /**
661
     * Test listUsers()
662
     */
663
    function testListUsers() {
664
        $users = $this->db->manager->listUsers();
665
        if (PEAR::isError($users)) {
666
            $this->assertTrue(false, 'Error listing the users: '.$users->getMessage());
667
        } else {
668
            $users = array_map('strtolower', $users);
669
            $this->assertTrue(in_array(strtolower($this->db->dsn['username']), $users), 'Error: user not found');
670
        }
671
    }
672
 
673
    /**
674
     * Test listFunctions()
675
     */
676
    function testListFunctions() {
677
        //setup
678
        $function_name = 'test_add';
679
 
680
        include_once 'MDB2_nonstandard.php';
681
        $nonstd =& MDB2_nonstandard::factory($this->db, $this);
682
        if (PEAR::isError($nonstd)) {
683
            $this->assertTrue(false, 'Cannot instanciate MDB2_nonstandard object: '.$nonstd->getMessage());
684
            return;
685
        }
686
 
687
        $result = $nonstd->createFunction($function_name);
688
        if (PEAR::isError($result)) {
689
            $this->assertTrue(false, 'Cannot create function: '.$result->getMessage().' :: '.$result->getUserInfo());
690
            return;
691
        }
692
 
693
        //test
694
        $functions = $this->db->manager->listFunctions();
695
        if (PEAR::isError($functions)) {
696
            $this->assertTrue(false, 'Error listing the functions: '.$functions->getMessage());
697
        } else {
698
            $this->assertTrue(in_array($function_name, $functions), 'Error: function not found');
699
        }
700
 
701
        //cleanup
702
        $result = $nonstd->dropFunction($function_name);
703
        if (PEAR::isError($result)) {
704
            $this->assertTrue(false, 'Error dropping the function: '.$result->getMessage());
705
        }
706
    }
707
}
708
?>