aboutsummaryrefslogtreecommitdiffstats
path: root/tests/cron
diff options
context:
space:
mode:
authorNils Adermann <naderman@naderman.de>2011-01-13 00:51:32 +0100
committerOleg Pudeyev <oleg@bsdpower.com>2011-02-12 22:05:54 -0500
commit09b136272b9ec25824f1c72d0148bdfe43a43603 (patch)
treeaaadafee6c7a7dd2b0d70c7b774349561fc0fd93 /tests/cron
parent7a8233020bdeb872dad6057b7799c43c1543aba4 (diff)
downloadforums-09b136272b9ec25824f1c72d0148bdfe43a43603.tar
forums-09b136272b9ec25824f1c72d0148bdfe43a43603.tar.gz
forums-09b136272b9ec25824f1c72d0148bdfe43a43603.tar.bz2
forums-09b136272b9ec25824f1c72d0148bdfe43a43603.tar.xz
forums-09b136272b9ec25824f1c72d0148bdfe43a43603.zip
[feature/system-cron] Cache cron's task names.
Instead of using a path relative to phpbb_root_path the path to the task directory is directly passed to the cron manager. Dummy tasks are now in the tests directory directly. PHPBB3-9596
Diffstat (limited to 'tests/cron')
-rw-r--r--tests/cron/manager_test.php32
-rw-r--r--tests/cron/task/testmod/dummy_task.php23
-rw-r--r--tests/cron/task/testmod/second_dummy_task.php23
3 files changed, 70 insertions, 8 deletions
diff --git a/tests/cron/manager_test.php b/tests/cron/manager_test.php
index 39e052bd57..c282a802b2 100644
--- a/tests/cron/manager_test.php
+++ b/tests/cron/manager_test.php
@@ -7,40 +7,56 @@
*
*/
+require_once __DIR__ . '/../mock/cache.php';
+require_once __DIR__ . '/task/testmod/dummy_task.php';
+require_once __DIR__ . '/task/testmod/second_dummy_task.php';
+
class phpbb_cron_manager_test extends PHPUnit_Framework_TestCase
{
public function setUp()
{
- $this->manager = new phpbb_cron_manager(__DIR__ . '/../../phpBB/', 'php');
+ $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->assertGreaterThan(1, count($tasks));
+ $this->assertEquals(2, sizeof($tasks));
}
public function test_manager_finds_shipped_task_by_name()
{
- $task = $this->manager->find_task('phpbb_cron_task_core_queue');
- $this->assertNotNull($task);
+ $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('phpbb_cron_task_core_queue', array());
- $this->assertNotNull($task);
+ $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->assertGreaterThan(0, count($tasks));
+ $this->assertEquals(2, sizeof($tasks));
}
public function test_manager_finds_one_ready_task()
{
$task = $this->manager->find_one_ready_task();
- $this->assertNotNull($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));
}
}
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;
+ }
+}