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

  1. <?php
  2.  
  3. /**
  4.  * API Unit tests for PEAR_PackageFileManager package.
  5.  * 
  6.  * @version    $Id: PEAR_PackageFileManager_TestCase_getExistingPackageXML.php,v 1.5 2004/02/07 04:59:54 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_TestCase_getExistingPackageXML extends PHPUnit_TestCase
  17. {
  18.     /**
  19.      * A PEAR_PackageFileManager object
  20.      * @var        object
  21.      */
  22.     var $packagexml;
  23.  
  24.     function PEAR_PackageFileManager_TestCase_getExistingPackageXML($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.         $this->packagexml = new PEAR_PackageFileManager;
  36.         PEAR::pushErrorHandling(PEAR_ERROR_CALLBACK, array(&$this, 'PEARerrorHandler'));
  37.         $this->errorThrown = false;
  38.         $this->_expectedMessage = 'NO ERROR TRIGGERED';
  39.         $this->_expectedCode = -1;
  40.         $this->_testMethod = 'unknown';
  41.     }
  42.  
  43.     function tearDown()
  44.     {
  45.         unset($this->packagexml);
  46.         PEAR::popErrorHandling();
  47.     }
  48.  
  49.     function errorCodeToString($code)
  50.     {
  51.         $codes = array_flip(array(
  52.             'OOPS' => -1,
  53.             'PEAR_PACKAGEFILEMANAGER_NOSTATE' => PEAR_PACKAGEFILEMANAGER_NOSTATE,
  54.             'PEAR_PACKAGEFILEMANAGER_NOVERSION' => PEAR_PACKAGEFILEMANAGER_NOVERSION,
  55.             'PEAR_PACKAGEFILEMANAGER_NOPKGDIR' => PEAR_PACKAGEFILEMANAGER_NOPKGDIR,
  56.             'PEAR_PACKAGEFILEMANAGER_NOBASEDIR' => PEAR_PACKAGEFILEMANAGER_NOBASEDIR,
  57.             'PEAR_PACKAGEFILEMANAGER_GENERATOR_NOTFOUND' => PEAR_PACKAGEFILEMANAGER_GENERATOR_NOTFOUND,
  58.             'PEAR_PACKAGEFILEMANAGER_GENERATOR_NOTFOUND_ANYWHERE' => PEAR_PACKAGEFILEMANAGER_GENERATOR_NOTFOUND_ANYWHERE,
  59.             'PEAR_PACKAGEFILEMANAGER_CANTWRITE_PKGFILE' => PEAR_PACKAGEFILEMANAGER_CANTWRITE_PKGFILE,
  60.             'PEAR_PACKAGEFILEMANAGER_DEST_UNWRITABLE' => PEAR_PACKAGEFILEMANAGER_DEST_UNWRITABLE,
  61.             'PEAR_PACKAGEFILEMANAGER_CANTCOPY_PKGFILE' => PEAR_PACKAGEFILEMANAGER_CANTCOPY_PKGFILE,
  62.             'PEAR_PACKAGEFILEMANAGER_CANTOPEN_TMPPKGFILE' => PEAR_PACKAGEFILEMANAGER_CANTOPEN_TMPPKGFILE,
  63.             'PEAR_PACKAGEFILEMANAGER_PATH_DOESNT_EXIST' => PEAR_PACKAGEFILEMANAGER_PATH_DOESNT_EXIST,
  64.             'PEAR_PACKAGEFILEMANAGER_NOCVSENTRIES' => PEAR_PACKAGEFILEMANAGER_NOCVSENTRIES,
  65.             'PEAR_PACKAGEFILEMANAGER_DIR_DOESNT_EXIST' => PEAR_PACKAGEFILEMANAGER_DIR_DOESNT_EXIST,
  66.             'PEAR_PACKAGEFILEMANAGER_RUN_SETOPTIONS' => PEAR_PACKAGEFILEMANAGER_RUN_SETOPTIONS,
  67.             'PEAR_PACKAGEFILEMANAGER_NOPACKAGE' => PEAR_PACKAGEFILEMANAGER_NOPACKAGE,
  68.             'PEAR_PACKAGEFILEMANAGER_WRONG_MROLE' => PEAR_PACKAGEFILEMANAGER_WRONG_MROLE,
  69.             'PEAR_PACKAGEFILEMANAGER_NOSUMMARY' => PEAR_PACKAGEFILEMANAGER_NOSUMMARY,
  70.             'PEAR_PACKAGEFILEMANAGER_NODESC' => PEAR_PACKAGEFILEMANAGER_NODESC,
  71.             'PEAR_PACKAGEFILEMANAGER_ADD_MAINTAINERS' => PEAR_PACKAGEFILEMANAGER_ADD_MAINTAINERS,
  72.             'PEAR_PACKAGEFILEMANAGER_NO_FILES' => PEAR_PACKAGEFILEMANAGER_NO_FILES,
  73.             'PEAR_PACKAGEFILEMANAGER_IGNORED_EVERYTHING' => PEAR_PACKAGEFILEMANAGER_IGNORED_EVERYTHING,
  74.             'PEAR_PACKAGEFILEMANAGER_INVALID_PACKAGE' => PEAR_PACKAGEFILEMANAGER_INVALID_PACKAGE,
  75.             'PEAR_PACKAGEFILEMANAGER_INVALID_REPLACETYPE' => PEAR_PACKAGEFILEMANAGER_INVALID_REPLACETYPE,
  76.             'PEAR_PACKAGEFILEMANAGER_INVALID_ROLE' => PEAR_PACKAGEFILEMANAGER_INVALID_ROLE,
  77.             'PEAR_PACKAGEFILEMANAGER_PHP_NOT_PACKAGE' => PEAR_PACKAGEFILEMANAGER_PHP_NOT_PACKAGE
  78.         ));
  79.         return $codes[$code];
  80.     }
  81.  
  82.     function _stripWhitespace($str)
  83.     {
  84.         return preg_replace('/\\s+/', '', $str);
  85.     }
  86.  
  87.     function _methodExists($name) 
  88.     {
  89.         if (in_array(strtolower($name), get_class_methods($this->packagexml))) {
  90.             return true;
  91.         }
  92.         $this->assertTrue(false, 'method '. $name . ' not implemented in ' . get_class($this->packagexml));
  93.         return false;
  94.     }
  95.  
  96.     function errorHandler($errno, $errstr, $errfile, $errline) {
  97.         //die("$errstr in $errfile at line $errline: $errstr");
  98.         $this->errorOccured = true;
  99.         $this->assertTrue(false, "$errstr at line $errline, $errfile");
  100.     }
  101.  
  102.     function PEARerrorHandler($error) {
  103.         $this->assertEquals($this->_expectedCode, $error->getCode(),
  104.             $this->_testMethod . ' ' . $this->errorCodeToString($this->_expectedCode)
  105.             . ' actual: ' . $this->errorCodeToString($error->getCode()));
  106.         $this->assertEquals($this->_expectedMessage, $error->getMessage(), $this->_testMethod);
  107.         $this->errorThrown = 'true';
  108.     }
  109.     
  110.     function expectPEARError($method, $msg, $code = null)
  111.     {
  112.         $this->_expectedMessage = $msg;
  113.         $this->_expectedCode = $code;
  114.         $this->_testMethod = $method;
  115.     }
  116.     
  117.     function test_invalid_wrongdir()
  118.     {
  119.         if (!$this->_methodExists('_getExistingPackageXML')) {
  120.             return;
  121.         }
  122.         $this->expectPEARError('invalid nopackage',
  123.             'PEAR_PackageFileManager Error: package.xml file path "array" ' .
  124.             'doesn\'t exist or isn\'t a directory', PEAR_PACKAGEFILEMANAGER_PATH_DOESNT_EXIST);
  125.         $this->packagexml->_getExistingPackageXML(array(), 'package.xml');
  126.         $this->assertEquals('true', $this->errorThrown, 'no error thrown');
  127.     }
  128.     
  129.     function test_invalid_notexists_nopackage()
  130.     {
  131.         if (!$this->_methodExists('_getExistingPackageXML')) {
  132.             return;
  133.         }
  134.         $this->expectPEARError('invalid nopackage',
  135.             'PEAR_PackageFileManager Error: Package Name (option \'package\') ' .
  136.             'must by specified in PEAR_PackageFileManager '.
  137.             'setOptions to create a new package.xml', PEAR_PACKAGEFILEMANAGER_NOPACKAGE);
  138.         $this->packagexml->_getExistingPackageXML(dirname(__FILE__), 'blah.xml');
  139.         $this->assertEquals('true', $this->errorThrown, 'no error thrown');
  140.     }
  141.     
  142.     function test_valid_simple()
  143.     {
  144.         if (!$this->_methodExists('_getExistingPackageXML')) {
  145.             return;
  146.         }
  147.         $this->packagexml->_options['pearcommonclass'] = 'PEAR_Common';
  148.         $res = $this->packagexml->_getExistingPackageXML(dirname(__FILE__) . '/', 'test1_package.xml');
  149.         $this->assertFalse(is_object($res), 'returned error');
  150.         $PEAR_Common = $this->packagexml->_options['pearcommonclass'];
  151.         $common = new $PEAR_Common;
  152.         $contents = $common->infoFromAny(dirname(__FILE__) . '/test1_package.xml');
  153.         $this->assertEquals($contents['release_deps'], $this->packagexml->_packageXml['release_deps'], 'wrong deps');
  154.         $this->assertEquals($contents['maintainers'], $this->packagexml->_packageXml['maintainers'], 'wrong maintainers');
  155.         $this->assertEquals($this->packagexml->_packageXml['release_deps'],
  156.             $this->packagexml->_options['deps'], 'wrong deps');
  157.         $this->assertEquals($this->packagexml->_packageXml['maintainers'],
  158.             $this->packagexml->_options['maintainers'], 'wrong maintainers');
  159.     }
  160.     
  161.     function test_valid_deps()
  162.     {
  163.         if (!$this->_methodExists('_getExistingPackageXML')) {
  164.             return;
  165.         }
  166.         $this->packagexml->_options['pearcommonclass'] = 'PEAR_Common';
  167.         $this->packagexml->_options['deps'] =
  168.             array(
  169.                 array('name' => 'pork', 'rel' => 'ge', 'version' => '1.0.0',
  170.                       'optional' => 'yes')
  171.             );
  172.         $res = $this->packagexml->_getExistingPackageXML(dirname(__FILE__) . '/', 'test1_package.xml');
  173.         $this->assertFalse(is_object($res), 'returned error');
  174.         $PEAR_Common = $this->packagexml->_options['pearcommonclass'];
  175.         $common = new $PEAR_Common;
  176.         $contents = $common->infoFromAny(dirname(__FILE__) . '/test1_package.xml');
  177.         $this->assertEquals(array(
  178.                 array('name' => 'pork', 'rel' => 'ge', 'version' => '1.0.0',
  179.                       'optional' => 'yes')
  180.             ), $this->packagexml->_packageXml['release_deps'], 'wrong deps');
  181.         $this->assertEquals($contents['maintainers'], $this->packagexml->_packageXml['maintainers'], 'wrong maintainers');
  182.         $this->assertEquals($this->packagexml->_packageXml['release_deps'],
  183.             $this->packagexml->_options['deps'], 'wrong deps');
  184.         $this->assertEquals($this->packagexml->_packageXml['maintainers'],
  185.             $this->packagexml->_options['maintainers'], 'wrong maintainers');
  186.     }
  187.     
  188.     function test_valid_maintainers()
  189.     {
  190.         if (!$this->_methodExists('_getExistingPackageXML')) {
  191.             return;
  192.         }
  193.         $this->packagexml->_options['pearcommonclass'] = 'PEAR_Common';
  194.         $this->packagexml->_options['maintainers'] =
  195.             array(
  196.                 array('name' => 'Gerg', 'email' => 'foo@example.com',
  197.                       'role' => 'lead',
  198.                       'handle' => 'cellogerg')
  199.             );
  200.         $res = $this->packagexml->_getExistingPackageXML(dirname(__FILE__) . '/', 'test1_package.xml');
  201.         $this->assertFalse(is_object($res), 'returned error');
  202.         $PEAR_Common = $this->packagexml->_options['pearcommonclass'];
  203.         $common = new $PEAR_Common;
  204.         $contents = $common->infoFromAny(dirname(__FILE__) . '/test1_package.xml');
  205.         $this->assertEquals($contents['release_deps'], $this->packagexml->_packageXml['release_deps'], 'wrong deps');
  206.         $this->assertEquals(array(
  207.                 array('name' => 'Gerg', 'email' => 'foo@example.com',
  208.                       'role' => 'lead',
  209.                       'handle' => 'cellogerg')
  210.             ), $this->packagexml->_packageXml['maintainers'], 'wrong maintainers');
  211.         $this->assertEquals($this->packagexml->_packageXml['release_deps'],
  212.             $this->packagexml->_options['deps'], 'wrong deps');
  213.         $this->assertEquals($this->packagexml->_packageXml['maintainers'],
  214.             $this->packagexml->_options['maintainers'], 'wrong maintainers');
  215.     }
  216. }
  217.  
  218. ?>
  219.