home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 June / ENTER.ISO / files / xampp-win32-1.4.5-installer.exe / xampp / MDB_manager_testcase.php < prev    next >
Encoding:
PHP Script  |  2004-03-24  |  7.4 KB  |  166 lines

  1. <?php
  2. // +----------------------------------------------------------------------+
  3. // | PHP Version 4                                                        |
  4. // +----------------------------------------------------------------------+
  5. // | Copyright (c) 1998-2004 Manuel Lemos, Paul Cooper                    |
  6. // | All rights reserved.                                                 |
  7. // +----------------------------------------------------------------------+
  8. // | MDB 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. // | Author: Paul Cooper <pgc@ucecom.com>                                 |
  42. // +----------------------------------------------------------------------+
  43. //
  44. // $Id: MDB_manager_testcase.php,v 1.9.4.3 2004/01/08 13:43:00 lsmith Exp $
  45.  
  46. class MDB_Manager_TestCase extends PHPUnit_TestCase {
  47.     //contains the dsn of the database we are testing
  48.     var $dsn;
  49.     //contains the options that should be used during testing
  50.     var $options;
  51.     //contains the name of the database we are testing
  52.     var $database;
  53.     //contains the MDB_Manager object of the db once we have connected
  54.     var $manager;
  55.     //contains the name of the driver_test schema
  56.     var $driver_input_file = 'driver_test.schema';
  57.     //contains the name of the lob_test schema
  58.     var $lob_input_file = 'lob_test.schema';
  59.     //contains the name of the extension to use for backup schemas
  60.     var $backup_extension = '.before';
  61.  
  62.     function MDB_Manager_Test($name) {
  63.         $this->PHPUnit_TestCase($name);
  64.     }
  65.  
  66.     function setUp() {
  67.         $this->dsn      = $GLOBALS['dsn'];
  68.         $this->options  = $GLOBALS['options'];
  69.         $this->database = $GLOBALS['database'];
  70.         $backup_file = $this->driver_input_file.$this->backup_extension;
  71.         if (file_exists($backup_file)) {
  72.             unlink($backup_file);
  73.         }
  74.         $backup_file = $this->lob_input_file.$this->backup_extension;
  75.         if (file_exists($backup_file)) {
  76.             unlink($backup_file);
  77.         }
  78.         $this->manager =& new MDB_Manager;
  79.         $this->manager->connect($this->dsn, $this->options);
  80.         if (MDB::isError($this->manager)) {
  81.             $this->assertTrue(false, 'Could not connect to manager in setUp');
  82.             exit;
  83.         }
  84.         $this->fields = array(
  85.             'user_name',
  86.             'user_password',
  87.             'subscribed',
  88.             'user_id',
  89.             'quota',
  90.             'weight',
  91.             'access_date',
  92.             'access_time',
  93.             'approved'
  94.         );
  95.  
  96.         $this->types = array(
  97.            'text',
  98.            'text',
  99.            'boolean',
  100.            'integer',
  101.            'decimal',
  102.            'float',
  103.            'date',
  104.            'time',
  105.            'timestamp'
  106.        );
  107.     }
  108.  
  109.     function tearDown() {
  110.         unset($this->dsn);
  111.         if (!MDB::isError($this->manager)) {
  112.             $this->manager->disconnect();
  113.         }
  114.         unset($this->manager);
  115.     }
  116.  
  117.     function methodExists(&$class, $name) {
  118.         if (is_object($class)
  119.             && array_key_exists(strtolower($name), array_flip(get_class_methods($class)))
  120.         ) {
  121.             return true;
  122.         }
  123.         $this->assertTrue(false, 'method '. $name.' not implemented in '.get_class($class));
  124.         return false;
  125.     }
  126.  
  127.     function testCreateDatabase() {
  128.         if (!$this->methodExists($this->manager->database, 'dropDatabase')) {
  129.             return;
  130.         }
  131.         $result = $this->manager->database->dropDatabase($this->database);
  132.         if (!MDB::isError($result) || $result->getCode() != MDB_ERROR_UNSUPPORTED) {
  133.             if (!$this->methodExists($this->manager, 'updateDatabase')) {
  134.                 return;
  135.             }
  136.             $result = $this->manager->updateDatabase($this->driver_input_file, false, array('create' =>'1', 'name' => $this->database));
  137.             if(!MDB::isError($result)) {
  138.                 $result = $this->manager->updateDatabase($this->lob_input_file, false, array('create' =>'0', 'name' => $this->database));
  139.             }
  140.             $this->assertFalse(MDB::isError($result), 'Error creating database');
  141.         } else if ($result->getCode() == MDB_ERROR_UNSUPPORTED) {
  142.             $this->assertTrue(false, 'Database creation not supported');
  143.         }
  144.     }
  145.  
  146.     function testUpdateDatabase() {
  147.         if (!$this->methodExists($this->manager, 'updateDatabase')) {
  148.             return;
  149.         }
  150.         $backup_file = $this->driver_input_file.$this->backup_extension;
  151.         if (!file_exists($backup_file)) {
  152.             copy($this->driver_input_file, $backup_file);
  153.         }
  154.         $result = $this->manager->updateDatabase($this->driver_input_file, $backup_file, array('create' =>'0', 'name' =>$this->database));
  155.         if(!MDB::isError($result)) {
  156.             $backup_file = $this->lob_input_file.$this->backup_extension;
  157.             if (!file_exists($backup_file)) {
  158.                 copy($this->lob_input_file, $backup_file);
  159.             }
  160.             $result = $this->manager->updateDatabase($this->lob_input_file, $backup_file, array('create' =>'0', 'name' => $this->database));
  161.         }
  162.         $this->assertFalse(MDB::isError($result), 'Error updating database');
  163.     }
  164. }
  165.  
  166. ?>