diff options
Diffstat (limited to 'tests/cron')
-rw-r--r-- | tests/cron/manager_test.php | 83 | ||||
-rw-r--r-- | tests/cron/task/testmod/dummy_task.php | 23 | ||||
-rw-r--r-- | tests/cron/task/testmod/second_dummy_task.php | 23 | ||||
-rw-r--r-- | tests/cron/task2/testmod/simple_not_runnable.php | 13 | ||||
-rw-r--r-- | tests/cron/task2/testmod/simple_ready.php | 8 | ||||
-rw-r--r-- | tests/cron/task2/testmod/simple_should_not_run.php | 13 |
6 files changed, 163 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; + } +} |