diff options
Diffstat (limited to 'tests/cron')
-rw-r--r-- | tests/cron/ext/testext/cron/dummy_task.php | 28 | ||||
-rw-r--r-- | tests/cron/includes/cron/task/core/dummy_task.php | 28 | ||||
-rw-r--r-- | tests/cron/includes/cron/task/core/second_dummy_task.php | 28 | ||||
-rw-r--r-- | tests/cron/manager_test.php | 76 | ||||
-rw-r--r-- | tests/cron/tasks/simple_not_runnable.php | 18 | ||||
-rw-r--r-- | tests/cron/tasks/simple_ready.php | 13 | ||||
-rw-r--r-- | tests/cron/tasks/simple_should_not_run.php | 18 |
7 files changed, 209 insertions, 0 deletions
diff --git a/tests/cron/ext/testext/cron/dummy_task.php b/tests/cron/ext/testext/cron/dummy_task.php new file mode 100644 index 0000000000..8cdb6b09d5 --- /dev/null +++ b/tests/cron/ext/testext/cron/dummy_task.php @@ -0,0 +1,28 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2010 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +class phpbb_ext_testext_cron_dummy_task extends \phpbb\cron\task\base +{ + static public $was_run = 0; + + public function get_name() + { + return get_class($this); + } + + public function run() + { + self::$was_run++; + } + + public function should_run() + { + return true; + } +} diff --git a/tests/cron/includes/cron/task/core/dummy_task.php b/tests/cron/includes/cron/task/core/dummy_task.php new file mode 100644 index 0000000000..c34684701b --- /dev/null +++ b/tests/cron/includes/cron/task/core/dummy_task.php @@ -0,0 +1,28 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2010 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +class phpbb_cron_task_core_dummy_task extends \phpbb\cron\task\base +{ + static public $was_run = 0; + + public function get_name() + { + return get_class($this); + } + + public function run() + { + self::$was_run++; + } + + public function should_run() + { + return true; + } +} diff --git a/tests/cron/includes/cron/task/core/second_dummy_task.php b/tests/cron/includes/cron/task/core/second_dummy_task.php new file mode 100644 index 0000000000..1b212ab05d --- /dev/null +++ b/tests/cron/includes/cron/task/core/second_dummy_task.php @@ -0,0 +1,28 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2010 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +class phpbb_cron_task_core_second_dummy_task extends \phpbb\cron\task\base +{ + static public $was_run = 0; + + public function get_name() + { + return get_class($this); + } + + public function run() + { + self::$was_run++; + } + + public function should_run() + { + return true; + } +} diff --git a/tests/cron/manager_test.php b/tests/cron/manager_test.php new file mode 100644 index 0000000000..713f44c1e2 --- /dev/null +++ b/tests/cron/manager_test.php @@ -0,0 +1,76 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2010 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +require_once dirname(__FILE__) . '/includes/cron/task/core/dummy_task.php'; +require_once dirname(__FILE__) . '/includes/cron/task/core/second_dummy_task.php'; +require_once dirname(__FILE__) . '/ext/testext/cron/dummy_task.php'; +require_once dirname(__FILE__) . '/tasks/simple_ready.php'; +require_once dirname(__FILE__) . '/tasks/simple_not_runnable.php'; +require_once dirname(__FILE__) . '/tasks/simple_should_not_run.php'; + +class phpbb_cron_manager_test extends PHPUnit_Framework_TestCase +{ + public function setUp() + { + $this->manager = $this->create_cron_manager(array( + new phpbb_cron_task_core_dummy_task(), + new phpbb_cron_task_core_second_dummy_task(), + new phpbb_ext_testext_cron_dummy_task(), + )); + $this->task_name = 'phpbb_cron_task_core_dummy_task'; + } + + 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_finds_all_ready_tasks() + { + $tasks = $this->manager->find_all_ready_tasks(); + $this->assertEquals(3, 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_only_ready_tasks() + { + $manager = $this->create_cron_manager(array( + new phpbb_cron_task_core_simple_ready(), + new phpbb_cron_task_core_simple_not_runnable(), + new phpbb_cron_task_core_simple_should_not_run(), + )); + $tasks = $manager->find_all_ready_tasks(); + $task_names = $this->tasks_to_names($tasks); + $this->assertEquals(array('phpbb_cron_task_core_simple_ready'), $task_names); + } + + private function tasks_to_names($tasks) + { + $names = array(); + foreach ($tasks as $task) + { + $names[] = $task->get_name(); + } + return $names; + } + + private function create_cron_manager($tasks) + { + global $phpbb_root_path, $phpEx; + + return new \phpbb\cron\manager($tasks, $phpbb_root_path, $phpEx); + } +} diff --git a/tests/cron/tasks/simple_not_runnable.php b/tests/cron/tasks/simple_not_runnable.php new file mode 100644 index 0000000000..4951b5b4b9 --- /dev/null +++ b/tests/cron/tasks/simple_not_runnable.php @@ -0,0 +1,18 @@ +<?php + +class phpbb_cron_task_core_simple_not_runnable extends \phpbb\cron\task\base +{ + public function get_name() + { + return get_class($this); + } + + public function run() + { + } + + public function is_runnable() + { + return false; + } +} diff --git a/tests/cron/tasks/simple_ready.php b/tests/cron/tasks/simple_ready.php new file mode 100644 index 0000000000..245d9ba738 --- /dev/null +++ b/tests/cron/tasks/simple_ready.php @@ -0,0 +1,13 @@ +<?php + +class phpbb_cron_task_core_simple_ready extends \phpbb\cron\task\base +{ + public function get_name() + { + return get_class($this); + } + + public function run() + { + } +} diff --git a/tests/cron/tasks/simple_should_not_run.php b/tests/cron/tasks/simple_should_not_run.php new file mode 100644 index 0000000000..7bd9df31b6 --- /dev/null +++ b/tests/cron/tasks/simple_should_not_run.php @@ -0,0 +1,18 @@ +<?php + +class phpbb_cron_task_core_simple_should_not_run extends \phpbb\cron\task\base +{ + public function get_name() + { + return get_class($this); + } + + public function run() + { + } + + public function should_run() + { + return false; + } +} |