aboutsummaryrefslogtreecommitdiffstats
path: root/tests/console/cron/run_all_test.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/console/cron/run_all_test.php')
-rw-r--r--tests/console/cron/run_all_test.php96
1 files changed, 96 insertions, 0 deletions
diff --git a/tests/console/cron/run_all_test.php b/tests/console/cron/run_all_test.php
new file mode 100644
index 0000000000..b718d1c117
--- /dev/null
+++ b/tests/console/cron/run_all_test.php
@@ -0,0 +1,96 @@
+<?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\run_all;
+
+require_once dirname(__FILE__) . '/tasks/simple.php';
+
+class phpbb_console_command_cron_run_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;
+ global $cron_num_exec;
+
+ $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_simple(),
+ );
+ $this->cron_manager = new \phpbb\cron\manager($tasks, $phpbb_root_path, $pathEx);
+
+ $cron_num_exec = 0;
+
+ $this->assertSame('0', $config['cron_lock']);
+ }
+
+ public function test_normal_use()
+ {
+ global $cron_num_exec;
+
+ $command_tester = $this->get_command_tester();
+ $command_tester->execute(array('command' => $this->command_name));
+
+ $this->assertSame('', $command_tester->getDisplay());
+ $this->assertSame(1, $cron_num_exec);
+ }
+
+ public function test_verbose_mode()
+ {
+ global $cron_num_exec;
+
+ $command_tester = $this->get_command_tester();
+ $command_tester->execute(array('command' => $this->command_name, '--verbose' => true));
+
+ $this->assertContains('RUNNING_TASK', $command_tester->getDisplay());
+ $this->assertSame(1, $cron_num_exec);
+ }
+
+ public function test_error_lock()
+ {
+ global $cron_num_exec;
+
+ $this->lock->acquire();
+ $command_tester = $this->get_command_tester();
+ $command_tester->execute(array('command' => $this->command_name));
+
+ $this->assertContains('CRON_LOCK_ERROR', $command_tester->getDisplay());
+ $this->assertSame(0, $cron_num_exec);
+ }
+
+ public function get_command_tester()
+ {
+ $application = new Application();
+ $application->add(new run_all($this->cron_manager, $this->lock, $this->user));
+
+ $command = $application->find('cron:run-all');
+ $this->command_name = $command->getName();
+ return new CommandTester($command);
+ }
+}