Advertisement
dragonbe

Auth Adapter Test

Oct 2nd, 2012
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.57 KB | None | 0 0
  1. <?php
  2.  
  3. require_once 'In2it/Auth/Adapter/File.php';
  4. class In2it_Auth_Adapter_FileTest extends PHPUnit_Framework_TestCase
  5. {
  6.     public function goodDataProvider()
  7.     {
  8.         return array (
  9.             array ('test', 'test'),
  10.             array ('abcd', '123hup1234'),
  11.         );
  12.     }
  13.     public function badDataProvider()
  14.     {
  15.         return array (
  16.             array ('test', 'test123'),
  17.             array ('', ''),
  18.         );
  19.     }
  20.     /**
  21.      * @dataProvider goodDataProvider
  22.      */
  23.     public function testAuthenticationIsSuccessful($username, $password)
  24.     {
  25.         $filename = dirname(__FILE__) . '/_files/testusers';
  26.        
  27.         $file = new In2it_Auth_Adapter_File(
  28.             $username,
  29.             $password,
  30.             $filename
  31.         );
  32.         $result = $file->authenticate();
  33.         $this->assertType('Zend_Auth_Result', $result);
  34.         $this->assertSame(Zend_Auth_Result::SUCCESS, $result->getCode());
  35.         $this->assertTrue($result->isValid());
  36.     }
  37.     /**
  38.      * @dataProvider badDataProvider
  39.      */
  40.     public function testAuthenticationFails($username, $password)
  41.     {
  42.         $filename = dirname(__FILE__) . '/_files/testusers';
  43.        
  44.         $file = new In2it_Auth_Adapter_File(
  45.             $username,
  46.             $password,
  47.             $filename
  48.         );
  49.         $result = $file->authenticate();
  50.         $this->assertType('Zend_Auth_Result', $result);
  51.         $this->assertSame(Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID, $result->getCode());
  52.         $this->assertFalse($result->isValid());
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement