* Copyright 2001-2012 Strangecode, LLC * * This file is part of The Strangecode Codebase. * * The Strangecode Codebase is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License as published by the * Free Software Foundation, either version 3 of the License, or (at your option) * any later version. * * The Strangecode Codebase is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * The Strangecode Codebase. If not, see . */ /** * PHPUnit test case for codebase/lib/Auth_File.inc.php * * The method skeletons below need to be filled in with * real data so that the tests will run correctly. Replace * all EXPECTED_VAL and PARAM strings with real data. * * Created with PHPUnit_Skeleton on 2005-08-09 */ require_once 'PHPUnit.php'; class Auth_FileTest extends PHPUnit_TestCase { var $Auth_File; function Auth_FileTest($name) { $this->PHPUnit_TestCase($name); } function setUp() { require dirname(__FILE__) . '/_config.inc.php'; require_once '../lib/Auth_File.inc.php'; $this->Auth_File =& new Auth_File('test_auth'); $this->Auth_File->setParam(array('htpasswd_file' => dirname(__FILE__) . '/_test_htpasswd')); } function tearDown() { unset($this->Auth_File); } function test_authenticate() { $true = $this->Auth_File->authenticate('testuser', 'testpass'); $this->assertTrue($true, 'testuser not authorized with good password.'); $false = $this->Auth_File->authenticate('testuser', 'wrongpass'); $this->assertFalse($false, 'testuser not blocked with bad password.'); } function test_login() { $result = $this->Auth_File->login('testuser', 'testpass'); $this->assertTrue($result, 'testuser login failed.'); $this->assertTrue($_SESSION['_auth_file'][$this->Auth_File->_ns]['authenticated'], 'testuser authentication not found in session.'); } function test_clear() { $result = $this->Auth_File->login('testuser', 'testpass'); $this->Auth_File->clear(); $this->assertFalse($_SESSION['_auth_file'][$this->Auth_File->_ns]['authenticated'], 'testuser authentication not false in session.'); } function test_isloggedin() { $this->Auth_File->login('testuser', 'testpass'); $true = $this->Auth_File->isloggedin(); $this->assertTrue($true, 'testuser not logged in but should be.'); $this->Auth_File->clear(); $false = $this->Auth_File->isloggedin(); $this->assertFalse($false, 'testuser is logged in but shouldn\'t be.'); } // function test_isadmin() // { // $this->Auth_File->login('testuser', 'testpass'); // $true = $this->Auth_File->isadmin(); // $this->assertTrue($true); // } // // function test_requireadminlogin() // { // $result = $this->Auth_File->requireadminlogin(PARAM); // $expected = EXPECTED_VAL; // $this->assertEquals($expected, $result); // } // // function test__encrypt() // { // $result = $this->Auth_File->_encrypt(PARAM); // $expected = EXPECTED_VAL; // $this->assertEquals($expected, $result); // } // // function test__salt() // { // $result = $this->Auth_File->_salt(PARAM); // $expected = EXPECTED_VAL; // $this->assertEquals($expected, $result); // } } // Running the test. $suite = new PHPUnit_TestSuite('Auth_FileTest'); $result = PHPUnit::run($suite); echo $result->toString();