1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-08-06 08:47:45 +02:00

[ticket/14542] Move cron to controller

PHPBB3-14542
This commit is contained in:
Máté Bartus
2016-03-18 22:57:02 +01:00
parent d74e85ffd9
commit 6eecc26e31
13 changed files with 374 additions and 83 deletions

View File

@@ -74,7 +74,34 @@ class phpbb_console_command_cron_list_test extends phpbb_test_case
$task->set_name('command' . $i);
$i++;
}
$this->cron_manager = new \phpbb\cron\manager($tasks, $phpbb_root_path, $pathEx);
$mock_config = new \phpbb\config\config(array(
'force_server_vars' => false,
'enable_mod_rewrite' => '',
));
$mock_router = $this->getMockBuilder('\phpbb\routing\router')
->setMethods(array('setContext', 'generate'))
->disableOriginalConstructor()
->getMock();
$mock_router->method('setContext')
->willReturn(true);
$mock_router->method('generate')
->willReturn('foobar');
$request = new \phpbb\request\request();
$routing_helper = new \phpbb\routing\helper(
$mock_config,
$mock_router,
new \phpbb\symfony_request($request),
$request,
new \phpbb\filesystem\filesystem(),
$phpbb_root_path,
$pathEx
);
$this->cron_manager = new \phpbb\cron\manager($tasks, $routing_helper, $phpbb_root_path, $pathEx);
}
public function get_command_tester()

View File

