From 09b136272b9ec25824f1c72d0148bdfe43a43603 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Thu, 13 Jan 2011 00:51:32 +0100 Subject: [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 --- tests/cron/manager_test.php | 32 ++++++++++++++++++++------- tests/cron/task/testmod/dummy_task.php | 23 +++++++++++++++++++ tests/cron/task/testmod/second_dummy_task.php | 23 +++++++++++++++++++ 3 files changed, 70 insertions(+), 8 deletions(-) create mode 100644 tests/cron/task/testmod/dummy_task.php create mode 100644 tests/cron/task/testmod/second_dummy_task.php (limited to 'tests/cron') 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 @@ +