1 | <?php |
---|
2 | /** |
---|
3 | * PHPUnit test case for Auth_File |
---|
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 | * |
---|
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'; |
---|
25 | $this->Auth_File =& new Auth_File(array('htpasswd_file' => dirname(__FILE__) . '/_test_htpasswd')); |
---|
26 | } |
---|
27 | |
---|
28 | function tearDown() |
---|
29 | { |
---|
30 | unset($this->Auth_File); |
---|
31 | } |
---|
32 | |
---|
33 | function test_authenticate() |
---|
34 | { |
---|
35 | $true = $this->Auth_File->authenticate('testuser', 'testpass'); |
---|
36 | $this->assertTrue($true, 'testuser not authorized with good password.'); |
---|
37 | |
---|
38 | $false = $this->Auth_File->authenticate('testuser', 'wrongpass'); |
---|
39 | $this->assertFalse($false, 'testuser not blocked with bad password.'); |
---|
40 | } |
---|
41 | |
---|
42 | function test_login() |
---|
43 | { |
---|
44 | $result = $this->Auth_File->login('testuser', 'testpass'); |
---|
45 | $this->assertTrue($result, 'testuser login failed.'); |
---|
46 | $this->assertTrue($_SESSION['_auth']['authenticated'], 'testuser authentication not found in session.'); |
---|
47 | } |
---|
48 | |
---|
49 | function test_clearauth() |
---|
50 | { |
---|
51 | $result = $this->Auth_File->login('testuser', 'testpass'); |
---|
52 | $this->Auth_File->clearauth(); |
---|
53 | $this->assertFalse($_SESSION['_auth']['authenticated'], 'testuser authentication not false in session.'); |
---|
54 | } |
---|
55 | |
---|
56 | function test_isloggedin() |
---|
57 | { |
---|
58 | $this->Auth_File->login('testuser', 'testpass'); |
---|
59 | $true = $this->Auth_File->isloggedin(); |
---|
60 | $this->assertTrue($true, 'testuser not logged in but should be.'); |
---|
61 | |
---|
62 | $this->Auth_File->clearauth(); |
---|
63 | $false = $this->Auth_File->isloggedin(); |
---|
64 | $this->assertFalse($false, 'testuser is logged in but shouldn\'t be.'); |
---|
65 | } |
---|
66 | |
---|
67 | // function test_isadmin() |
---|
68 | // { |
---|
69 | // $this->Auth_File->login('testuser', 'testpass'); |
---|
70 | // $true = $this->Auth_File->isadmin(); |
---|
71 | // $this->assertTrue($true); |
---|
72 | // } |
---|
73 | // |
---|
74 | // function test_requireadminlogin() |
---|
75 | // { |
---|
76 | // $result = $this->Auth_File->requireadminlogin(PARAM); |
---|
77 | // $expected = EXPECTED_VAL; |
---|
78 | // $this->assertEquals($expected, $result); |
---|
79 | // } |
---|
80 | // |
---|
81 | // function test__encrypt() |
---|
82 | // { |
---|
83 | // $result = $this->Auth_File->_encrypt(PARAM); |
---|
84 | // $expected = EXPECTED_VAL; |
---|
85 | // $this->assertEquals($expected, $result); |
---|
86 | // } |
---|
87 | // |
---|
88 | // function test__salt() |
---|
89 | // { |
---|
90 | // $result = $this->Auth_File->_salt(PARAM); |
---|
91 | // $expected = EXPECTED_VAL; |
---|
92 | // $this->assertEquals($expected, $result); |
---|
93 | // } |
---|
94 | |
---|
95 | } |
---|
96 | // Running the test. |
---|
97 | $suite = new PHPUnit_TestSuite('Auth_FileTest'); |
---|
98 | $result = PHPUnit::run($suite); |
---|
99 | echo $result->toString(); |
---|
100 | ?> |
---|