aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorIgor Wiedler <igor@wiedler.ch>2011-02-13 15:54:42 +0100
committerIgor Wiedler <igor@wiedler.ch>2011-02-13 15:54:42 +0100
commit04bd2e640e771948671ab6554df8962de980f511 (patch)
treed1e5a226ca875e940d1d98c710051d1911d8b2ad /tests
parent8f0e9aee5ce518937b7ed05c2cd602e85e5b0b8a (diff)
parent1fd8d6de7f6bb41505530c83e487a9dc18bd25af (diff)
downloadforums-04bd2e640e771948671ab6554df8962de980f511.tar
forums-04bd2e640e771948671ab6554df8962de980f511.tar.gz
forums-04bd2e640e771948671ab6554df8962de980f511.tar.bz2
forums-04bd2e640e771948671ab6554df8962de980f511.tar.xz
forums-04bd2e640e771948671ab6554df8962de980f511.zip
Merge branch 'feature/system-cron' into develop
* feature/system-cron: (67 commits) [feature/system-cron] More tests for cron manager. [feature/system-cron] Added documentation for cron manager constructor. [feature/system-cron] Remove an unecessary assignment and an unecessary comment [feature/system-cron] Clarify comments about flush() call in cron. [feature/system-cron] preg_match returns int so cast to bool, fix comment [feature/system-cron] Rename lock() to acquire and unlock() to release. [feature/system-cron] Cache cron's task names. [feature/system-cron] Use a RecursiveDirectoryIterator instead of readdir. [feature/system-cron] Add array type hints if appropriate and remove globals. [feature/system-cron] Make use of the new config class in locks. [feature/system-cron] Fix duplicate instantiation of class loader in tests. [feature/system-cron] Abstract the database locking mechanism out of cron. [feature/system-cron] Move tests to phpunit.xml and always load class loader [feature/system-cron] Basic tests for cron manager. [feature/system-cron] Added @param/@return documentation [feature/system-cron] Add phpDoc documentation for everything else. [feature/system-cron] Cast result in cron_manager::is_valid_name() to bool. [feature/system-cron] Add phpDoc documentation for phpbb_cron_manager class. [feature/system-cron] Add phpDoc documentation for phpbb_cron_lock class. [feature/system-cron] Adjust SQL query style to follow coding guidelines. ...
Diffstat (limited to 'tests')
-rw-r--r--tests/cron/manager_test.php83
-rw-r--r--tests/cron/task/testmod/dummy_task.php23
-rw-r--r--tests/cron/task/testmod/second_dummy_task.php23
-rw-r--r--tests/cron/task2/testmod/simple_not_runnable.php13
-rw-r--r--tests/cron/task2/testmod/simple_ready.php8
-rw-r--r--tests/cron/task2/testmod/simple_should_not_run.php13
-rw-r--r--tests/lock/db_test.php83
-rw-r--r--tests/lock/fixtures/config.xml13
8 files changed, 259 insertions, 0 deletions
diff --git a/tests/cron/manager_test.php b/tests/cron/manager_test.php
new file mode 100644
index 0000000000..6288a5c641
--- /dev/null
+++ b/tests/cron/manager_test.php
@@ -0,0 +1,83 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2010 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+require_once __DIR__ . '/../mock/cache.php';
+require_once __DIR__ . '/task/testmod/dummy_task.php';
+require_once __DIR__ . '/task/testmod/second_dummy_task.php';
+require_once __DIR__ . '/task2/testmod/simple_ready.php';
+require_once __DIR__ . '/task2/testmod/simple_not_runnable.php';
+require_once __DIR__ . '/task2/testmod/simple_should_not_run.php';
+
+class phpbb_cron_manager_test extends PHPUnit_Framework_TestCase
+{
+ public function setUp()
+ {
+ $this->manager = new phpbb_cron_manager(__DIR__ . '/task/', 'php');
+ $this->task_name = 'phpbb_cron_task_testmod_dummy_task';
+ }
+
+ public function test_manager_finds_shipped_tasks()
+ {
+ $tasks = $this->manager->find_cron_task_names();
+ $this->assertEquals(2, sizeof($tasks));
+ }
+
+ public function test_manager_finds_shipped_task_by_name()
+ {
+ $task = $this->manager->find_task($this->task_name);
+ $this->assertInstanceOf('phpbb_cron_task_wrapper', $task);
+ $this->assertEquals($this->task_name, $task->get_name());
+ }
+
+ public function test_manager_instantiates_task_by_name()
+ {
+ $task = $this->manager->instantiate_task($this->task_name, array());
+ $this->assertInstanceOf('phpbb_cron_task_wrapper', $task);
+ $this->assertEquals($this->task_name, $task->get_name());
+ }
+
+ public function test_manager_finds_all_ready_tasks()
+ {
+ $tasks = $this->manager->find_all_ready_tasks();
+ $this->assertEquals(2, sizeof($tasks));
+ }
+
+ public function test_manager_finds_one_ready_task()
+ {
+ $task = $this->manager->find_one_ready_task();
+ $this->assertInstanceOf('phpbb_cron_task_wrapper', $task);
+ }
+
+ public function test_manager_finds_all_ready_tasks_cached()
+ {
+ $cache = new phpbb_mock_cache(array('_cron_tasks' => array($this->task_name)));
+ $manager = new phpbb_cron_manager(__DIR__ . '/../../phpBB/', 'php', $cache);
+
+ $tasks = $manager->find_all_ready_tasks();
+ $this->assertEquals(1, sizeof($tasks));
+ }
+
+ public function test_manager_finds_only_ready_tasks()
+ {
+ $manager = new phpbb_cron_manager(__DIR__ . '/task2/', 'php');
+ $tasks = $manager->find_all_ready_tasks();
+ $task_names = $this->tasks_to_names($tasks);
+ $this->assertEquals(array('phpbb_cron_task_testmod_simple_ready'), $task_names);
+ }
+
+ private function tasks_to_names($tasks)
+ {
+ $names = array();
+ foreach ($tasks as $task)
+ {
+ $names[] = get_class($task->task);
+ }
+ return $names;
+ }
+}
diff --git a/tests/cron/task/testmod/dummy_task.php b/tests/cron/task/testmod/dummy_task.php
new file mode 100644
index 0000000000..5941157589
--- /dev/null
+++ b/tests/cron/task/testmod/dummy_task.php
@@ -0,0 +1,23 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2010 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+class phpbb_cron_task_testmod_dummy_task extends phpbb_cron_task_base
+{
+ public static $was_run = 0;
+
+ public function run()
+ {
+ self::$was_run++;
+ }
+
+ public function should_run()
+ {
+ return true;
+ }
+}
diff --git a/tests/cron/task/testmod/second_dummy_task.php b/tests/cron/task/testmod/second_dummy_task.php
new file mode 100644
index 0000000000..7118b2ebe7
--- /dev/null
+++ b/tests/cron/task/testmod/second_dummy_task.php
@@ -0,0 +1,23 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2010 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+class phpbb_cron_task_testmod_second_dummy_task extends phpbb_cron_task_base
+{
+ public static $was_run = 0;
+
+ public function run()
+ {
+ self::$was_run++;
+ }
+
+ public function should_run()
+ {
+ return true;
+ }
+}
diff --git a/tests/cron/task2/testmod/simple_not_runnable.php b/tests/cron/task2/testmod/simple_not_runnable.php
new file mode 100644
index 0000000000..54869fa1cc
--- /dev/null
+++ b/tests/cron/task2/testmod/simple_not_runnable.php
@@ -0,0 +1,13 @@
+<?php
+
+class phpbb_cron_task_testmod_simple_not_runnable extends phpbb_cron_task_base
+{
+ public function run()
+ {
+ }
+
+ public function is_runnable()
+ {
+ return false;
+ }
+}
diff --git a/tests/cron/task2/testmod/simple_ready.php b/tests/cron/task2/testmod/simple_ready.php
new file mode 100644
index 0000000000..e407441e90
--- /dev/null
+++ b/tests/cron/task2/testmod/simple_ready.php
@@ -0,0 +1,8 @@
+<?php
+
+class phpbb_cron_task_testmod_simple_ready extends phpbb_cron_task_base
+{
+ public function run()
+ {
+ }
+}
diff --git a/tests/cron/task2/testmod/simple_should_not_run.php b/tests/cron/task2/testmod/simple_should_not_run.php
new file mode 100644
index 0000000000..14ba4cdbd3
--- /dev/null
+++ b/tests/cron/task2/testmod/simple_should_not_run.php
@@ -0,0 +1,13 @@
+<?php
+
+class phpbb_cron_task_testmod_simple_should_not_run extends phpbb_cron_task_base
+{
+ public function run()
+ {
+ }
+
+ public function should_run()
+ {
+ return false;
+ }
+}
diff --git a/tests/lock/db_test.php b/tests/lock/db_test.php
new file mode 100644
index 0000000000..3b2e3ea3b2
--- /dev/null
+++ b/tests/lock/db_test.php
@@ -0,0 +1,83 @@
+<?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 = new phpbb_config(array('rand_seed' => '', 'rand_seed_last_update' => '0'));
+ set_config(null, null, null, $this->config);
+ $this->lock = new phpbb_lock_db('test_lock', $this->config, $this->db);
+ }
+
+ public function test_new_lock()
+ {
+ $this->assertTrue($this->lock->acquire());
+ $this->assertTrue(isset($this->config['test_lock']), 'Lock was created');
+
+ $lock2 = new phpbb_lock_db('test_lock', $this->config, $this->db);
+ $this->assertFalse($lock2->acquire());
+
+ $this->lock->release();
+ $this->assertEquals('0', $this->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->acquire());
+ }
+
+ public function test_double_lock()
+ {
+ $this->assertTrue($this->lock->acquire());
+ $this->assertTrue(isset($this->config['test_lock']), 'Lock was created');
+
+ $value = $this->config['test_lock'];
+
+ $this->assertFalse($this->lock->acquire());
+ $this->assertEquals($value, $this->config['test_lock'], 'Second lock failed');
+
+ $this->lock->release();
+ $this->assertEquals('0', $this->config['test_lock'], 'Lock was released');
+ }
+
+ public function test_double_unlock()
+ {
+ $this->assertTrue($this->lock->acquire());
+ $this->assertFalse(empty($this->config['test_lock']), 'First lock is acquired');
+
+ $this->lock->release();
+ $this->assertEquals('0', $this->config['test_lock'], 'First lock is released');
+
+ $lock2 = new phpbb_lock_db('test_lock', $this->config, $this->db);
+ $this->assertTrue($lock2->acquire());
+ $this->assertFalse(empty($this->config['test_lock']), 'Second lock is acquired');
+
+ $this->lock->release();
+ $this->assertFalse(empty($this->config['test_lock']), 'Double release of first lock is ignored');
+
+ $lock2->release();
+ $this->assertEquals('0', $this->config['test_lock'], 'Second lock is released');
+ }
+}
diff --git a/tests/lock/fixtures/config.xml b/tests/lock/fixtures/config.xml
new file mode 100644
index 0000000000..f36c8b929a
--- /dev/null
+++ b/tests/lock/fixtures/config.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_config">
+ <column>config_name</column>
+ <column>config_value</column>
+ <column>is_dynamic</column>
+ <row>
+ <value>foo_lock</value>
+ <value>1 abcd</value>
+ <value>1</value>
+ </row>
+ </table>
+</dataset>