1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-07-30 21:40:43 +02:00

[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
This commit is contained in:
Nils Adermann
2011-01-13 00:51:32 +01:00
committed by Oleg Pudeyev
parent 7a8233020b
commit 09b136272b
6 changed files with 106 additions and 21 deletions

View File

@@ -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));
}
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}