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_checkIgnore.php < prev    next >
Encoding:
PHP Script  |  2004-03-24  |  13.0 KB  |  314 lines

  1. <?php
  2.  
  3. /**
  4.  * API Unit tests for PEAR_PackageFileManager package.
  5.  * 
  6.  * @version    $Id: PEAR_PackageFileManager_File_TestCase_checkIgnore.php,v 1.2 2003/10/18 21:55:02 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_checkIgnore extends PHPUnit_TestCase
  17. {
  18.     /**
  19.      * A PEAR_PackageFileManager object
  20.      * @var        object
  21.      */
  22.     var $packagexml;
  23.  
  24.     function PEAR_PackageFileManager_File_TestCase_checkIgnore($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());
  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_nonarray()
  119.     {
  120.         if (!$this->_methodExists('_checkIgnore')) {
  121.             return;
  122.         }
  123.         if (!$this->_methodExists('_setupIgnore')) {
  124.             return;
  125.         }
  126.         $this->packagexml->_setupIgnore(false, 1);
  127.         $res = $this->packagexml->_checkIgnore(basename('anything\\goes'),
  128.             'anything\\goes', 1);
  129.         $this->assertFalse($res, 'wrongo');
  130.         $this->assertFalse($this->errorThrown, 'error thrown');
  131.     }
  132.     
  133.     function test_emptyarray()
  134.     {
  135.         if (!$this->_methodExists('_checkIgnore')) {
  136.             return;
  137.         }
  138.         if (!$this->_methodExists('_setupIgnore')) {
  139.             return;
  140.         }
  141.         $this->packagexml->_setupIgnore(array(), 1);
  142.         $res = $this->packagexml->_checkIgnore(basename('anything\\goes'),
  143.             'anything\\goes', 1);
  144.         $this->assertFalse($res, 'wrongo');
  145.         $this->assertFalse($this->errorThrown, 'error thrown');
  146.     }
  147.     
  148.     function test_simple_no()
  149.     {
  150.         if (!$this->_methodExists('_checkIgnore')) {
  151.             return;
  152.         }
  153.         if (!$this->_methodExists('_setupIgnore')) {
  154.             return;
  155.         }
  156.         $this->packagexml->_setupIgnore(array('frog*'), 1);
  157.         $this->packagexml->_setupIgnore(array('frog*'), 0);
  158.         $res = $this->packagexml->_checkIgnore(basename('anything\\goes'),
  159.             'anything\\goes', 1);
  160.         $this->assertFalse($res, 'wrongo 1');
  161.         $res = $this->packagexml->_checkIgnore(basename('anything\\goes'),
  162.             'anything\\goes', 0);
  163.         $this->assertTrue($res, 'wrongo 2');
  164.         $this->assertFalse($this->errorThrown, 'error thrown');
  165.     }
  166.     
  167.     function test_simple_pass()
  168.     {
  169.         if (!$this->_methodExists('_checkIgnore')) {
  170.             return;
  171.         }
  172.         if (!$this->_methodExists('_setupIgnore')) {
  173.             return;
  174.         }
  175.         $this->packagexml->_setupIgnore(array('frog*'), 1);
  176.         $this->packagexml->_setupIgnore(array('frog*'), 0);
  177.         $res = $this->packagexml->_checkIgnore(basename('anything\\goes\\frog'),
  178.             'anything\\goes\\frog', 1);
  179.         $this->assertTrue($res, 'wrongo 1');
  180.         $res = $this->packagexml->_checkIgnore(basename('anything\\goes\\frog'),
  181.             'anything\\goes\\frog', 0);
  182.         $this->assertFalse($res, 'wrongo 2');
  183.         $this->assertFalse($this->errorThrown, 'error thrown');
  184.     }
  185.     
  186.     function test_simple_dir_pass()
  187.     {
  188.         if (!$this->_methodExists('_checkIgnore')) {
  189.             return;
  190.         }
  191.         if (!$this->_methodExists('_setupIgnore')) {
  192.             return;
  193.         }
  194.         $this->packagexml->_setupIgnore(array('frog*/'), 1);
  195.         $this->packagexml->_setupIgnore(array('frog*/'), 0);
  196.         $res = $this->packagexml->_checkIgnore(basename('anything\\froggoes\\test.php'),
  197.             'anything\\froggoes\\test.php', 1);
  198.         $this->assertTrue($res, 'wrongo 1');
  199.         $res = $this->packagexml->_checkIgnore(basename('anything\\froggoes\\test.php'),
  200.             'anything\\froggoes\\test.php', 0);
  201.         $this->assertFalse($res, 'wrongo 2');
  202.         $this->assertFalse($this->errorThrown, 'error thrown');
  203.     }
  204.     
  205.     function test_simple_dir_no()
  206.     {
  207.         if (!$this->_methodExists('_checkIgnore')) {
  208.             return;
  209.         }
  210.         if (!$this->_methodExists('_setupIgnore')) {
  211.             return;
  212.         }
  213.         $this->packagexml->_setupIgnore(array('frog*/'), 1);
  214.         $this->packagexml->_setupIgnore(array('frog*/'), 0);
  215.         $res = $this->packagexml->_checkIgnore(basename('anything\\frooggoes\\test.php'),
  216.             'anything\\frooggoes\\test.php', 1);
  217.         $this->assertFalse($res, 'wrongo 1');
  218.         $res = $this->packagexml->_checkIgnore(basename('anything\\frooggoes\\test.php'),
  219.             'anything\\frooggoes\\test.php', 0);
  220.         $this->assertTrue($res, 'wrongo 2');
  221.         $this->assertFalse($this->errorThrown, 'error thrown');
  222.     }
  223.     
  224.     function test_complex_pass()
  225.     {
  226.         if (!$this->_methodExists('_checkIgnore')) {
  227.             return;
  228.         }
  229.         if (!$this->_methodExists('_setupIgnore')) {
  230.             return;
  231.         }
  232.         $this->packagexml->_setupIgnore(array('*frog*/test.php'), 1);
  233.         $this->packagexml->_setupIgnore(array('*frog*/test.php'), 0);
  234.         $res = $this->packagexml->_checkIgnore(basename('froggoes\\test.php'),
  235.             'froggoes\\test.php', 1);
  236.         $this->assertTrue($res, 'wrongo 1');
  237.         $res = $this->packagexml->_checkIgnore(basename('froggoes\\test.php'),
  238.             'froggoes\\test.php', 0);
  239.         $this->assertFalse($res, 'wrongo 2');
  240.         $this->assertFalse($this->errorThrown, 'error thrown');
  241.     }
  242.     
  243.     function test_complex_no()
  244.     {
  245.         if (!$this->_methodExists('_checkIgnore')) {
  246.             return;
  247.         }
  248.         if (!$this->_methodExists('_setupIgnore')) {
  249.             return;
  250.         }
  251.         $this->packagexml->_setupIgnore(array('*frog*/test.php'), 1);
  252.         $this->packagexml->_setupIgnore(array('*frog*/test.php'), 0);
  253.         $res = $this->packagexml->_checkIgnore(basename('anything\\frooggoes\\test.php'),
  254.             'anything\\frooggoes\\test.php', 1);
  255.         $this->assertFalse($res, 'wrongo 1');
  256.         $res = $this->packagexml->_checkIgnore(basename('anything\\frooggoes\\test.php'),
  257.             'anything\\frooggoes\\test.php', 0);
  258.         $this->assertTrue($res, 'wrongo 2');
  259.         $this->assertFalse($this->errorThrown, 'error thrown');
  260.     }
  261.     
  262.     function test_complex_multiple_pass()
  263.     {
  264.         if (!$this->_methodExists('_checkIgnore')) {
  265.             return;
  266.         }
  267.         if (!$this->_methodExists('_setupIgnore')) {
  268.             return;
  269.         }
  270.         $this->packagexml->_setupIgnore(array('gorf*', '*frog*/test.php'), 1);
  271.         $this->packagexml->_setupIgnore(array('gorf*', '*frog*/test.php'), 0);
  272.         $res = $this->packagexml->_checkIgnore(basename('anything\\froggoes\\test.php'),
  273.             'anything\\froggoes\\test.php', 1);
  274.         $this->assertTrue($res, 'wrongo 1');
  275.         $res = $this->packagexml->_checkIgnore(basename('anything\\froggoes\\gorftest.php'),
  276.             'anything\\froggoes\\gorftest.php', 1);
  277.         $this->assertTrue($res, 'wrongo 1.5');
  278.         $res = $this->packagexml->_checkIgnore(basename('anything\\froggoes\\test.php'),
  279.             'anything\\froggoes\\test.php', 0);
  280.         $this->assertFalse($res, 'wrongo 2');
  281.         $res = $this->packagexml->_checkIgnore(basename('anything\\froggoes\\gorftest.php'),
  282.             'anything\\froggoes\\gorftest.php', 0);
  283.         $this->assertFalse($res, 'wrongo 2.5');
  284.         $this->assertFalse($this->errorThrown, 'error thrown');
  285.     }
  286.     
  287.     function test_complex_multiple_no()
  288.     {
  289.         if (!$this->_methodExists('_checkIgnore')) {
  290.             return;
  291.         }
  292.         if (!$this->_methodExists('_setupIgnore')) {
  293.             return;
  294.         }
  295.         $this->packagexml->_setupIgnore(array('gorf*', '*frog*/test.php'), 1);
  296.         $this->packagexml->_setupIgnore(array('gorf*', '*frog*/test.php'), 0);
  297.         $res = $this->packagexml->_checkIgnore(basename('anything\\frooggoes\\test.php'),
  298.             'anything\\frooggoes\\test.php', 1);
  299.         $this->assertFalse($res, 'wrongo 1');
  300.         $res = $this->packagexml->_checkIgnore(basename('anything\\froggoes\\goorftest.php'),
  301.             'anything\\frooggoes\\gorftest.php', 1);
  302.         $this->assertFalse($res, 'wrongo 1.5');
  303.         $res = $this->packagexml->_checkIgnore(basename('anything\\frooggoes\\test.php'),
  304.             'anything\\frooggoes\\test.php', 0);
  305.         $this->assertTrue($res, 'wrongo 2');
  306.         $res = $this->packagexml->_checkIgnore(basename('anything\\froggoes\\goorftest.php'),
  307.             'anything\\frooggoes\\gorftest.php', 0);
  308.         $this->assertTrue($res, 'wrongo 2.5');
  309.         $this->assertFalse($this->errorThrown, 'error thrown');
  310.     }
  311. }
  312.  
  313. ?>
  314.