@@ -50,7 +50,34 @@ class phpbb_console_command_cron_run_test extends phpbb_database_test_case
$tasks = array(
$this->task,
);
$this->cron_manager = new \phpbb\cron\manager($tasks, $phpbb_root_path, $phbEx);
$mock_config = new \phpbb\config\config(array(
'force_server_vars' => false,
'enable_mod_rewrite' => '',
));
$mock_router = $this->getMockBuilder('\phpbb\routing\router')
->setMethods(array('setContext', 'generate'))
->disableOriginalConstructor()
->getMock();
$mock_router->method('setContext')
->willReturn(true);
$mock_router->method('generate')
->willReturn('foobar');
$request = new \phpbb\request\request();
$routing_helper = new \phpbb\routing\helper(
$mock_config,
$mock_router,
new \phpbb\symfony_request($request),
$request,
new \phpbb\filesystem\filesystem(),
$phpbb_root_path,
$phpEx
);
$this->cron_manager = new \phpbb\cron\manager($tasks, $routing_helper, $phpbb_root_path, $phpEx);
$this->assertSame('0', $config['cron_lock']);
}
@@ -96,7 +123,34 @@ class phpbb_console_command_cron_run_test extends phpbb_database_test_case
{
$tasks = array(
);
$this->cron_manager = new \phpbb\cron\manager($tasks, $phpbb_root_path, $phpEx);
$mock_config = new \phpbb\config\config(array(
'force_server_vars' => false,
'enable_mod_rewrite' => '',
));
$mock_router = $this->getMockBuilder('\phpbb\routing\router')
->setMethods(array('setContext', 'generate'))
->disableOriginalConstructor()
->getMock();
$mock_router->method('setContext')
->willReturn(true);
$mock_router->method('generate')
->willReturn('foobar');
$request = new \phpbb\request\request();
$routing_helper = new \phpbb\routing\helper(
$mock_config,
$mock_router,
new \phpbb\symfony_request($request),
$request,
new \phpbb\filesystem\filesystem(),
$phpbb_root_path,
$phpEx
);
$this->cron_manager = new \phpbb\cron\manager($tasks, $routing_helper, $phpbb_root_path, $phpEx);
$command_tester = $this->get_command_tester();
$exit_status = $command_tester->execute(array('command' => $this->command_name));
@@ -109,7 +163,34 @@ class phpbb_console_command_cron_run_test extends phpbb_database_test_case
{
$tasks = array(
);
$this->cron_manager = new \phpbb\cron\manager($tasks, $phpbb_root_path, $phpEx);
$mock_config = new \phpbb\config\config(array(
'force_server_vars' => false,
'enable_mod_rewrite' => '',
));
$mock_router = $this->getMockBuilder('\phpbb\routing\router')
->setMethods(array('setContext', 'generate'))
->disableOriginalConstructor()
->getMock();
$mock_router->method('setContext')
->willReturn(true);
$mock_router->method('generate')
->willReturn('foobar');
$request = new \phpbb\request\request();
$routing_helper = new \phpbb\routing\helper(
$mock_config,
$mock_router,
new \phpbb\symfony_request($request),
$request,
new \phpbb\filesystem\filesystem(),
$phpbb_root_path,
$phpEx
);
$this->cron_manager = new \phpbb\cron\manager($tasks, $routing_helper, $phpbb_root_path, $phpEx);
$command_tester = $this->get_command_tester();
$exit_status = $command_tester->execute(array('command' => $this->command_name, '--verbose' => true));

View File

@@ -75,6 +75,32 @@ class phpbb_cron_manager_test extends \phpbb_test_case
{
global $phpbb_root_path, $phpEx;
return new \phpbb\cron\manager($tasks, $phpbb_root_path, $phpEx);
$mock_config = new \phpbb\config\config(array(
'force_server_vars' => false,
'enable_mod_rewrite' => '',
));
$mock_router = $this->getMockBuilder('\phpbb\routing\router')
->setMethods(array('setContext', 'generate'))
->disableOriginalConstructor()
->getMock();
$mock_router->method('setContext')
->willReturn(true);
$mock_router->method('generate')
->willReturn('foobar');
$request = new \phpbb\request\request();
$routing_helper = new \phpbb\routing\helper(
$mock_config,
$mock_router,
new \phpbb\symfony_request($request),
$request,
new \phpbb\filesystem\filesystem(),
$phpbb_root_path,
$phpEx
);
return new \phpbb\cron\manager($tasks, $routing_helper, $phpbb_root_path, $phpEx);
}
}

View File

@@ -37,6 +37,13 @@ class phpbb_functional_controllers_compatibility_test extends phpbb_functional_t
$this->assert301('feed.php?t=1', 'app.php/feed/topic/1');
}
public function test_cron_compatibility()
{
$this->assert301('cron.php?cron_type=foo', 'app.php/cron/foo');
$this->assert301('cron.php?cron_type=foo&bar=foobar', 'app.php/cron/foo?bar=foobar');
$this->assert301('cron.php?cron_type=foo&bar=foobar&who=me', 'app.php/cron/foo?bar=foobar&who=me');
}
protected function assert301($from, $to)
{
self::$client->followRedirects(false);
@@ -44,6 +51,7 @@ class phpbb_functional_controllers_compatibility_test extends phpbb_functional_t
// Fix sid issues
$location = self::$client->getResponse()->getHeader('Location');
$location = str_replace('&', '&', $location);
$location = preg_replace('#sid=[^&]+(&(amp;)?)?#', '', $location);
if (substr($location, -1) === '?')
{

View File

@@ -130,7 +130,16 @@ class phpbb_functional_prune_shadow_topic_test extends phpbb_functional_test_cas
$crawler = self::request('GET', "viewforum.php?f={$this->data['forums']['Prune Shadow']}&sid={$this->sid}");
$this->assertNotEmpty($crawler->filter('img')->last()->attr('src'));
self::request('GET', "cron.php?cron_type=cron.task.core.prune_shadow_topics&f={$this->data['forums']['Prune Shadow']}&sid={$this->sid}", array(), false);
self::request('GET', "app.php/cron/cron.task.core.prune_shadow_topics?f={$this->data['forums']['Prune Shadow']}&sid={$this->sid}", array(), false);
// Try to ensure that the cron can actually run before we start to wait for it
sleep(1);
$cron_lock = new \phpbb\lock\db('cron_lock', new \phpbb\config\db($this->db, new \phpbb\cache\driver\dummy(), 'phpbb_config'), $this->db);
while (!$cron_lock->acquire())
{
// do nothing
}
$cron_lock->release();
$this->assert_forum_details($this->data['forums']['Prune Shadow'], array(
'forum_posts_approved' => 0,