source: trunk/tests/Auth_FileTest.php @ 154

Last change on this file since 154 was 154, checked in by scdev, 18 years ago

${1}

File size: 3.0 KB
Line 
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 */
11require_once 'PHPUnit.php';
12class 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('test_auth');
26        $this->Auth_File->setParam(array('htpasswd_file' => dirname(__FILE__) . '/_test_htpasswd'));
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.');
47        $this->assertTrue($_SESSION['_auth_file'][$this->Auth_File->_ns]['authenticated'], 'testuser authentication not found in session.');
48    }
49
50    function test_clear()
51    {
52        $result = $this->Auth_File->login('testuser', 'testpass');
53        $this->Auth_File->clear();
54        $this->assertFalse($_SESSION['_auth_file'][$this->Auth_File->_ns]['authenticated'], 'testuser authentication not false in session.');
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->clear();
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//     }
74//
75//     function test_requireadminlogin()
76//     {
77//         $result = $this->Auth_File->requireadminlogin(PARAM);
78//         $expected = EXPECTED_VAL;
79//         $this->assertEquals($expected, $result);
80//     }
81//
82//     function test__encrypt()
83//     {
84//         $result = $this->Auth_File->_encrypt(PARAM);
85//         $expected = EXPECTED_VAL;
86//         $this->assertEquals($expected, $result);
87//     }
88//
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);
100echo $result->toString();
101?>
Note: See TracBrowser for help on using the repository browser.