source: trunk/tests/Auth_FileTest.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: 4.0 KB
RevLine 
[1]1<?php
2/**
[362]3 * The Strangecode Codebase - a general application development framework for PHP
4 * For details visit the project site: <http://trac.strangecode.com/codebase/>
[396]5 * Copyright 2001-2012 Strangecode, LLC
[468]6 *
[362]7 * This file is part of The Strangecode Codebase.
[42]8 *
[362]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.
[468]13 *
[362]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.
[468]18 *
[362]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/Auth_File.inc.php
25 *
[42]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 *
[1]30 * Created with PHPUnit_Skeleton on 2005-08-09
31 */
32require_once 'PHPUnit.php';
33class Auth_FileTest extends PHPUnit_TestCase {
34
35    var $Auth_File;
36
37    function Auth_FileTest($name)
38    {
39        $this->PHPUnit_TestCase($name);
40    }
41
42    function setUp()
43    {
44        require dirname(__FILE__) . '/_config.inc.php';
45        require_once '../lib/Auth_File.inc.php';
[136]46        $this->Auth_File =& new Auth_File('test_auth');
47        $this->Auth_File->setParam(array('htpasswd_file' => dirname(__FILE__) . '/_test_htpasswd'));
[1]48    }
49
50    function tearDown()
51    {
52        unset($this->Auth_File);
53    }
54
55    function test_authenticate()
56    {
57        $true = $this->Auth_File->authenticate('testuser', 'testpass');
58        $this->assertTrue($true, 'testuser not authorized with good password.');
59
60        $false = $this->Auth_File->authenticate('testuser', 'wrongpass');
61        $this->assertFalse($false, 'testuser not blocked with bad password.');
62    }
63
64    function test_login()
65    {
66        $result = $this->Auth_File->login('testuser', 'testpass');
67        $this->assertTrue($result, 'testuser login failed.');
[154]68        $this->assertTrue($_SESSION['_auth_file'][$this->Auth_File->_ns]['authenticated'], 'testuser authentication not found in session.');
[1]69    }
70
[149]71    function test_clear()
[1]72    {
73        $result = $this->Auth_File->login('testuser', 'testpass');
[149]74        $this->Auth_File->clear();
[154]75        $this->assertFalse($_SESSION['_auth_file'][$this->Auth_File->_ns]['authenticated'], 'testuser authentication not false in session.');
[1]76    }
77
78    function test_isloggedin()
79    {
80        $this->Auth_File->login('testuser', 'testpass');
81        $true = $this->Auth_File->isloggedin();
82        $this->assertTrue($true, 'testuser not logged in but should be.');
83
[149]84        $this->Auth_File->clear();
[1]85        $false = $this->Auth_File->isloggedin();
86        $this->assertFalse($false, 'testuser is logged in but shouldn\'t be.');
87    }
88
89//     function test_isadmin()
90//     {
91//         $this->Auth_File->login('testuser', 'testpass');
92//         $true = $this->Auth_File->isadmin();
93//         $this->assertTrue($true);
94//     }
[42]95//
[1]96//     function test_requireadminlogin()
97//     {
98//         $result = $this->Auth_File->requireadminlogin(PARAM);
99//         $expected = EXPECTED_VAL;
100//         $this->assertEquals($expected, $result);
101//     }
[42]102//
[1]103//     function test__encrypt()
104//     {
105//         $result = $this->Auth_File->_encrypt(PARAM);
106//         $expected = EXPECTED_VAL;
107//         $this->assertEquals($expected, $result);
108//     }
[42]109//
[1]110//     function test__salt()
111//     {
112//         $result = $this->Auth_File->_salt(PARAM);
113//         $expected = EXPECTED_VAL;
114//         $this->assertEquals($expected, $result);
115//     }
116
117}
118// Running the test.
119$suite = new PHPUnit_TestSuite('Auth_FileTest');
120$result = PHPUnit::run($suite);
121echo $result->toString();
Note: See TracBrowser for help on using the repository browser.