aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lock/db_test.php
blob: 0702a2c21e2354b0dc14201e10d732b1857fca03 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
/**
*
* @package testing
* @copyright (c) 2010 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

require_once __DIR__ . '/../../phpBB/includes/functions.php';

class phpbb_lock_db_test extends phpbb_database_test_case
{
	private $db;
	private $config;
	private $lock;

	public function getDataSet()
	{
		return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/config.xml');
	}

	public function setUp()
	{
		global $db, $config;

		$db = $this->db = $this->new_dbal();
		$config = $this->config = array('rand_seed' => '', 'rand_seed_last_update' => '0');
		$this->lock = new phpbb_lock_db('test_lock', $this->config, $this->db);
	}

	public function test_new_lock()
	{
		global $config;

		$this->assertTrue($this->lock->lock());
		$this->assertTrue(isset($config['test_lock']), 'Lock was created');

		$lock2 = new phpbb_lock_db('test_lock', $config, $this->db);
		$this->assertFalse($lock2->lock());

		$this->lock->unlock();
		$this->assertEquals('0', $config['test_lock'], 'Lock was released');
	}

	public function test_expire_lock()
	{
		$lock = new phpbb_lock_db('foo_lock', $this->config, $this->db);
		$this->assertTrue($lock->lock());
	}

	public function test_double_lock()
	{
		global $config;

		$this->assertTrue($this->lock->lock());
		$this->assertTrue(isset($config['test_lock']), 'Lock was created');

		$value = $config['test_lock'];

		$this->assertTrue($this->lock->lock());
		$this->assertEquals($value, $config['test_lock'], 'Second lock was ignored');

		$this->lock->unlock();
		$this->assertEquals('0', $config['test_lock'], 'Lock was released');
	}
}