aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lock/db_test.php
diff options
context:
space:
mode:
authorNils Adermann <naderman@naderman.de>2011-01-07 20:58:28 +0100
committerOleg Pudeyev <oleg@bsdpower.com>2011-02-12 22:05:53 -0500
commit3a3a8bb96d0cb7be2529ab095f305fd3b042783c (patch)
treee8bc13cacb8ab2f9803c2d13d55025e4903e4d7f /tests/lock/db_test.php
parent6e5e4721d83c8bde9780b02bd011bdbf5d188dea (diff)
downloadforums-3a3a8bb96d0cb7be2529ab095f305fd3b042783c.tar
forums-3a3a8bb96d0cb7be2529ab095f305fd3b042783c.tar.gz
forums-3a3a8bb96d0cb7be2529ab095f305fd3b042783c.tar.bz2
forums-3a3a8bb96d0cb7be2529ab095f305fd3b042783c.tar.xz
forums-3a3a8bb96d0cb7be2529ab095f305fd3b042783c.zip
[feature/system-cron] Abstract the database locking mechanism out of cron.
Added a number of tests for the locking mechanism which can now lock arbitrary config variables. PHPBB3-9596
Diffstat (limited to 'tests/lock/db_test.php')
-rw-r--r--tests/lock/db_test.php67
1 files changed, 67 insertions, 0 deletions
diff --git a/tests/lock/db_test.php b/tests/lock/db_test.php
new file mode 100644
index 0000000000..0702a2c21e
--- /dev/null
+++ b/tests/lock/db_test.php
@@ -0,0 +1,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');
+ }
+}