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

  1. <?php
  2. require_once 'System.php';
  3. require_once 'PHPUnit.php';
  4. require_once 'File/Passwd/Custom.php';
  5.  
  6.  
  7. $GLOBALS['tmpfile'] = System::mktemp();
  8. $GLOBALS['map']     = array(
  9.     'extra1', 'extra2', 'extra3'
  10. );
  11. $GLOBALS['users']   = array(
  12.     'mike' => array(
  13.         'pass' =>   'mikespass',
  14.     ),
  15.     'pete' => array(
  16.         'pass' =>   'petespass',
  17.     ),
  18.     'mary' => array(
  19.         'pass' =>   'maryspass',
  20.     )
  21. );
  22.  
  23.  
  24. /**
  25.  * TestCase for File_Passwd_CustomTest class
  26.  * Generated by PHPEdit.XUnit Plugin
  27.  * 
  28.  */
  29. class File_Passwd_CustomTest extends PHPUnit_TestCase{
  30.  
  31.     var $pwd;
  32.     
  33.     /**
  34.      * Constructor
  35.      * @param string $name The name of the test.
  36.      * @access protected
  37.      */
  38.     function File_Passwd_CustomTest($name){
  39.         $this->PHPUnit_TestCase($name);
  40.     }
  41.     
  42.     /**
  43.      * Called before the test functions will be executed this function is defined in PHPUnit_TestCase and overwritten here
  44.      * @access protected
  45.      */
  46.     function setUp(){
  47.         $this->pwd = &new File_Passwd_Custom();
  48.     }
  49.     
  50.     /**
  51.      * Called after the test functions are executed this function is defined in PHPUnit_TestCase and overwritten here
  52.      * @access protected
  53.      */
  54.     function tearDown(){
  55.         $this->pwd = null;
  56.     }
  57.     
  58.     /**
  59.      * Regression test for File_Passwd_Custom.setDelim method
  60.      * @access public
  61.      */
  62.     function testsetDelim(){
  63.         $this->pwd->setDelim('abc');
  64.         $this->assertEquals('a', $this->pwd->getDelim());
  65.     }
  66.     
  67.     /**
  68.      * Regression test for File_Passwd_Custom.getDelim method
  69.      * @access public
  70.      */
  71.     function testgetDelim(){
  72.         $this->pwd->setDelim('%');
  73.         $this->assertEquals('%', $this->pwd->getDelim());
  74.     }
  75.     
  76.     /**
  77.      * Regression test for File_Passwd_Custom.setEncFunc method
  78.      * @access public
  79.      */
  80.     function testsetEncFunc(){
  81.         $this->assertTrue(PEAR::isError($this->pwd->setEncFunc('nonexistant')));
  82.         $this->assertFalse(PEAR::isError($this->pwd->setEncFunc('md5')));
  83.     }
  84.     
  85.     /**
  86.      * Regression test for File_Passwd_Custom.getEncFunc method
  87.      * @access public
  88.      */
  89.     function testgetEncFunc(){
  90.         $this->pwd->setEncFunc(array('File_Passwd', 'crypt_plain'));
  91.         $this->assertEquals('File_Passwd::crypt_plain', $this->pwd->getEncFunc());
  92.     }
  93.     
  94.     /**
  95.      * Regression test for File_Passwd_Custom.useMap method
  96.      * @access public
  97.      */
  98.     function testuseMap(){
  99.         $this->pwd->useMap(false);
  100.         $this->assertFalse($this->pwd->useMap());
  101.         $this->pwd->useMap(true);
  102.         $this->assertTrue($this->pwd->useMap());
  103.     }
  104.     
  105.     /**
  106.      * Regression test for File_Passwd_Custom.setMap method
  107.      * @access public
  108.      */
  109.     function testsetMap(){
  110.         $this->pwd->setMap($GLOBALS['map']);
  111.         $this->assertEquals($GLOBALS['map'], $this->pwd->getMap());
  112.     }
  113.     
  114.     /**
  115.      * Regression test for File_Passwd_Custom.getMap method
  116.      * @access public
  117.      */
  118.     function testgetMap(){
  119.         $this->pwd->setMap(array('prop'));
  120.         $this->assertEquals(array('prop'), $this->pwd->getMap());
  121.     }
  122.     
  123.     /**
  124.      * Regression test for File_Passwd_Custom.save method
  125.      * @access public
  126.      */
  127.     function testsave(){
  128.         $this->pwd->setFile($GLOBALS['tmpfile']);
  129.         $this->pwd->setDelim('|');
  130.         $this->pwd->setEncFunc(array('File_Passwd', 'crypt_plain'));
  131.         foreach ($GLOBALS['users'] as $user => $pass_r) {
  132.             $this->pwd->addUser($user, $pass_r['pass']);
  133.         }
  134.         $this->assertFalse(PEAR::isError($this->pwd->save()));
  135.         $this->assertEquals(file('passwd.custom.txt'), file($GLOBALS['tmpfile']));
  136.     }
  137.     
  138.     /**
  139.      * Regression test for File_Passwd_Custom.parse method
  140.      * @access public
  141.      */
  142.     function testparse(){
  143.         $this->pwd->useMap(true);
  144.         $this->pwd->setFile('passwd.custom.txt');
  145.         $this->pwd->setDelim('|');
  146.         $this->pwd->load();
  147.         $this->assertEquals($GLOBALS['users'], $this->pwd->_users);
  148.     }
  149.     
  150.     /**
  151.      * Regression test for File_Passwd_Custom.addUser method
  152.      * @access public
  153.      */
  154.     function testaddUser(){
  155.         $this->pwd->useMap(true);
  156.         $this->pwd->setEncFunc('md5');
  157.         $this->pwd->addUser('testadd', 'pass');
  158.         $this->assertTrue($this->pwd->userExists('testadd'));
  159.         $this->assertEquals(md5('pass'), $this->pwd->_users['testadd']['pass']);
  160.     }
  161.     
  162.     /**
  163.      * Regression test for File_Passwd_Custom.modUser method
  164.      * @access public
  165.      */
  166.     function testmodUser(){
  167.         $this->pwd->useMap(true);
  168.         $this->pwd->setEncFunc('md5');
  169.         $this->pwd->addUser('testmod', 'pass');
  170.         $this->assertFalse(PEAR::isError($this->pwd->modUser('testmod', array('pass' => 'newpass'))));
  171.         $this->assertEquals('newpass', $this->pwd->_users['testmod']['pass']);
  172.     }
  173.     
  174.     /**
  175.      * Regression test for File_Passwd_Custom.changePasswd method
  176.      * @access public
  177.      */
  178.     function testchangePasswd(){
  179.         $this->pwd->useMap(true);
  180.         $this->pwd->setEncFunc('md5');
  181.         $this->pwd->addUser('changepass', 'pass');
  182.         $this->assertFalse(PEAR::isError($this->pwd->changePasswd('changepass', 'newpass')));
  183.         $this->assertEquals(md5('newpass'), $this->pwd->_users['changepass']['pass']);
  184.     }
  185.     
  186.     /**
  187.      * Regression test for File_Passwd_Custom.verifyPasswd method
  188.      * @access public
  189.      */
  190.     function testverifyPasswd(){
  191.         $this->pwd->addUser('testverify', 'password');
  192.         $rs = $this->pwd->verifyPasswd('testverify', 'password');
  193.         $this->assertFalse(PEAR::isError($rs));
  194.         $this->assertTrue($rs);
  195.     }
  196.  
  197.     function teststaticAuth(){
  198.         $this->assertTrue(true === File_Passwd::staticAuth('Custom', 'passwd.custom.txt', 'mike', 'mikespass', array(array('File_Passwd', 'crypt_plain'), '|')));
  199.         $this->assertTrue(false === File_Passwd::staticAuth('Custom', 'passwd.custom.txt', 'mike', 'abc', array(array('File_Passwd', 'crypt_plain'), '|')));
  200.         $this->assertTrue(PEAR::isError(File_Passwd::staticAuth('Custom', 'passwd.custom.txt', 'mike', 'mikespass')));
  201.     }
  202.     
  203. }
  204.  
  205. ?>