diff options
author | LEZY Thomas <thomas.gif.91@gmail.com> | 2014-05-27 12:36:44 +0200 |
---|---|---|
committer | LEZY Thomas <thomas.gif.91@gmail.com> | 2014-05-27 18:37:37 +0200 |
commit | abb8a2892d862c097285ee7f300d12c32428e12c (patch) | |
tree | 78cdcdbd88ef88aaacef3ccaccb792bd2bdccaab /tests/console | |
parent | 1b73c217f0ba80e448bb3f34ffe8ed082fa5e99f (diff) | |
download | forums-abb8a2892d862c097285ee7f300d12c32428e12c.tar forums-abb8a2892d862c097285ee7f300d12c32428e12c.tar.gz forums-abb8a2892d862c097285ee7f300d12c32428e12c.tar.bz2 forums-abb8a2892d862c097285ee7f300d12c32428e12c.tar.xz forums-abb8a2892d862c097285ee7f300d12c32428e12c.zip |
[ticket/12597] Command for executing all available cron tasks
Command cron:execute-all executes all available cron tasks.
Test files in tests/console/cron folder
PHPBB3-12597
Diffstat (limited to 'tests/console')
-rw-r--r-- | tests/console/cron/execute_all_test.php | 85 | ||||
-rw-r--r-- | tests/console/cron/fixtures/config.xml | 9 | ||||
-rw-r--r-- | tests/console/cron/tasks/simple_ready.php | 13 |
3 files changed, 107 insertions, 0 deletions
diff --git a/tests/console/cron/execute_all_test.php b/tests/console/cron/execute_all_test.php new file mode 100644 index 0000000000..83cffd5be6 --- /dev/null +++ b/tests/console/cron/execute_all_test.php @@ -0,0 +1,85 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2014 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +use Symfony\Component\Console\Application; +use Symfony\Component\Console\Tester\CommandTester; +use phpbb\console\command\cron\execute_all; + +require_once dirname(__FILE__) . '/tasks/simple_ready.php'; + +class phpbb_console_command_cron_execute_all_test extends phpbb_database_test_case +{ + protected $db; + protected $config; + protected $lock; + protected $user; + protected $cron_manager; + protected $command_name; + + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/config.xml'); + } + + public function setUp() + { + global $db, $config, $phpbb_root_path, $pathEx; + + $db = $this->db = $this->new_dbal(); + $config = $this->config = new \phpbb\config\config(array('cron_lock' => '0')); + set_config(null, null, null, $this->config); + $this->lock = new \phpbb\lock\db('cron_lock', $this->config, $this->db); + + $this->user = $this->getMock('\phpbb\user'); + $this->user->method('lang')->will($this->returnArgument(0)); + + $tasks = array( + new phpbb_cron_task_core_simple_ready(), + ); + $this->cron_manager = new \phpbb\cron\manager($tasks, $phpbb_root_path, $pathEx); + + $this->assertEquals('0', $config['cron_lock']); + } + + public function test_normal_use() + { + $command_tester = $this->get_command_tester(); + $command_tester->execute(array('command' => $command_name)); + + $this->assertEquals('', $command_tester->getDisplay()); + } + + public function test_verbose_mode() + { + $command_tester = $this->get_command_tester(); + $command_tester->execute(array('command' => $command_name, '--verbose' => true)); + + $this->assertContains('RUNNING_TASK', $command_tester->getDisplay()); + } + + public function test_error_lock() + { + $this->lock->acquire(); + $command_tester = $this->get_command_tester(); + $command_tester->execute(array('command' => $command_name)); + + $this->assertContains('CRON_LOCK_ERROR', $command_tester->getDisplay()); + } + + public function get_command_tester() + { + $application = new Application(); + $application->add(new execute_all($this->cron_manager, $this->lock, $this->user)); + + $command = $application->find('cron:execute-all'); + $command_name = $command->getName(); + return new CommandTester($command); + } +} + diff --git a/tests/console/cron/fixtures/config.xml b/tests/console/cron/fixtures/config.xml new file mode 100644 index 0000000000..b49be1e05a --- /dev/null +++ b/tests/console/cron/fixtures/config.xml @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> + <table name="phpbb_config"> + <column>config_name</column> + <column>config_value</column> + <column>is_dynamic</column> + </table> +</dataset> + diff --git a/tests/console/cron/tasks/simple_ready.php b/tests/console/cron/tasks/simple_ready.php new file mode 100644 index 0000000000..245d9ba738 --- /dev/null +++ b/tests/console/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() + { + } +} |