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

  1. <?php
  2.  
  3. /**
  4.  * API Unit tests for PEAR_PackageFileManager package.
  5.  * 
  6.  * @version    $Id: PEAR_PackageFileManager_File_TestCase_setDir.php,v 1.3 2004/02/07 05:37:35 cellog Exp $
  7.  * @author     Laurent Laville <pear@laurent-laville.org> portions from HTML_CSS
  8.  * @author     Greg Beaver
  9.  * @package    PEAR_PackageFileManager
  10.  */
  11.  
  12. /**
  13.  * @package PEAR_PackageFileManager
  14.  */
  15.  
  16. class PEAR_PackageFileManager_File_TestCase_setDir extends PHPUnit_TestCase
  17. {
  18.     /**
  19.      * A PEAR_PackageFileManager object
  20.      * @var        object
  21.      */
  22.     var $packagexml;
  23.  
  24.     function PEAR_PackageFileManager_File_TestCase_setDir($name)
  25.     {
  26.         $this->PHPUnit_TestCase($name);
  27.     }
  28.  
  29.     function setUp()
  30.     {
  31.         error_reporting(E_ALL);
  32.         $this->errorOccured = false;
  33.         set_error_handler(array(&$this, 'errorHandler'));
  34.  
  35.         $a = false;
  36.         $this->packagexml = new PEAR_PackageFileManager_File($a, array('lang' => 'en'));
  37.         PEAR::pushErrorHandling(PEAR_ERROR_CALLBACK, array(&$this, 'PEARerrorHandler'));
  38.         $this->errorThrown = false;
  39.         $this->_expectedMessage = 'NO ERROR TRIGGERED';
  40.         $this->_expectedCode = -1;
  41.         $this->_testMethod = 'unknown';
  42.     }
  43.  
  44.     function tearDown()
  45.     {
  46.         unset($this->packagexml);
  47.         PEAR::popErrorHandling();
  48.     }
  49.  
  50.     function errorCodeToString($code)
  51.     {
  52.         $codes = array_flip(array(
  53.             'OOPS' => -1,
  54.             'PEAR_PACKAGEFILEMANAGER_NOSTATE' => PEAR_PACKAGEFILEMANAGER_NOSTATE,
  55.             'PEAR_PACKAGEFILEMANAGER_NOVERSION' => PEAR_PACKAGEFILEMANAGER_NOVERSION,
  56.             'PEAR_PACKAGEFILEMANAGER_NOPKGDIR' => PEAR_PACKAGEFILEMANAGER_NOPKGDIR,
  57.             'PEAR_PACKAGEFILEMANAGER_NOBASEDIR' => PEAR_PACKAGEFILEMANAGER_NOBASEDIR,
  58.             'PEAR_PACKAGEFILEMANAGER_GENERATOR_NOTFOUND' => PEAR_PACKAGEFILEMANAGER_GENERATOR_NOTFOUND,
  59.             'PEAR_PACKAGEFILEMANAGER_GENERATOR_NOTFOUND_ANYWHERE' => PEAR_PACKAGEFILEMANAGER_GENERATOR_NOTFOUND_ANYWHERE,
  60.             'PEAR_PACKAGEFILEMANAGER_CANTWRITE_PKGFILE' => PEAR_PACKAGEFILEMANAGER_CANTWRITE_PKGFILE,
  61.             'PEAR_PACKAGEFILEMANAGER_DEST_UNWRITABLE' => PEAR_PACKAGEFILEMANAGER_DEST_UNWRITABLE,
  62.             'PEAR_PACKAGEFILEMANAGER_CANTCOPY_PKGFILE' => PEAR_PACKAGEFILEMANAGER_CANTCOPY_PKGFILE,
  63.             'PEAR_PACKAGEFILEMANAGER_CANTOPEN_TMPPKGFILE' => PEAR_PACKAGEFILEMANAGER_CANTOPEN_TMPPKGFILE,
  64.             'PEAR_PACKAGEFILEMANAGER_PATH_DOESNT_EXIST' => PEAR_PACKAGEFILEMANAGER_PATH_DOESNT_EXIST,
  65.             'PEAR_PACKAGEFILEMANAGER_NOCVSENTRIES' => PEAR_PACKAGEFILEMANAGER_NOCVSENTRIES,
  66.             'PEAR_PACKAGEFILEMANAGER_DIR_DOESNT_EXIST' => PEAR_PACKAGEFILEMANAGER_DIR_DOESNT_EXIST,
  67.             'PEAR_PACKAGEFILEMANAGER_RUN_SETOPTIONS' => PEAR_PACKAGEFILEMANAGER_RUN_SETOPTIONS,
  68.             'PEAR_PACKAGEFILEMANAGER_NOPACKAGE' => PEAR_PACKAGEFILEMANAGER_NOPACKAGE,
  69.             'PEAR_PACKAGEFILEMANAGER_WRONG_MROLE' => PEAR_PACKAGEFILEMANAGER_WRONG_MROLE,
  70.             'PEAR_PACKAGEFILEMANAGER_NOSUMMARY' => PEAR_PACKAGEFILEMANAGER_NOSUMMARY,
  71.             'PEAR_PACKAGEFILEMANAGER_NODESC' => PEAR_PACKAGEFILEMANAGER_NODESC,
  72.             'PEAR_PACKAGEFILEMANAGER_ADD_MAINTAINERS' => PEAR_PACKAGEFILEMANAGER_ADD_MAINTAINERS,
  73.             'PEAR_PACKAGEFILEMANAGER_NO_FILES' => PEAR_PACKAGEFILEMANAGER_NO_FILES,
  74.             'PEAR_PACKAGEFILEMANAGER_IGNORED_EVERYTHING' => PEAR_PACKAGEFILEMANAGER_IGNORED_EVERYTHING,
  75.             'PEAR_PACKAGEFILEMANAGER_INVALID_PACKAGE' => PEAR_PACKAGEFILEMANAGER_INVALID_PACKAGE,
  76.             'PEAR_PACKAGEFILEMANAGER_INVALID_REPLACETYPE' => PEAR_PACKAGEFILEMANAGER_INVALID_REPLACETYPE,
  77.             'PEAR_PACKAGEFILEMANAGER_INVALID_ROLE' => PEAR_PACKAGEFILEMANAGER_INVALID_ROLE,
  78.             'PEAR_PACKAGEFILEMANAGER_PHP_NOT_PACKAGE' => PEAR_PACKAGEFILEMANAGER_PHP_NOT_PACKAGE
  79.         ));
  80.         return $codes[$code];
  81.     }
  82.  
  83.     function _stripWhitespace($str)
  84.     {
  85.         return preg_replace('/\\s+/', '', $str);
  86.     }
  87.  
  88.     function _methodExists($name) 
  89.     {
  90.         if (in_array(strtolower($name), get_class_methods($this->packagexml))) {
  91.             return true;
  92.         }
  93.         $this->assertTrue(false, 'method '. $name . ' not implemented in ' . get_class($this->packagexml));
  94.         return false;
  95.     }
  96.  
  97.     function errorHandler($errno, $errstr, $errfile, $errline) {
  98.         //die("$errstr in $errfile at line $errline: $errstr");
  99.         $this->errorOccured = true;
  100.         $this->assertTrue(false, "$errstr at line $errline, $errfile");
  101.     }
  102.  
  103.     function PEARerrorHandler($error) {
  104.         $this->assertEquals($this->_expectedCode, $error->getCode(),
  105.             $this->_testMethod . ' ' . $this->errorCodeToString($this->_expectedCode)
  106.             . ' actual: ' . $this->errorCodeToString($error->getCode()));
  107.         $this->assertEquals($this->_expectedMessage, $error->getMessage(), $this->_testMethod);
  108.         $this->errorThrown = 'true';
  109.     }
  110.     
  111.     function expectPEARError($method, $msg, $code = null)
  112.     {
  113.         $this->_expectedMessage = $msg;
  114.         $this->_expectedCode = $code;
  115.         $this->_testMethod = $method;
  116.     }
  117.     
  118.     function test_concept()
  119.     {
  120.         if (!$this->_methodExists('_setDir')) {
  121.             return;
  122.         }
  123.         $test = array('my' => array('butt' => array('first')));
  124.         $arr = array('my' => array('other' => array('test')));
  125.         $assert = $this->packagexml->_setDir($arr, $test);
  126.         $this->assertEquals(array('my' => array('other' => array('test'), 'butt' => array('first'))),
  127.             $assert,
  128.             'Wrong contents');
  129.     }
  130. }
  131.  
  132. ?>
  133.