[1] | 1 | <?php |
---|
| 2 | /** |
---|
| 3 | * PHPUnit test case for RecordLock |
---|
[42] | 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 | * |
---|
[1] | 9 | * Created with PHPUnit_Skeleton on 2005-08-09 |
---|
| 10 | */ |
---|
| 11 | require_once 'PHPUnit.php'; |
---|
| 12 | class RecordLockTest extends PHPUnit_TestCase { |
---|
| 13 | |
---|
| 14 | var $RecordLock; |
---|
| 15 | var $Auth_SQL; |
---|
| 16 | |
---|
| 17 | function RecordLockTest($name) |
---|
| 18 | { |
---|
| 19 | $this->PHPUnit_TestCase($name); |
---|
| 20 | } |
---|
| 21 | |
---|
| 22 | function setUp() |
---|
| 23 | { |
---|
[130] | 24 | $db =& DB::getInstance(); |
---|
| 25 | |
---|
[1] | 26 | require dirname(__FILE__) . '/_config.inc.php'; |
---|
| 27 | require_once '../lib/RecordLock.inc.php'; |
---|
| 28 | require_once '../lib/Auth_SQL.inc.php'; |
---|
| 29 | |
---|
| 30 | $this->Auth_SQL =& new Auth_SQL('testauth'); |
---|
| 31 | $this->Auth_SQL->setParam(array( |
---|
| 32 | 'db_table' => 'test_user_tbl', |
---|
| 33 | 'db_primary_key' => 'user_id', |
---|
| 34 | 'db_login_table' => 'test_login_tbl', |
---|
| 35 | 'login_url' => '/login.php', |
---|
| 36 | 'blocking' => true |
---|
| 37 | )); |
---|
| 38 | |
---|
| 39 | // Use fresh user table. |
---|
| 40 | $this->Auth_SQL->initDB(true); |
---|
| 41 | |
---|
| 42 | // Insert test data. |
---|
[130] | 43 | $db->query(" |
---|
[1] | 44 | INSERT INTO test_user_tbl ( |
---|
| 45 | username, |
---|
| 46 | userpass, |
---|
| 47 | first_name, |
---|
| 48 | last_name, |
---|
| 49 | email, |
---|
| 50 | user_type |
---|
| 51 | ) VALUES ( |
---|
| 52 | 'testuser', |
---|
| 53 | md5('testpass'), |
---|
| 54 | 'John', |
---|
| 55 | 'Doe', |
---|
| 56 | 'john@example.com', |
---|
| 57 | 'admin' |
---|
| 58 | ) |
---|
| 59 | "); |
---|
| 60 | $this->Auth_SQL->login('testuser', 'testpass'); |
---|
| 61 | |
---|
| 62 | $this->RecordLock =& RecordLock::getInstance($this->Auth_SQL); |
---|
| 63 | $this->RecordLock->setParam(array('db_table' => 'test_lock_tbl')); |
---|
| 64 | |
---|
| 65 | // Use fresh lock table. |
---|
| 66 | $this->RecordLock->initDB(true); |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | function tearDown() |
---|
| 70 | { |
---|
[130] | 71 | $db =& DB::getInstance(); |
---|
| 72 | |
---|
[1] | 73 | unset($this->RecordLock); |
---|
| 74 | unset($this->Auth_SQL); |
---|
[130] | 75 | $db->query("DROP TABLE IF EXISTS test_user_tbl"); |
---|
| 76 | $db->query("DROP TABLE IF EXISTS test_login_tbl"); |
---|
| 77 | $db->query("DROP TABLE IF EXISTS test_lock_tbl"); |
---|
[1] | 78 | } |
---|
| 79 | |
---|
| 80 | function test_getinstance() |
---|
| 81 | { |
---|
| 82 | $result = RecordLock::getinstance($this->Auth_SQL); |
---|
| 83 | $this->assertTrue($result && is_a($result, 'RecordLock')); |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | function test_setparam() |
---|
| 87 | { |
---|
| 88 | $this->RecordLock->setparam(array('var'=>'val')); |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | function test_getparam() |
---|
| 92 | { |
---|
| 93 | $this->RecordLock->getparam('var'); |
---|
| 94 | } |
---|
| 95 | |
---|
| 96 | function test_select() |
---|
| 97 | { |
---|
| 98 | $this->RecordLock->set('test_user_tbl', 'user_id', '1'); |
---|
| 99 | $result = $this->RecordLock->select('test_user_tbl', 'user_id', '1'); |
---|
| 100 | $this->assertTrue($result); |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | function test_islocked() |
---|
| 104 | { |
---|
| 105 | $this->RecordLock->select('test_user_tbl', 'user_id', '1'); |
---|
| 106 | |
---|
| 107 | $this->RecordLock->set('test_user_tbl', 'user_id', '1'); |
---|
| 108 | $result = $this->RecordLock->islocked(); |
---|
| 109 | $this->assertTrue($result, 'Lock was not set.'); |
---|
| 110 | |
---|
| 111 | $this->RecordLock->remove(); |
---|
| 112 | $this->RecordLock->select('test_user_tbl', 'user_id', '1'); |
---|
| 113 | $result = $this->RecordLock->islocked(); |
---|
| 114 | $this->assertFalse($result, 'Lock was not removed.'); |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | function test_ismine() |
---|
| 118 | { |
---|
| 119 | $this->RecordLock->set('test_user_tbl', 'user_id', '1'); |
---|
| 120 | $this->RecordLock->select('test_user_tbl', 'user_id', '1'); |
---|
| 121 | $result = $this->RecordLock->ismine(); |
---|
| 122 | $this->assertTrue($result); |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | function test_set() |
---|
| 126 | { |
---|
| 127 | $this->RecordLock->select('test_user_tbl', 'user_id', '1'); |
---|
| 128 | $this->RecordLock->remove(); |
---|
| 129 | $this->RecordLock->set('test_user_tbl', 'user_id', '1'); |
---|
| 130 | $this->RecordLock->select('test_user_tbl', 'user_id', '1'); |
---|
| 131 | $result = $this->RecordLock->islocked(); |
---|
| 132 | $this->assertTrue($result); |
---|
| 133 | } |
---|
| 134 | |
---|
| 135 | function test_remove() |
---|
| 136 | { |
---|
| 137 | $this->RecordLock->select('test_user_tbl', 'user_id', '1'); |
---|
| 138 | $this->RecordLock->set('test_user_tbl', 'user_id', '1'); |
---|
| 139 | $this->RecordLock->remove(); |
---|
| 140 | $this->RecordLock->select('test_user_tbl', 'user_id', '1'); |
---|
| 141 | $result = $this->RecordLock->islocked(); |
---|
| 142 | $this->assertFalse($result); |
---|
| 143 | } |
---|
| 144 | |
---|
| 145 | function test_removeall() |
---|
| 146 | { |
---|
| 147 | $this->RecordLock->select('test_user_tbl', 'user_id', '1'); |
---|
| 148 | $this->RecordLock->set('test_user_tbl', 'user_id', '1'); |
---|
| 149 | $this->RecordLock->removeall(); |
---|
| 150 | $this->RecordLock->select('test_user_tbl', 'user_id', '1'); |
---|
| 151 | $result = $this->RecordLock->islocked(); |
---|
| 152 | $this->assertFalse($result); |
---|
| 153 | } |
---|
| 154 | |
---|
| 155 | function test__auto_timeout() |
---|
| 156 | { |
---|
| 157 | $this->RecordLock->_auto_timeout(); |
---|
| 158 | } |
---|
| 159 | |
---|
| 160 | function test_getid() |
---|
| 161 | { |
---|
| 162 | $this->RecordLock->select('test_user_tbl', 'user_id', '1'); |
---|
| 163 | $this->RecordLock->set('test_user_tbl', 'user_id', '1'); |
---|
| 164 | $result = $this->RecordLock->getid(); |
---|
| 165 | $this->assertTrue('' != $result); |
---|
| 166 | $this->assertTrue(is_numeric($result)); |
---|
| 167 | } |
---|
| 168 | |
---|
| 169 | function test_gettitle() |
---|
| 170 | { |
---|
| 171 | $this->RecordLock->select('test_user_tbl', 'user_id', '1'); |
---|
| 172 | $this->RecordLock->set('test_user_tbl', 'user_id', '1', 'userlock'); |
---|
| 173 | $result = $this->RecordLock->gettitle(); |
---|
| 174 | $this->assertEquals('userlock', $result); |
---|
| 175 | } |
---|
| 176 | |
---|
| 177 | function test_geteditor() |
---|
| 178 | { |
---|
| 179 | $this->RecordLock->select('test_user_tbl', 'user_id', '1'); |
---|
| 180 | $this->RecordLock->set('test_user_tbl', 'user_id', '1', 'userlock'); |
---|
| 181 | $result = $this->RecordLock->geteditor(); |
---|
| 182 | $this->assertEquals('testuser', $result); |
---|
| 183 | } |
---|
| 184 | |
---|
| 185 | function test_getsecondselapsed() |
---|
| 186 | { |
---|
| 187 | $result = $this->RecordLock->getsecondselapsed(); |
---|
| 188 | $this->assertType('integer', $result); |
---|
| 189 | } |
---|
| 190 | |
---|
| 191 | } |
---|
| 192 | // Running the test. |
---|
| 193 | $suite = new PHPUnit_TestSuite('RecordLockTest'); |
---|
| 194 | $result = PHPUnit::run($suite); |
---|
| 195 | echo $result->toString(); |
---|
| 196 | ?> |
---|