[1] | 1 | <?php |
---|
| 2 | /** |
---|
| 3 | * PHPUnit test case for Auth_File |
---|
[42] | 4 | * |
---|
| 5 | * The method skeletons below need to be filled in with |
---|
| 6 | * real data so that the tests will run correctly. Replace |
---|
| 7 | * all EXPECTED_VAL and PARAM strings with real data. |
---|
| 8 | * |
---|
[1] | 9 | * Created with PHPUnit_Skeleton on 2005-08-09 |
---|
| 10 | */ |
---|
| 11 | require_once 'PHPUnit.php'; |
---|
| 12 | class Auth_FileTest extends PHPUnit_TestCase { |
---|
| 13 | |
---|
| 14 | var $Auth_File; |
---|
| 15 | |
---|
| 16 | function Auth_FileTest($name) |
---|
| 17 | { |
---|
| 18 | $this->PHPUnit_TestCase($name); |
---|
| 19 | } |
---|
| 20 | |
---|
| 21 | function setUp() |
---|
| 22 | { |
---|
| 23 | require dirname(__FILE__) . '/_config.inc.php'; |
---|
| 24 | require_once '../lib/Auth_File.inc.php'; |
---|
[126] | 25 | $this->Auth_File =& new Auth_File('test'); |
---|
| 26 | $this->Auth_File->setParam(array('htpasswd_file' => dirname(__FILE__) . '/_test_htpasswd')); |
---|
[1] | 27 | } |
---|
| 28 | |
---|
| 29 | function tearDown() |
---|
| 30 | { |
---|
| 31 | unset($this->Auth_File); |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | function test_authenticate() |
---|
| 35 | { |
---|
| 36 | $true = $this->Auth_File->authenticate('testuser', 'testpass'); |
---|
| 37 | $this->assertTrue($true, 'testuser not authorized with good password.'); |
---|
| 38 | |
---|
| 39 | $false = $this->Auth_File->authenticate('testuser', 'wrongpass'); |
---|
| 40 | $this->assertFalse($false, 'testuser not blocked with bad password.'); |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | function test_login() |
---|
| 44 | { |
---|
| 45 | $result = $this->Auth_File->login('testuser', 'testpass'); |
---|
| 46 | $this->assertTrue($result, 'testuser login failed.'); |
---|
[126] | 47 | $this->assertTrue($_SESSION['_auth_test']['authenticated'], 'testuser authentication not found in session.'); |
---|
[1] | 48 | } |
---|
| 49 | |
---|
| 50 | function test_clearauth() |
---|
| 51 | { |
---|
| 52 | $result = $this->Auth_File->login('testuser', 'testpass'); |
---|
| 53 | $this->Auth_File->clearauth(); |
---|
[126] | 54 | $this->assertFalse($_SESSION['_auth_test']['authenticated'], 'testuser authentication not false in session.'); |
---|
[1] | 55 | } |
---|
| 56 | |
---|
| 57 | function test_isloggedin() |
---|
| 58 | { |
---|
| 59 | $this->Auth_File->login('testuser', 'testpass'); |
---|
| 60 | $true = $this->Auth_File->isloggedin(); |
---|
| 61 | $this->assertTrue($true, 'testuser not logged in but should be.'); |
---|
| 62 | |
---|
| 63 | $this->Auth_File->clearauth(); |
---|
| 64 | $false = $this->Auth_File->isloggedin(); |
---|
| 65 | $this->assertFalse($false, 'testuser is logged in but shouldn\'t be.'); |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | // function test_isadmin() |
---|
| 69 | // { |
---|
| 70 | // $this->Auth_File->login('testuser', 'testpass'); |
---|
| 71 | // $true = $this->Auth_File->isadmin(); |
---|
| 72 | // $this->assertTrue($true); |
---|
| 73 | // } |
---|
[42] | 74 | // |
---|
[1] | 75 | // function test_requireadminlogin() |
---|
| 76 | // { |
---|
| 77 | // $result = $this->Auth_File->requireadminlogin(PARAM); |
---|
| 78 | // $expected = EXPECTED_VAL; |
---|
| 79 | // $this->assertEquals($expected, $result); |
---|
| 80 | // } |
---|
[42] | 81 | // |
---|
[1] | 82 | // function test__encrypt() |
---|
| 83 | // { |
---|
| 84 | // $result = $this->Auth_File->_encrypt(PARAM); |
---|
| 85 | // $expected = EXPECTED_VAL; |
---|
| 86 | // $this->assertEquals($expected, $result); |
---|
| 87 | // } |
---|
[42] | 88 | // |
---|
[1] | 89 | // function test__salt() |
---|
| 90 | // { |
---|
| 91 | // $result = $this->Auth_File->_salt(PARAM); |
---|
| 92 | // $expected = EXPECTED_VAL; |
---|
| 93 | // $this->assertEquals($expected, $result); |
---|
| 94 | // } |
---|
| 95 | |
---|
| 96 | } |
---|
| 97 | // Running the test. |
---|
| 98 | $suite = new PHPUnit_TestSuite('Auth_FileTest'); |
---|
| 99 | $result = PHPUnit::run($suite); |
---|
| 100 | echo $result->toString(); |
---|
| 101 | ?> |
---|