From 9f942776ad5a3b396045e6f97db6ef655c5d9fcc Mon Sep 17 00:00:00 2001 From: LEZY Thomas Date: Wed, 28 May 2014 19:51:59 +0200 Subject: [ticket/12597] Changes name of command cron:run-all to cron:run. Also adds an optional argument to specify one precise cron task to lauch, and modifies test file accordingly. PHPBB3-12597 --- tests/console/cron/run_test.php | 120 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 tests/console/cron/run_test.php (limited to 'tests/console/cron/run_test.php') diff --git a/tests/console/cron/run_test.php b/tests/console/cron/run_test.php new file mode 100644 index 0000000000..c7c514c084 --- /dev/null +++ b/tests/console/cron/run_test.php @@ -0,0 +1,120 @@ +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)); + + $this->task = new phpbb_cron_task_simple(); + $tasks = array( + $this->task, + ); + $this->cron_manager = new \phpbb\cron\manager($tasks, $phpbb_root_path, $pathEx); + + $this->assertSame('0', $config['cron_lock']); + } + + public function test_normal_use() + { + $command_tester = $this->get_command_tester(); + $command_tester->execute(array('command' => $this->command_name)); + + $this->assertSame('', $command_tester->getDisplay()); + $this->assertSame(true, $this->task->executed); + } + + public function test_verbose_mode() + { + $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(true, $this->task->executed); + } + + public function test_error_lock() + { + $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(false, $this->task->executed); + } + + public function test_arg_valid() + { + $command_tester = $this->get_command_tester(); + $command_tester->execute(array('command' => $this->command_name, 'name' => 'phpbb_cron_task_simple')); + + $this->assertSame('', $command_tester->getDisplay()); + $this->assertSame(true, $this->task->executed); + } + + public function test_arg_invalid() + { + $command_tester = $this->get_command_tester(); + $command_tester->execute(array('command' => $this->command_name, 'name' => 'foo')); + + $this->assertContains('CRON_NO_TASK', $command_tester->getDisplay()); + $this->assertSame(false, $this->task->executed); + } + + public function test_arg_valid_verbose() + { + $command_tester = $this->get_command_tester(); + $command_tester->execute(array('command' => $this->command_name, 'name' => 'phpbb_cron_task_simple', '--verbose' => true)); + + $this->assertSame('', $command_tester->getDisplay()); + $this->assertSame(true, $this->task->executed); + } + + public function get_command_tester() + { + $application = new Application(); + $application->add(new run($this->cron_manager, $this->lock, $this->user)); + + $command = $application->find('cron:run'); + $this->command_name = $command->getName(); + return new CommandTester($command); + } +} -- cgit v1.2.1 From e7fd259766ff78edf98ee08fff83cb70ac46b6f7 Mon Sep 17 00:00:00 2001 From: LEZY Thomas Date: Thu, 29 May 2014 16:37:45 +0200 Subject: [ticket/12597] Refactoring and test improving Adding tests of return status Refactoring code Adding consistency in verbose mode PHPBB3-12597 --- tests/console/cron/run_test.php | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) (limited to 'tests/console/cron/run_test.php') diff --git a/tests/console/cron/run_test.php b/tests/console/cron/run_test.php index c7c514c084..e5cd170492 100644 --- a/tests/console/cron/run_test.php +++ b/tests/console/cron/run_test.php @@ -56,56 +56,74 @@ class phpbb_console_command_cron_run_test extends phpbb_database_test_case public function test_normal_use() { $command_tester = $this->get_command_tester(); - $command_tester->execute(array('command' => $this->command_name)); + $exit_status = $command_tester->execute(array('command' => $this->command_name)); $this->assertSame('', $command_tester->getDisplay()); $this->assertSame(true, $this->task->executed); + $this->assertSame(0, $exit_status); } public function test_verbose_mode() { $command_tester = $this->get_command_tester(); - $command_tester->execute(array('command' => $this->command_name, '--verbose' => true)); + $exit_status = $command_tester->execute(array('command' => $this->command_name, '--verbose' => true)); $this->assertContains('RUNNING_TASK', $command_tester->getDisplay()); $this->assertSame(true, $this->task->executed); + $this->assertSame(0, $exit_status); } public function test_error_lock() { $this->lock->acquire(); $command_tester = $this->get_command_tester(); - $command_tester->execute(array('command' => $this->command_name)); + $exit_status = $command_tester->execute(array('command' => $this->command_name)); $this->assertContains('CRON_LOCK_ERROR', $command_tester->getDisplay()); $this->assertSame(false, $this->task->executed); + $this->assertSame(1, $exit_status); + } + + public function test_no_task() + { + $tasks = array( + ); + $this->cron_manager = new \phpbb\cron\manager($tasks, $phpbb_root_path, $pathEx); + $command_tester = $this->get_command_tester(); + $exit_status = $command_tester->execute(array('command' => $this->command_name)); + + $this->assertContains('CRON_NO_TASK', $command_tester->getDisplay()); + $this->assertSame(0, $exit_status); } public function test_arg_valid() { $command_tester = $this->get_command_tester(); - $command_tester->execute(array('command' => $this->command_name, 'name' => 'phpbb_cron_task_simple')); + $exit_status = $command_tester->execute(array('command' => $this->command_name, 'name' => 'phpbb_cron_task_simple')); $this->assertSame('', $command_tester->getDisplay()); $this->assertSame(true, $this->task->executed); + $this->assertSame(0, $exit_status); } public function test_arg_invalid() { $command_tester = $this->get_command_tester(); - $command_tester->execute(array('command' => $this->command_name, 'name' => 'foo')); + $exit_status = $command_tester->execute(array('command' => $this->command_name, 'name' => 'foo')); - $this->assertContains('CRON_NO_TASK', $command_tester->getDisplay()); + $this->assertContains('CRON_NO_SUCH_TASK', $command_tester->getDisplay()); $this->assertSame(false, $this->task->executed); + $this->assertSame(2, $exit_status); } public function test_arg_valid_verbose() { $command_tester = $this->get_command_tester(); - $command_tester->execute(array('command' => $this->command_name, 'name' => 'phpbb_cron_task_simple', '--verbose' => true)); + $exit_status = $command_tester->execute(array('command' => $this->command_name, 'name' => 'phpbb_cron_task_simple', '--verbose' => true)); - $this->assertSame('', $command_tester->getDisplay()); + $this->assertContains('RUNNING_TASK', $command_tester->getDisplay()); $this->assertSame(true, $this->task->executed); + $this->assertSame(0, $exit_status); } public function get_command_tester() -- cgit v1.2.1 From 2f2e404639bd0164387615a1f5c338cdbf9e2dfe Mon Sep 17 00:00:00 2001 From: LEZY Thomas Date: Thu, 29 May 2014 17:40:57 +0200 Subject: [ticket/12597] Fix test file Fix bug of test_no_task that expected a message where none was supposed to exist. PHPBB3-12597 --- tests/console/cron/run_test.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'tests/console/cron/run_test.php') diff --git a/tests/console/cron/run_test.php b/tests/console/cron/run_test.php index e5cd170492..599d089a1f 100644 --- a/tests/console/cron/run_test.php +++ b/tests/console/cron/run_test.php @@ -61,6 +61,7 @@ class phpbb_console_command_cron_run_test extends phpbb_database_test_case $this->assertSame('', $command_tester->getDisplay()); $this->assertSame(true, $this->task->executed); $this->assertSame(0, $exit_status); + $this->assertSame(false, $this->lock->owns_lock()); } public function test_verbose_mode() @@ -71,6 +72,7 @@ class phpbb_console_command_cron_run_test extends phpbb_database_test_case $this->assertContains('RUNNING_TASK', $command_tester->getDisplay()); $this->assertSame(true, $this->task->executed); $this->assertSame(0, $exit_status); + $this->assertSame(false, $this->lock->owns_lock()); } public function test_error_lock() @@ -92,8 +94,22 @@ class phpbb_console_command_cron_run_test extends phpbb_database_test_case $command_tester = $this->get_command_tester(); $exit_status = $command_tester->execute(array('command' => $this->command_name)); + $this->assertSame('', $command_tester->getDisplay()); + $this->assertSame(0, $exit_status); + $this->assertSame(false, $this->lock->owns_lock()); + } + + public function test_no_task_verbose() + { + $tasks = array( + ); + $this->cron_manager = new \phpbb\cron\manager($tasks, $phpbb_root_path, $pathEx); + $command_tester = $this->get_command_tester(); + $exit_status = $command_tester->execute(array('command' => $this->command_name, '--verbose' => true)); + $this->assertContains('CRON_NO_TASK', $command_tester->getDisplay()); $this->assertSame(0, $exit_status); + $this->assertSame(false, $this->lock->owns_lock()); } public function test_arg_valid() @@ -104,6 +120,7 @@ class phpbb_console_command_cron_run_test extends phpbb_database_test_case $this->assertSame('', $command_tester->getDisplay()); $this->assertSame(true, $this->task->executed); $this->assertSame(0, $exit_status); + $this->assertSame(false, $this->lock->owns_lock()); } public function test_arg_invalid() @@ -114,6 +131,7 @@ class phpbb_console_command_cron_run_test extends phpbb_database_test_case $this->assertContains('CRON_NO_SUCH_TASK', $command_tester->getDisplay()); $this->assertSame(false, $this->task->executed); $this->assertSame(2, $exit_status); + $this->assertSame(false, $this->lock->owns_lock()); } public function test_arg_valid_verbose() @@ -124,6 +142,7 @@ class phpbb_console_command_cron_run_test extends phpbb_database_test_case $this->assertContains('RUNNING_TASK', $command_tester->getDisplay()); $this->assertSame(true, $this->task->executed); $this->assertSame(0, $exit_status); + $this->assertSame(false, $this->lock->owns_lock()); } public function get_command_tester() -- cgit v1.2.1 From 01dba249d789dd1548c4c1cdfb97630121ece69a Mon Sep 17 00:00:00 2001 From: LEZY Thomas Date: Thu, 29 May 2014 18:25:27 +0200 Subject: [ticket/12597] Fix wrong global variable name $pathEx changed to $phpEx PHPBB3-12597 --- tests/console/cron/run_test.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests/console/cron/run_test.php') diff --git a/tests/console/cron/run_test.php b/tests/console/cron/run_test.php index 599d089a1f..8908c536c0 100644 --- a/tests/console/cron/run_test.php +++ b/tests/console/cron/run_test.php @@ -34,7 +34,7 @@ class phpbb_console_command_cron_run_test extends phpbb_database_test_case public function setUp() { - global $db, $config, $phpbb_root_path, $pathEx; + global $db, $config, $phpbb_root_path, $phpEx; $db = $this->db = $this->new_dbal(); $config = $this->config = new \phpbb\config\config(array('cron_lock' => '0')); @@ -48,7 +48,7 @@ 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, $pathEx); + $this->cron_manager = new \phpbb\cron\manager($tasks, $phpbb_root_path, $phbEx); $this->assertSame('0', $config['cron_lock']); } @@ -90,7 +90,7 @@ 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, $pathEx); + $this->cron_manager = new \phpbb\cron\manager($tasks, $phpbb_root_path, $phpEx); $command_tester = $this->get_command_tester(); $exit_status = $command_tester->execute(array('command' => $this->command_name)); @@ -103,7 +103,7 @@ 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, $pathEx); + $this->cron_manager = new \phpbb\cron\manager($tasks, $phpbb_root_path, $phpEx); $command_tester = $this->get_command_tester(); $exit_status = $command_tester->execute(array('command' => $this->command_name, '--verbose' => true)); -- cgit v1.2.1 From 21c6102d55ab26e9038467ab901246494dd94832 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Fri, 30 May 2014 22:34:26 +0200 Subject: [ticket/12637] Fixup all incorrect uses of file header. PHPBB3-12637 --- tests/console/cron/run_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/console/cron/run_test.php') diff --git a/tests/console/cron/run_test.php b/tests/console/cron/run_test.php index 8908c536c0..ff251cff3c 100644 --- a/tests/console/cron/run_test.php +++ b/tests/console/cron/run_test.php @@ -3,7 +3,7 @@ * * This file is part of the phpBB Forum Software package. * -* @copyright (c) phpBB Limited +* @copyright (c) phpBB Limited * @license GNU General Public License, version 2 (GPL-2.0) * * For full copyright and license information, please see -- cgit v1.2.1 From 07ce29c081c8bbd24a5094d89346be33dda583c5 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Thu, 17 Jul 2014 17:19:36 +0200 Subject: [ticket/12656] Pass user object into all console commands. PHPBB3-12656 --- tests/console/cron/run_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/console/cron/run_test.php') diff --git a/tests/console/cron/run_test.php b/tests/console/cron/run_test.php index ff251cff3c..60bd74e1f0 100644 --- a/tests/console/cron/run_test.php +++ b/tests/console/cron/run_test.php @@ -148,7 +148,7 @@ class phpbb_console_command_cron_run_test extends phpbb_database_test_case public function get_command_tester() { $application = new Application(); - $application->add(new run($this->cron_manager, $this->lock, $this->user)); + $application->add(new run($this->user, $this->cron_manager, $this->lock)); $command = $application->find('cron:run'); $this->command_name = $command->getName(); -- cgit v1.2.1 From 8d99b4afe1557a6ec0e760c4876bb06a3b9991d3 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 10 Aug 2014 13:40:27 +0200 Subject: [ticket/12932] Fix tests and calls to create_datetime PHPBB3-12932 --- tests/console/cron/run_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/console/cron/run_test.php') diff --git a/tests/console/cron/run_test.php b/tests/console/cron/run_test.php index 60bd74e1f0..029dc5249b 100644 --- a/tests/console/cron/run_test.php +++ b/tests/console/cron/run_test.php @@ -41,7 +41,7 @@ class phpbb_console_command_cron_run_test extends phpbb_database_test_case 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 = $this->getMock('\phpbb\user', array(), array('\phpbb\datetime')); $this->user->method('lang')->will($this->returnArgument(0)); $this->task = new phpbb_cron_task_simple(); -- cgit v1.2.1 From 21c8985fe85d54facc9dce59f6b7cbd293b21ade Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Fri, 14 Nov 2014 01:35:13 +0100 Subject: [ticket/13338] Add include statements for dependencies. PHPBB3-13338 --- tests/console/cron/run_test.php | 1 + 1 file changed, 1 insertion(+) (limited to 'tests/console/cron/run_test.php') diff --git a/tests/console/cron/run_test.php b/tests/console/cron/run_test.php index 029dc5249b..f76e967484 100644 --- a/tests/console/cron/run_test.php +++ b/tests/console/cron/run_test.php @@ -16,6 +16,7 @@ use Symfony\Component\Console\Tester\CommandTester; use phpbb\console\command\cron\run; require_once dirname(__FILE__) . '/tasks/simple.php'; +require_once dirname(__FILE__) . '/../../../phpBB/includes/functions.php'; class phpbb_console_command_cron_run_test extends phpbb_database_test_case { -- cgit v1.2.1