2014-05-27 12:36:44 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
*
|
2014-05-28 18:28:46 +02:00
|
|
|
* This file is part of the phpBB Forum Software package.
|
|
|
|
*
|
|
|
|
* @copyright (c) phpBB Limited
|
|
|
|
* @license GNU General Public License, version 2 (GPL-2.0)
|
|
|
|
*
|
|
|
|
* For full copyright and license information, please see
|
|
|
|
* the docs/CREDITS.txt file.
|
2014-05-27 12:36:44 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
use Symfony\Component\Console\Application;
|
|
|
|
use Symfony\Component\Console\Tester\CommandTester;
|
2014-05-28 14:39:02 +02:00
|
|
|
use phpbb\console\command\cron\run_all;
|
2014-05-27 12:36:44 +02:00
|
|
|
|
2014-05-28 10:13:37 +02:00
|
|
|
require_once dirname(__FILE__) . '/tasks/simple.php';
|
2014-05-27 12:36:44 +02:00
|
|
|
|
2014-05-28 14:39:02 +02:00
|
|
|
class phpbb_console_command_cron_run_all_test extends phpbb_database_test_case
|
2014-05-27 12:36:44 +02:00
|
|
|
{
|
|
|
|
protected $db;
|
|
|
|
protected $config;
|
|
|
|
protected $lock;
|
|
|
|
protected $user;
|
|
|
|
protected $cron_manager;
|
|
|
|
protected $command_name;
|
2014-05-28 18:02:30 +02:00
|
|
|
protected $task;
|
2014-05-27 12:36:44 +02:00
|
|
|
|
|
|
|
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));
|
|
|
|
|
2014-05-28 18:02:30 +02:00
|
|
|
$this->task = new phpbb_cron_task_simple();
|
2014-05-27 12:36:44 +02:00
|
|
|
$tasks = array(
|
2014-05-28 18:02:30 +02:00
|
|
|
$this->task,
|
2014-05-27 12:36:44 +02:00
|
|
|
);
|
|
|
|
$this->cron_manager = new \phpbb\cron\manager($tasks, $phpbb_root_path, $pathEx);
|
|
|
|
|
2014-05-28 14:39:02 +02:00
|
|
|
$this->assertSame('0', $config['cron_lock']);
|
2014-05-27 12:36:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function test_normal_use()
|
|
|
|
{
|
|
|
|
$command_tester = $this->get_command_tester();
|
2014-05-28 10:13:37 +02:00
|
|
|
$command_tester->execute(array('command' => $this->command_name));
|
2014-05-27 12:36:44 +02:00
|
|
|
|
2014-05-28 14:39:02 +02:00
|
|
|
$this->assertSame('', $command_tester->getDisplay());
|
2014-05-28 18:02:30 +02:00
|
|
|
$this->assertSame(true, $this->task->executed);
|
2014-05-27 12:36:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function test_verbose_mode()
|
|
|
|
{
|
|
|
|
$command_tester = $this->get_command_tester();
|
2014-05-28 10:13:37 +02:00
|
|
|
$command_tester->execute(array('command' => $this->command_name, '--verbose' => true));
|
2014-05-27 12:36:44 +02:00
|
|
|
|
|
|
|
$this->assertContains('RUNNING_TASK', $command_tester->getDisplay());
|
2014-05-28 18:02:30 +02:00
|
|
|
$this->assertSame(true, $this->task->executed);
|
2014-05-27 12:36:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function test_error_lock()
|
|
|
|
{
|
|
|
|
$this->lock->acquire();
|
|
|
|
$command_tester = $this->get_command_tester();
|
2014-05-28 10:13:37 +02:00
|
|
|
$command_tester->execute(array('command' => $this->command_name));
|
2014-05-27 12:36:44 +02:00
|
|
|
|
|
|
|
$this->assertContains('CRON_LOCK_ERROR', $command_tester->getDisplay());
|
2014-05-28 18:02:30 +02:00
|
|
|
$this->assertSame(false, $this->task->executed);
|
2014-05-27 12:36:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function get_command_tester()
|
|
|
|
{
|
|
|
|
$application = new Application();
|
2014-05-28 14:39:02 +02:00
|
|
|
$application->add(new run_all($this->cron_manager, $this->lock, $this->user));
|
2014-05-27 12:36:44 +02:00
|
|
|
|
2014-05-28 14:39:02 +02:00
|
|
|
$command = $application->find('cron:run-all');
|
2014-05-28 10:13:37 +02:00
|
|
|
$this->command_name = $command->getName();
|
2014-05-27 12:36:44 +02:00
|
|
|
return new CommandTester($command);
|
|
|
|
}
|
|
|
|
}
|