source: trunk/tests/RecordLockTest.php @ 1

Last change on this file since 1 was 1, checked in by scdev, 19 years ago

Initial import.

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