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

  1. <?php
  2. require_once 'System.php';
  3. require_once 'PHPUnit.php';
  4. require_once 'File/Passwd/Cvs.php';
  5.  
  6. $GLOBALS['tmpfile'] = System::mktemp();
  7. $GLOBALS['user']    = array(
  8.     'mike' => array( 'passwd' => 'Tlu5Cq9nQ48Qc', 'system' => 'mike'),
  9.     'pete' => array( 'passwd' => '6j8u02M0HVycY'),
  10.     'mary' => array( 'passwd' => 'H7YIMXbnZ0Nyo', 'system' => 'marianne')
  11. );
  12.  
  13. /**
  14.  * TestCase for File_Passwd_CvsTest class
  15.  * Generated by PHPEdit.XUnit Plugin
  16.  * 
  17.  */
  18. class File_Passwd_CvsTest extends PHPUnit_TestCase{
  19.  
  20.     var $pwd;
  21.  
  22.     /**
  23.      * Constructor
  24.      * @param string $name The name of the test.
  25.      * @access protected
  26.      */
  27.     function File_Passwd_CvsTest($name){
  28.         $this->PHPUnit_TestCase($name);
  29.     }
  30.     
  31.     /**
  32.      * Called before the test functions will be executed this function is defined in PHPUnit_TestCase and overwritten here
  33.      * @access protected
  34.      */
  35.     function setUp(){
  36.         $this->pwd = &new File_Passwd_Cvs();
  37.     }
  38.     
  39.     /**
  40.      * Called after the test functions are executed this function is defined in PHPUnit_TestCase and overwritten here
  41.      * @access protected
  42.      */
  43.     function tearDown(){
  44.         $this->pwd = null;
  45.     }
  46.     
  47.     /**
  48.      * Regression test for File_Passwd_Cvs.File_Passwd_Cvs method
  49.      * @access public
  50.      */
  51.     function testFile_Passwd_Cvs(){
  52.         $this->assertTrue(is_a($this->pwd, 'File_Passwd_Cvs'));
  53.     }
  54.     
  55.     /**
  56.      * Regression test for File_Passwd_Cvs.save method
  57.      * @access public
  58.      */
  59.     function testsave(){
  60.         $this->pwd->_users = $GLOBALS['user'];
  61.         $this->pwd->setFile($GLOBALS['tmpfile']);
  62.         $this->assertTrue($this->pwd->save());
  63.         $this->assertEquals(file('passwd.cvs.txt'), file($GLOBALS['tmpfile']));
  64.     }
  65.     
  66.     /**
  67.      * Regression test for File_Passwd_Cvs.parse method
  68.      * @access public
  69.      */
  70.     function testparse(){
  71.         $this->pwd->_users = array();
  72.         $this->pwd->setFile('passwd.cvs.txt');
  73.         $this->assertTrue($this->pwd->load());
  74.         $this->assertEquals($GLOBALS['user'], $this->pwd->_users);
  75.     }
  76.     
  77.     /**
  78.      * Regression test for File_Passwd_Cvs.addUser method
  79.      * @access public
  80.      */
  81.     function testaddUser(){
  82.         $this->assertTrue($this->pwd->addUser('add', 123));
  83.         $this->assertTrue($this->pwd->userExists('add'));
  84.     }
  85.     
  86.     /**
  87.      * Regression test for File_Passwd_Cvs.verifyPasswd method
  88.      * @access public
  89.      */
  90.     function testverifyPasswd(){
  91.         $this->pwd->addUser('verify', 12345);
  92.         $this->assertTrue($this->pwd->verifyPasswd('verify', 12345));
  93.         $this->assertFalse($this->pwd->verifyPasswd('verify', 0));
  94.         $this->assertTrue(PEAR::isError($this->pwd->verifyPasswd('nobody', 0)));
  95.     }
  96.     
  97.     /**
  98.      * Regression test for File_Passwd_Cvs.changePasswd method
  99.      * @access public
  100.      */
  101.     function testchangePasswd(){
  102.         $this->pwd->addUser('change', 123);
  103.         $this->assertTrue($this->pwd->changePasswd('change', 'abc'));
  104.         $this->assertTrue($this->pwd->verifyPasswd('change', 'abc'));
  105.     }
  106.     
  107.     /**
  108.      * Regression test for File_Passwd_Cvs.changeSysUser method
  109.      * @access public
  110.      */
  111.     function testchangeSysUser(){
  112.         $this->pwd->addUser('chsys', 123, 'nobody');
  113.         $this->assertTrue($this->pwd->changeSysUser('chsys', 'mike'));
  114.         $this->assertEquals('mike', $this->pwd->_users['chsys']['system']);
  115.     }
  116.     
  117.     /**
  118.      * Regression test for File_Passwd_Cvs._genPass method
  119.      * @access public
  120.      */
  121.     function test_genPass(){
  122.         $this->assertEquals('12IbR.gJ8wcpc', $this->pwd->_genPass(123, '12IbR.gJ8wcpc'));
  123.     }
  124.     
  125.     function teststaticAuth(){
  126.         $this->assertTrue(true === File_Passwd::staticAuth('cvs', 'passwd.cvs.txt', 'mike', 123));
  127.         $this->assertTrue(false === File_Passwd::staticAuth('cvs', 'passwd.cvs.txt', 'mike', 'abc'));
  128.         $this->assertFalse((File_Passwd::staticAuth('cvs', 'passwd.cvs.txt', 'nonexist', 'asd')));
  129.     }
  130. }
  131.  
  132. ?>