From 58d7302b495783edd6e0826c100ffa93acb0693d Mon Sep 17 00:00:00 2001 From: Etienne Baroux Date: Mon, 2 Jun 2014 12:17:37 +0200 Subject: [ticket/12602] Add files to print the cron list and test files. PHPBB3-12602 --- tests/console/cron/cron_list_test.php | 100 +++++++++++++++++++++ tests/console/cron/tasks/simple_not_ready.php | 13 +++ tests/console/cron/tasks/simple_not_runnable.php | 18 ++++ tests/console/cron/tasks/simple_ready.php | 13 +++ tests/console/cron/tasks/simple_should_not_run.php | 18 ++++ 5 files changed, 162 insertions(+) create mode 100644 tests/console/cron/cron_list_test.php create mode 100644 tests/console/cron/tasks/simple_not_ready.php create mode 100644 tests/console/cron/tasks/simple_not_runnable.php create mode 100644 tests/console/cron/tasks/simple_ready.php create mode 100644 tests/console/cron/tasks/simple_should_not_run.php (limited to 'tests') diff --git a/tests/console/cron/cron_list_test.php b/tests/console/cron/cron_list_test.php new file mode 100644 index 0000000000..12fac4a832 --- /dev/null +++ b/tests/console/cron/cron_list_test.php @@ -0,0 +1,100 @@ +user = $this->getMock('\phpbb\user'); + $this->user->method('lang')->will($this->returnArgument(0)); + } + + public function test_no_task() + { + $tasks = array(); + $this->get_cron_manager($tasks); + $command_tester = $this->get_command_tester(); + $command_tester->execute(array('command' => $this->command_name, '--no-ansi' => true)); + $this->assertContains('NO_TASK', $command_tester->getDisplay()); + } + + public function test_only_ready() + { + $tasks = array( + new phpbb_cron_task_simple(), + new phpbb_cron_task_simple() + ); + $this->get_cron_manager($tasks); + $command_tester = $this->get_command_tester(); + $command_tester->execute(array('command' => $this->command_name, '--no-ansi' => true)); + $this->assertContains('TASKS_READYcommand1command2', preg_replace('/\s+/', '', $command_tester->getDisplay())); + } + + public function test_only_not_ready() + { + $tasks = array( + new phpbb_cron_task_simple_not_ready(), + new phpbb_cron_task_simple_not_ready() + ); + $this->get_cron_manager($tasks); + $command_tester = $this->get_command_tester(); + $command_tester->execute(array('command' => $this->command_name, '--no-ansi' => true)); + $this->assertContains('TASKS_NOT_READYcommand1command2', preg_replace('/\s+/', '', $command_tester->getDisplay())); + } + + public function test_both_ready() + { + $tasks = array( + new phpbb_cron_task_simple(), + new phpbb_cron_task_simple(), + new phpbb_cron_task_simple_not_ready(), + new phpbb_cron_task_simple_not_ready() + ); + $this->get_cron_manager($tasks); + $command_tester = $this->get_command_tester(); + $command_tester->execute(array('command' => $this->command_name, '--no-ansi' => true)); + $this->assertSame('TASKS_READYcommand1command2TASKS_NOT_READYcommand3command4', preg_replace('/\s+/', '', $command_tester->getDisplay())); + } + + public function get_cron_manager(array $tasks) + { + global $pathEx, $phpbb_root_path; + $i = 1; + foreach ($tasks as $task) + { + $task->set_name('command' . $i); + $i++; + } + $this->cron_manager = new \phpbb\cron\manager($tasks, $phpbb_root_path, $pathEx); + } + + public function get_command_tester() + { + $application = new Application(); + $application->add(new cron_list($this->cron_manager, $this->user)); + + $command = $application->find('cron:list'); + $this->command_name = $command->getName(); + return new CommandTester($command); + } +} diff --git a/tests/console/cron/tasks/simple_not_ready.php b/tests/console/cron/tasks/simple_not_ready.php new file mode 100644 index 0000000000..887768e5fe --- /dev/null +++ b/tests/console/cron/tasks/simple_not_ready.php @@ -0,0 +1,13 @@ + Date: Mon, 2 Jun 2014 16:21:25 +0200 Subject: [ticket/12602] Cleanup tests PHPBB3-12602 --- tests/console/cron/cron_list_test.php | 16 ++++++++-------- tests/console/cron/tasks/simple_not_runnable.php | 18 ------------------ tests/console/cron/tasks/simple_ready.php | 7 +------ tests/console/cron/tasks/simple_should_not_run.php | 18 ------------------ 4 files changed, 9 insertions(+), 50 deletions(-) delete mode 100644 tests/console/cron/tasks/simple_not_runnable.php delete mode 100644 tests/console/cron/tasks/simple_should_not_run.php (limited to 'tests') diff --git a/tests/console/cron/cron_list_test.php b/tests/console/cron/cron_list_test.php index 12fac4a832..aabd3e388a 100644 --- a/tests/console/cron/cron_list_test.php +++ b/tests/console/cron/cron_list_test.php @@ -7,7 +7,7 @@ * */ -require_once dirname(__FILE__) . '/tasks/simple.php'; +require_once dirname(__FILE__) . '/tasks/simple_ready.php'; require_once dirname(__FILE__) . '/tasks/simple_not_ready.php'; use Symfony\Component\Console\Application; use Symfony\Component\Console\Tester\CommandTester; @@ -41,13 +41,13 @@ class phpbb_console_command_cron_list_test extends phpbb_test_case public function test_only_ready() { $tasks = array( - new phpbb_cron_task_simple(), - new phpbb_cron_task_simple() + new phpbb_cron_task_simple_ready(), + new phpbb_cron_task_simple_ready() ); $this->get_cron_manager($tasks); $command_tester = $this->get_command_tester(); $command_tester->execute(array('command' => $this->command_name, '--no-ansi' => true)); - $this->assertContains('TASKS_READYcommand1command2', preg_replace('/\s+/', '', $command_tester->getDisplay())); + $this->assertContains('TASKS_READY command1 command2', preg_replace('/\s+/', ' ', trim($command_tester->getDisplay()))); } public function test_only_not_ready() @@ -59,21 +59,21 @@ class phpbb_console_command_cron_list_test extends phpbb_test_case $this->get_cron_manager($tasks); $command_tester = $this->get_command_tester(); $command_tester->execute(array('command' => $this->command_name, '--no-ansi' => true)); - $this->assertContains('TASKS_NOT_READYcommand1command2', preg_replace('/\s+/', '', $command_tester->getDisplay())); + $this->assertContains('TASKS_NOT_READY command1 command2', preg_replace('/\s+/', ' ', trim($command_tester->getDisplay()))); } public function test_both_ready() { $tasks = array( - new phpbb_cron_task_simple(), - new phpbb_cron_task_simple(), + new phpbb_cron_task_simple_ready(), + new phpbb_cron_task_simple_ready(), new phpbb_cron_task_simple_not_ready(), new phpbb_cron_task_simple_not_ready() ); $this->get_cron_manager($tasks); $command_tester = $this->get_command_tester(); $command_tester->execute(array('command' => $this->command_name, '--no-ansi' => true)); - $this->assertSame('TASKS_READYcommand1command2TASKS_NOT_READYcommand3command4', preg_replace('/\s+/', '', $command_tester->getDisplay())); + $this->assertSame('TASKS_READY command1 command2 TASKS_NOT_READY command3 command4', preg_replace('/\s+/', ' ', trim($command_tester->getDisplay()))); } public function get_cron_manager(array $tasks) diff --git a/tests/console/cron/tasks/simple_not_runnable.php b/tests/console/cron/tasks/simple_not_runnable.php deleted file mode 100644 index 4951b5b4b9..0000000000 --- a/tests/console/cron/tasks/simple_not_runnable.php +++ /dev/null @@ -1,18 +0,0 @@ - Date: Tue, 3 Jun 2014 10:42:50 +0200 Subject: [ticket/12602] Changes to respect coding style and to factorize code. PHPBB3-12602 --- tests/console/cron/cron_list_test.php | 62 +++++++++++++++++------------------ 1 file changed, 30 insertions(+), 32 deletions(-) (limited to 'tests') diff --git a/tests/console/cron/cron_list_test.php b/tests/console/cron/cron_list_test.php index aabd3e388a..dd4a33ee62 100644 --- a/tests/console/cron/cron_list_test.php +++ b/tests/console/cron/cron_list_test.php @@ -23,6 +23,8 @@ class phpbb_console_command_cron_list_test extends phpbb_test_case protected $command_name; + protected $command_tester; + protected function setUp() { $this->user = $this->getMock('\phpbb\user'); @@ -31,49 +33,26 @@ class phpbb_console_command_cron_list_test extends phpbb_test_case public function test_no_task() { - $tasks = array(); - $this->get_cron_manager($tasks); - $command_tester = $this->get_command_tester(); - $command_tester->execute(array('command' => $this->command_name, '--no-ansi' => true)); - $this->assertContains('NO_TASK', $command_tester->getDisplay()); + $this->initiate_test(0,0); + $this->assertContains('NO_TASK', $this->command_tester->getDisplay()); } public function test_only_ready() { - $tasks = array( - new phpbb_cron_task_simple_ready(), - new phpbb_cron_task_simple_ready() - ); - $this->get_cron_manager($tasks); - $command_tester = $this->get_command_tester(); - $command_tester->execute(array('command' => $this->command_name, '--no-ansi' => true)); - $this->assertContains('TASKS_READY command1 command2', preg_replace('/\s+/', ' ', trim($command_tester->getDisplay()))); + $this->initiate_test(2,0); + $this->assertContains('TASKS_READY command1 command2', preg_replace('/\s+/', ' ', trim($this->command_tester->getDisplay()))); } public function test_only_not_ready() { - $tasks = array( - new phpbb_cron_task_simple_not_ready(), - new phpbb_cron_task_simple_not_ready() - ); - $this->get_cron_manager($tasks); - $command_tester = $this->get_command_tester(); - $command_tester->execute(array('command' => $this->command_name, '--no-ansi' => true)); - $this->assertContains('TASKS_NOT_READY command1 command2', preg_replace('/\s+/', ' ', trim($command_tester->getDisplay()))); + $this->initiate_test(0,2); + $this->assertContains('TASKS_NOT_READY command1 command2', preg_replace('/\s+/', ' ', trim($this->command_tester->getDisplay()))); } public function test_both_ready() { - $tasks = array( - new phpbb_cron_task_simple_ready(), - new phpbb_cron_task_simple_ready(), - new phpbb_cron_task_simple_not_ready(), - new phpbb_cron_task_simple_not_ready() - ); - $this->get_cron_manager($tasks); - $command_tester = $this->get_command_tester(); - $command_tester->execute(array('command' => $this->command_name, '--no-ansi' => true)); - $this->assertSame('TASKS_READY command1 command2 TASKS_NOT_READY command3 command4', preg_replace('/\s+/', ' ', trim($command_tester->getDisplay()))); + $this->initiate_test(2,2); + $this->assertSame('TASKS_READY command1 command2 TASKS_NOT_READY command3 command4', preg_replace('/\s+/', ' ', trim($this->command_tester->getDisplay()))); } public function get_cron_manager(array $tasks) @@ -97,4 +76,23 @@ class phpbb_console_command_cron_list_test extends phpbb_test_case $this->command_name = $command->getName(); return new CommandTester($command); } -} + + public function initiate_test ($number_ready, $number_not_ready) + { + $tasks = array(); + + for ($i = 0; $i < $number_ready; $i++) + { + $tasks[] = new phpbb_cron_task_simple_ready(); + } + + for ($i = 0; $i < $number_not_ready; $i++) + { + $tasks[] = new phpbb_cron_task_simple_not_ready(); + } + + $this->get_cron_manager($tasks); + $this->command_tester = $this->get_command_tester(); + $this->command_tester->execute(array('command' => $this->command_name, '--no-ansi' => true)); + } +} \ No newline at end of file -- cgit v1.2.1 From 721a1d0bc49fce52a8e438946a58ba0ca6db2f28 Mon Sep 17 00:00:00 2001 From: Etienne Baroux Date: Tue, 3 Jun 2014 10:50:00 +0200 Subject: [ticket/12602] Headers updated. PHPBB3-12602 --- tests/console/cron/cron_list_test.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/console/cron/cron_list_test.php b/tests/console/cron/cron_list_test.php index dd4a33ee62..921de31703 100644 --- a/tests/console/cron/cron_list_test.php +++ b/tests/console/cron/cron_list_test.php @@ -1,11 +1,15 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ require_once dirname(__FILE__) . '/tasks/simple_ready.php'; require_once dirname(__FILE__) . '/tasks/simple_not_ready.php'; -- cgit v1.2.1 From 5aca27e8cfc0f9387bc62756c8f296e2cec823a3 Mon Sep 17 00:00:00 2001 From: Etienne Baroux Date: Tue, 3 Jun 2014 10:54:28 +0200 Subject: [ticket/12602] Fix coding style mistakes. PHPBB3-12602 --- tests/console/cron/cron_list_test.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/console/cron/cron_list_test.php b/tests/console/cron/cron_list_test.php index 921de31703..32b7c792e8 100644 --- a/tests/console/cron/cron_list_test.php +++ b/tests/console/cron/cron_list_test.php @@ -13,6 +13,7 @@ require_once dirname(__FILE__) . '/tasks/simple_ready.php'; require_once dirname(__FILE__) . '/tasks/simple_not_ready.php'; + use Symfony\Component\Console\Application; use Symfony\Component\Console\Tester\CommandTester; use phpbb\console\command\cron\cron_list; @@ -99,4 +100,4 @@ class phpbb_console_command_cron_list_test extends phpbb_test_case $this->command_tester = $this->get_command_tester(); $this->command_tester->execute(array('command' => $this->command_name, '--no-ansi' => true)); } -} \ No newline at end of file +} -- cgit v1.2.1 From 442e12828b827239806e84dcd77641cfc5daca57 Mon Sep 17 00:00:00 2001 From: Etienne Baroux Date: Wed, 4 Jun 2014 21:56:55 +0200 Subject: [ticket/12602] Fix spaces issues. PHPBB3-12602 --- tests/console/cron/cron_list_test.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/console/cron/cron_list_test.php b/tests/console/cron/cron_list_test.php index 32b7c792e8..ad74f17875 100644 --- a/tests/console/cron/cron_list_test.php +++ b/tests/console/cron/cron_list_test.php @@ -38,25 +38,25 @@ class phpbb_console_command_cron_list_test extends phpbb_test_case public function test_no_task() { - $this->initiate_test(0,0); + $this->initiate_test(0, 0); $this->assertContains('NO_TASK', $this->command_tester->getDisplay()); } public function test_only_ready() { - $this->initiate_test(2,0); + $this->initiate_test(2, 0); $this->assertContains('TASKS_READY command1 command2', preg_replace('/\s+/', ' ', trim($this->command_tester->getDisplay()))); } public function test_only_not_ready() { - $this->initiate_test(0,2); + $this->initiate_test(0, 2); $this->assertContains('TASKS_NOT_READY command1 command2', preg_replace('/\s+/', ' ', trim($this->command_tester->getDisplay()))); } public function test_both_ready() { - $this->initiate_test(2,2); + $this->initiate_test(2, 2); $this->assertSame('TASKS_READY command1 command2 TASKS_NOT_READY command3 command4', preg_replace('/\s+/', ' ', trim($this->command_tester->getDisplay()))); } @@ -82,7 +82,7 @@ class phpbb_console_command_cron_list_test extends phpbb_test_case return new CommandTester($command); } - public function initiate_test ($number_ready, $number_not_ready) + public function initiate_test($number_ready, $number_not_ready) { $tasks = array(); -- cgit v1.2.1 From 49beb2075b8a6831c6c394fb7b2ba081b860664d Mon Sep 17 00:00:00 2001 From: Etienne Baroux Date: Fri, 6 Jun 2014 10:29:58 +0200 Subject: [ticket/12602] Fix test mistake. PHPBB3-12602 --- tests/console/cron/cron_list_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/console/cron/cron_list_test.php b/tests/console/cron/cron_list_test.php index ad74f17875..ea54c17738 100644 --- a/tests/console/cron/cron_list_test.php +++ b/tests/console/cron/cron_list_test.php @@ -39,7 +39,7 @@ class phpbb_console_command_cron_list_test extends phpbb_test_case public function test_no_task() { $this->initiate_test(0, 0); - $this->assertContains('NO_TASK', $this->command_tester->getDisplay()); + $this->assertContains('CRON_NO_RUNNABLE_TASK', $this->command_tester->getDisplay()); } public function test_only_ready() -- cgit v1.2.1 From 347de7f060095cc43c2a5b5575924997ac8d3dbf Mon Sep 17 00:00:00 2001 From: Etienne Baroux Date: Fri, 6 Jun 2014 14:55:37 +0200 Subject: [ticket/12602] Rectify language keys. PHPBB3-12602 --- tests/console/cron/cron_list_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/console/cron/cron_list_test.php b/tests/console/cron/cron_list_test.php index ea54c17738..46705a585f 100644 --- a/tests/console/cron/cron_list_test.php +++ b/tests/console/cron/cron_list_test.php @@ -39,7 +39,7 @@ class phpbb_console_command_cron_list_test extends phpbb_test_case public function test_no_task() { $this->initiate_test(0, 0); - $this->assertContains('CRON_NO_RUNNABLE_TASK', $this->command_tester->getDisplay()); + $this->assertContains('CRON_NO_TASKS', $this->command_tester->getDisplay()); } public function test_only_ready() -- cgit v1.2.1