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_getFileList.php < prev    next >
Encoding:
PHP Script  |  2004-03-24  |  9.1 KB  |  208 lines

  1. <?php
  2.  
  3. /**
  4.  * API Unit tests for PEAR_PackageFileManager package.
  5.  * 
  6.  * @version    $Id: PEAR_PackageFileManager_File_TestCase_getFileList.php,v 1.5 2004/02/07 06:13:27 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_getFileList extends PHPUnit_TestCase
  17. {
  18.     /**
  19.      * A PEAR_PackageFileManager object
  20.      * @var        object
  21.      */
  22.     var $packagexml;
  23.  
  24.     function PEAR_PackageFileManager_File_TestCase_getFileList($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_valid()
  119.     {
  120.         if (!$this->_methodExists('getFileList')) {
  121.             return;
  122.         }
  123.         $this->packagexml->_options['addhiddenfiles'] = false;
  124.         $this->packagexml->_options['packagefile'] = 'package.xml';
  125.         $this->packagexml->_options['ignore'] =
  126.         $this->packagexml->_options['include'] = false;
  127.         $this->packagexml->_options['packagedirectory'] =
  128.             dirname(__FILE__) . DIRECTORY_SEPARATOR . 'footest/';
  129.         $res = $this->packagexml->getFileList();
  130.         $this->assertEquals(
  131.             array(
  132.                 '/' =>
  133.                 array(
  134.                 'blarfoo' =>
  135.                     array(
  136.                         array(
  137.                             'file' => 'blartest.txt',
  138.                             'ext' => 'txt',
  139.                             'path' => 'blarfoo/blartest.txt',
  140.                             'fullpath' => dirname(__FILE__) . DIRECTORY_SEPARATOR . 'footest/blarfoo/blartest.txt',
  141.                         )
  142.                     ),
  143.                 'subfoo' =>
  144.                     array(
  145.                         0 =>
  146.                             array(
  147.                                 'file' => 'test11.txt',
  148.                                 'ext' => 'txt',
  149.                                 'path' => 'subfoo/test11.txt',
  150.                                 'fullpath' => dirname(__FILE__) . DIRECTORY_SEPARATOR . 'footest/subfoo/test11.txt',
  151.                             ),
  152.                         1 =>
  153.                             array(
  154.                                 'file' => 'test12.txt',
  155.                                 'ext' => 'txt',
  156.                                 'path' => 'subfoo/test12.txt',
  157.                                 'fullpath' => dirname(__FILE__) . DIRECTORY_SEPARATOR . 'footest/subfoo/test12.txt',
  158.                             ),
  159.                         'subsubfoo' =>
  160.                             array(
  161.                                 array(
  162.                                     'file' => 'boo.txt',
  163.                                     'ext' => 'txt',
  164.                                     'path' => 'subfoo/subsubfoo/boo.txt',
  165.                                     'fullpath' => dirname(__FILE__) . DIRECTORY_SEPARATOR . 'footest/subfoo/subsubfoo/boo.txt',
  166.                                 )
  167.                             ),
  168.                         ),
  169.                 'testCVS' =>
  170.                     array(
  171.                         0 =>
  172.                             array(
  173.                                 'file' => 'testEntries',
  174.                                 'ext' => '',
  175.                                 'path' => 'testCVS/testEntries',
  176.                                 'fullpath' => dirname(__FILE__) . DIRECTORY_SEPARATOR . 'footest/testCVS/testEntries',
  177.                             ),
  178.                             array(
  179.                                 'file' => 'testEntries.Extra',
  180.                                 'ext' => 'Extra',
  181.                                 'path' => 'testCVS/testEntries.Extra',
  182.                                 'fullpath' => dirname(__FILE__) . DIRECTORY_SEPARATOR . 'footest/testCVS/testEntries.Extra',
  183.                             ),
  184.                         ),
  185.                 0 =>
  186.                     array(
  187.                         'file' => 'test1.txt',
  188.                         'ext' => 'txt',
  189.                         'path' => 'test1.txt',
  190.                         'fullpath' => dirname(__FILE__) . DIRECTORY_SEPARATOR . 'footest/test1.txt',
  191.                     ),
  192.                 1 =>
  193.                     array(
  194.                         'file' => 'test2.txt',
  195.                         'ext' => 'txt',
  196.                         'path' => 'test2.txt',
  197.                         'fullpath' => dirname(__FILE__) . DIRECTORY_SEPARATOR . 'footest/test2.txt',
  198.                     ),
  199.                 )
  200.             ),
  201.             $res,
  202.             'incorrect dir structure');
  203.         $this->assertFalse($this->errorThrown, 'error thrown');
  204.     }
  205. }
  206.  
  207. ?>
  208.