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_dirList.php < prev    next >
Encoding:
PHP Script  |  2004-03-24  |  10.5 KB  |  241 lines

  1. <?php
  2.  
  3. /**
  4.  * API Unit tests for PEAR_PackageFileManager package.
  5.  * 
  6.  * @version    $Id: PEAR_PackageFileManager_File_TestCase_dirList.php,v 1.6 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_dirList extends PHPUnit_TestCase
  17. {
  18.     /**
  19.      * A PEAR_PackageFileManager object
  20.      * @var        object
  21.      */
  22.     var $packagexml;
  23.  
  24.     function PEAR_PackageFileManager_File_TestCase_dirList($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_invalid()
  119.     {
  120.         if (!$this->_methodExists('dirList')) {
  121.             return;
  122.         }
  123.         $this->expectPEARError(
  124.             'test_invalid',
  125.             'PEAR_PackageFileManager Error: Package source base directory ' .
  126.             '"fargusblurbe[]--#/"" doesn\'t exist or isn\'t a directory',
  127.             PEAR_PACKAGEFILEMANAGER_DIR_DOESNT_EXIST
  128.         );
  129.         $res = $this->packagexml->dirList('fargusblurbe[]--#/"');
  130.         $this->assertTrue(is_object($res), 'no error');
  131.         $this->assertEquals('true', $this->errorThrown, 'no error thrown');
  132.     }
  133.     
  134.     function test_valid()
  135.     {
  136.         if (!$this->_methodExists('dirList')) {
  137.             return;
  138.         }
  139.         if (!$this->_methodExists('_setupIgnore')) {
  140.             return;
  141.         }
  142.         $this->packagexml->_options['addhiddenfiles'] = false;
  143.         $this->packagexml->_setupIgnore(false, 0);
  144.         $this->packagexml->_setupIgnore(false, 1);
  145.         $res = $this->packagexml->dirList(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'footest');
  146.         $this->assertEquals(
  147.             array(
  148.                 dirname(__FILE__) . DIRECTORY_SEPARATOR . 'footest/blarfoo/blartest.txt',
  149.                 dirname(__FILE__) . DIRECTORY_SEPARATOR . 'footest/subfoo/subsubfoo/boo.txt',
  150.                 dirname(__FILE__) . DIRECTORY_SEPARATOR . 'footest/subfoo/test11.txt',
  151.                 dirname(__FILE__) . DIRECTORY_SEPARATOR . 'footest/subfoo/test12.txt',
  152.                 dirname(__FILE__) . DIRECTORY_SEPARATOR . 'footest/test1.txt',
  153.                 dirname(__FILE__) . DIRECTORY_SEPARATOR . 'footest/test2.txt',
  154.                 dirname(__FILE__) . DIRECTORY_SEPARATOR . 'footest/testCVS/testEntries',
  155.                 dirname(__FILE__) . DIRECTORY_SEPARATOR . 'footest/testCVS/testEntries.Extra',
  156.             ),
  157.             $res,
  158.             'incorrect dir structure');
  159.         $this->assertFalse($this->errorThrown, 'error thrown');
  160.     }
  161.     
  162.     function test_valid_addhiddenfiles()
  163.     {
  164.         if (!$this->_methodExists('dirList')) {
  165.             return;
  166.         }
  167.         if (!$this->_methodExists('_setupIgnore')) {
  168.             return;
  169.         }
  170.         $this->packagexml->_options['addhiddenfiles'] = true;
  171.         $this->packagexml->_setupIgnore(false, 0);
  172.         $this->packagexml->_setupIgnore(false, 1);
  173.         $res = $this->packagexml->dirList(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'footest');
  174.         $this->assertEquals(
  175.             array(
  176.                 dirname(__FILE__) . DIRECTORY_SEPARATOR . 'footest/.test',
  177.                 dirname(__FILE__) . DIRECTORY_SEPARATOR . 'footest/blarfoo/blartest.txt',
  178.                 dirname(__FILE__) . DIRECTORY_SEPARATOR . 'footest/subfoo/subsubfoo/boo.txt',
  179.                 dirname(__FILE__) . DIRECTORY_SEPARATOR . 'footest/subfoo/test11.txt',
  180.                 dirname(__FILE__) . DIRECTORY_SEPARATOR . 'footest/subfoo/test12.txt',
  181.                 dirname(__FILE__) . DIRECTORY_SEPARATOR . 'footest/test1.txt',
  182.                 dirname(__FILE__) . DIRECTORY_SEPARATOR . 'footest/test2.txt',
  183.                 dirname(__FILE__) . DIRECTORY_SEPARATOR . 'footest/testCVS/testEntries',
  184.                 dirname(__FILE__) . DIRECTORY_SEPARATOR . 'footest/testCVS/testEntries.Extra',
  185.             ),
  186.             $res,
  187.             'incorrect dir structure');
  188.         $this->assertFalse($this->errorThrown, 'error thrown');
  189.     }
  190.     
  191.     function test_valid_with_ignore()
  192.     {
  193.         if (!$this->_methodExists('dirList')) {
  194.             return;
  195.         }
  196.         if (!$this->_methodExists('_setupIgnore')) {
  197.             return;
  198.         }
  199.         $this->packagexml->_options['addhiddenfiles'] = false;
  200.         $this->packagexml->_setupIgnore(array('blar*'), 1);
  201.         $this->packagexml->_setupIgnore(false, 0);
  202.         $res = $this->packagexml->dirList(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'footest');
  203.         $this->assertEquals(
  204.             array(
  205.                 dirname(__FILE__) . DIRECTORY_SEPARATOR . 'footest/subfoo/subsubfoo/boo.txt',
  206.                 dirname(__FILE__) . DIRECTORY_SEPARATOR . 'footest/subfoo/test11.txt',
  207.                 dirname(__FILE__) . DIRECTORY_SEPARATOR . 'footest/subfoo/test12.txt',
  208.                 dirname(__FILE__) . DIRECTORY_SEPARATOR . 'footest/test1.txt',
  209.                 dirname(__FILE__) . DIRECTORY_SEPARATOR . 'footest/test2.txt',
  210.                 dirname(__FILE__) . DIRECTORY_SEPARATOR . 'footest/testCVS/testEntries',
  211.                 dirname(__FILE__) . DIRECTORY_SEPARATOR . 'footest/testCVS/testEntries.Extra',
  212.             ),
  213.             $res,
  214.             'incorrect dir structure');
  215.         $this->assertFalse($this->errorThrown, 'error thrown');
  216.     }
  217.     
  218.     function test_valid_with_include()
  219.     {
  220.         if (!$this->_methodExists('dirList')) {
  221.             return;
  222.         }
  223.         if (!$this->_methodExists('_setupIgnore')) {
  224.             return;
  225.         }
  226.         $this->packagexml->_options['addhiddenfiles'] = false;
  227.         $this->packagexml->_setupIgnore(array('blar*'), 0);
  228.         $this->packagexml->_setupIgnore(false, 1);
  229.         $res = $this->packagexml->dirList(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'footest');
  230.         $this->assertEquals(
  231.             array(
  232.                 dirname(__FILE__) . DIRECTORY_SEPARATOR . 'footest/blarfoo/blartest.txt',
  233.             ),
  234.             $res,
  235.             'incorrect dir structure');
  236.         $this->assertFalse($this->errorThrown, 'error thrown');
  237.     }
  238. }
  239.  
  240. ?>
  241.