source: trunk/tests/AuthFileTest.php

Last change on this file was 468, checked in by anonymous, 10 years ago

Completed integrating /branches/eli_branch into /trunk. Changes include:

  • Removed closing ?> from end of files
  • Upgrade old-style contructor methods to use construct() instead.
  • Class properties and methods defined as public, private, static or protected
  • Ensure code runs under E_ALL with only mysql_* deprecated warnings
  • Search for the '@' symbol anywhere it might be used to supress runtime errors, then replace with proper error recovery.
  • Run the php cli -l option to check files for syntax errors.
  • Bring tests up-to-date with latest version and methods of PHPUnit
File size: 3.8 KB
Line 
1<?php
2/**
3 * The Strangecode Codebase - a general application development framework for PHP
4 * For details visit the project site: <http://trac.strangecode.com/codebase/>
5 * Copyright 2001-2012 Strangecode, LLC
6 *
7 * This file is part of The Strangecode Codebase.
8 *
9 * The Strangecode Codebase is free software: you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as published by the
11 * Free Software Foundation, either version 3 of the License, or (at your option)
12 * any later version.
13 *
14 * The Strangecode Codebase is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * details.
18 *
19 * You should have received a copy of the GNU General Public License along with
20 * The Strangecode Codebase. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23/**
24 * PHPUnit test case for codebase/lib/AuthFile.inc.php
25 *
26 * The method skeletons below need to be filled in with
27 * real data so that the tests will run correctly. Replace
28 * all EXPECTED_VAL and PARAM strings with real data.
29 *
30 * Created with PHPUnit_Skeleton on 2005-08-09
31 */
32//
33class AuthFileTest extends PHPUnit_Framework_TestCase {
34
35    var $AuthFile;
36   
37    static $shared_session;
38
39    function setUp()
40    {
41        require dirname(__FILE__) . '/_config.inc.php';
42        require_once '../lib/Auth_File.inc.php';
43        $this->AuthFile = new Auth_File('test_auth');
44        $this->AuthFile->setParam(array('htpasswd_file' => dirname(__FILE__) . '/_test_htpasswd'));
45        $_SESSION = AuthFileTest::$shared_session;
46    }
47
48    function tearDown()
49    {
50        unset($this->AuthFile);
51        AuthFileTest::$shared_session = $_SESSION;
52    }
53
54    function test_authenticate()
55    {
56        $true = $this->AuthFile->authenticate('testuser', 'testpass');
57        $this->assertTrue($true, 'testuser not authorized with good password.');
58
59        $false = $this->AuthFile->authenticate('testuser', 'wrongpass');
60        $this->assertFalse($false, 'testuser not blocked with bad password.');
61    }
62
63    function test_login()
64    {
65        $result = $this->AuthFile->login('testuser', 'testpass');
66        $this->assertTrue($result, 'testuser login failed.');
67        $this->assertTrue($_SESSION['_auth_file']['test_auth']['authenticated'], 'testuser authentication not found in session.');
68    }
69
70    function test_clear()
71    {
72        $result = $this->AuthFile->login('testuser', 'testpass');
73        $this->AuthFile->clear();
74        $this->assertFalse($_SESSION['_auth_file']['test_auth']['authenticated'], 'testuser authentication not false in session.');
75    }
76
77    function test_isloggedin()
78    {
79        $this->AuthFile->login('testuser', 'testpass');
80        $true = $this->AuthFile->isloggedin();
81        $this->assertTrue($true, 'testuser not logged in but should be.');
82
83        $this->AuthFile->clear();
84        $false = $this->AuthFile->isloggedin();
85        $this->assertFalse($false, 'testuser is logged in but shouldn\'t be.');
86    }
87
88//     function test_isadmin()
89//     {
90//         $this->AuthFile->login('testuser', 'testpass');
91//         $true = $this->AuthFile->isadmin();
92//         $this->assertTrue($true);
93//     }
94//
95//     function test_requireadminlogin()
96//     {
97//         $result = $this->AuthFile->requireadminlogin(PARAM);
98//         $expected = EXPECTED_VAL;
99//         $this->assertEquals($expected, $result);
100//     }
101//
102//     function test__encrypt()
103//     {
104//         $result = $this->AuthFile->_encrypt(PARAM);
105//         $expected = EXPECTED_VAL;
106//         $this->assertEquals($expected, $result);
107//     }
108//
109//     function test__salt()
110//     {
111//         $result = $this->AuthFile->_salt(PARAM);
112//         $expected = EXPECTED_VAL;
113//         $this->assertEquals($expected, $result);
114//     }
115
116}
Note: See TracBrowser for help on using the repository browser.