* Copyright 2001-2010 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/Lock.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 LockTest extends PHPUnit_TestCase { var $Lock; var $Auth_SQL; function LockTest($name) { $this->PHPUnit_TestCase($name); } function setUp() { require dirname(__FILE__) . '/_config.inc.php'; require_once '../lib/Lock.inc.php'; require_once '../lib/Auth_SQL.inc.php'; $this->Auth_SQL =& new Auth_SQL('test'); $this->Auth_SQL->setParam(array( 'db_table' => 'test_user_tbl', 'db_primary_key' => 'user_id', 'db_login_table' => 'test_login_tbl', 'login_url' => '/login.php', 'blocking' => true )); // Use fresh user table. $this->Auth_SQL->initDB(true); // Insert test data. $db =& DB::getInstance(); $db->query(" INSERT INTO test_user_tbl ( username, userpass, first_name, last_name, email ) VALUES ( 'testuser', '" . $this->Auth_SQL->encryptPassword('testpass') . "', 'John', 'Doe', 'john@example.com' ) "); $this->Auth_SQL->login('testuser', 'testpass'); if (!$this->Auth_SQL->isLoggedIn()) { trigger_error("User login failed...tests canceled.", E_USER_ERROR); } $this->Lock =& Lock::getInstance($this->Auth_SQL); $this->Lock->setParam(array('db_table' => 'test_lock_tbl')); // Use fresh lock table. $this->Lock->initDB(true); } function tearDown() { $db =& DB::getInstance(); unset($this->Lock); unset($this->Auth_SQL); $db->query("DROP TABLE IF EXISTS test_user_tbl"); $db->query("DROP TABLE IF EXISTS test_login_tbl"); $db->query("DROP TABLE IF EXISTS test_lock_tbl"); } function test_getinstance() { $result = Lock::getinstance($this->Auth_SQL); $this->assertTrue($result && is_a($result, 'Lock')); } function test_setparam() { $this->Lock->setparam(array('var'=>'val')); } function test_getparam() { $this->Lock->getparam('var'); } function test_select() { $this->Lock->set('test_user_tbl', 'user_id', '1'); $result = $this->Lock->select('test_user_tbl', 'user_id', '1'); $this->assertTrue($result); } function test_islocked() { $this->Lock->select('test_user_tbl', 'user_id', '1'); $this->Lock->set('test_user_tbl', 'user_id', '1'); $result = $this->Lock->islocked(); $this->assertTrue($result, 'Lock was not set.'); $this->Lock->remove(); $this->Lock->select('test_user_tbl', 'user_id', '1'); $result = $this->Lock->islocked(); $this->assertFalse($result, 'Lock was not removed.'); } function test_ismine() { $this->Lock->set('test_user_tbl', 'user_id', '1'); $this->Lock->select('test_user_tbl', 'user_id', '1'); $result = $this->Lock->ismine(); $this->assertTrue($result); } function test_set() { $this->Lock->select('test_user_tbl', 'user_id', '1'); $this->Lock->remove(); $this->Lock->set('test_user_tbl', 'user_id', '1'); $this->Lock->select('test_user_tbl', 'user_id', '1'); $result = $this->Lock->islocked(); $this->assertTrue($result); } function test_remove() { $this->Lock->select('test_user_tbl', 'user_id', '1'); $this->Lock->set('test_user_tbl', 'user_id', '1'); $this->Lock->remove(); $this->Lock->select('test_user_tbl', 'user_id', '1'); $result = $this->Lock->islocked(); $this->assertFalse($result); } function test_removeall() { $this->Lock->select('test_user_tbl', 'user_id', '1'); $this->Lock->set('test_user_tbl', 'user_id', '1'); $this->Lock->removeall(); $this->Lock->select('test_user_tbl', 'user_id', '1'); $result = $this->Lock->islocked(); $this->assertFalse($result); } function test__auto_timeout() { $this->Lock->_auto_timeout(); } function test_getid() { $this->Lock->select('test_user_tbl', 'user_id', '1'); $this->Lock->set('test_user_tbl', 'user_id', '1'); $result = $this->Lock->getid(); $this->assertTrue('' != $result); $this->assertTrue(is_numeric($result)); } function test_gettitle() { $this->Lock->select('test_user_tbl', 'user_id', '1'); $this->Lock->set('test_user_tbl', 'user_id', '1', 'userlock'); $result = $this->Lock->gettitle(); $this->assertEquals('userlock', $result); } function test_geteditor() { $this->Lock->select('test_user_tbl', 'user_id', '1'); $this->Lock->set('test_user_tbl', 'user_id', '1', 'userlock'); $result = $this->Lock->geteditor(); $this->assertEquals('testuser', $result); } function test_getsecondselapsed() { $result = $this->Lock->getsecondselapsed(); $this->assertType('integer', $result); } } // Running the test. $suite = new PHPUnit_TestSuite('LockTest'); $result = PHPUnit::run($suite); echo $result->toString(); ?>