From 346f31a03156839d1b1931d2fc69cd2ab5656bc0 Mon Sep 17 00:00:00 2001 From: Etienne Baroux Date: Mon, 2 Jun 2014 10:12:18 +0200 Subject: [ticket/12610] Add command to check if the board is up to date. PHPBB3-12610 --- tests/console/update/check_test.php | 99 +++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 tests/console/update/check_test.php (limited to 'tests/console/update/check_test.php') diff --git a/tests/console/update/check_test.php b/tests/console/update/check_test.php new file mode 100644 index 0000000000..d257ef6c0a --- /dev/null +++ b/tests/console/update/check_test.php @@ -0,0 +1,99 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +use Symfony\Component\Console\Application; +use Symfony\Component\Console\Tester\CommandTester; +use phpbb\console\command\update\check; + +require_once dirname(__FILE__) . '/../../../phpBB/includes/functions_admin.php'; +require_once dirname(__FILE__) . '/../../../phpBB/includes/functions.php'; +require_once dirname(__FILE__) . '/../../../phpBB/includes/utf/utf_tools.php'; + +/** +* @slow +*/ +class phpbb_console_command_check_test extends phpbb_test_case +{ + protected $command_name; + + protected $version_helper; + + public function test_up_to_date() + { + $command_tester = $this->get_command_tester('100000'); + $status = $command_tester->execute(array('command' => $this->command_name, '--no-ansi' => true)); + $this->assertSame('', $command_tester->getDisplay()); + $this->assertSame($status, 0); + } + + public function test_up_to_date_verbose() + { + $command_tester = $this->get_command_tester('100000'); + $status = $command_tester->execute(array('command' => $this->command_name, '--no-ansi' => true, '--verbose' => true)); + $this->assertContains('UPDATE_NOT_NEEDED', $command_tester->getDisplay()); + $this->assertSame($status, 0); + } + + + public function test_not_up_to_date() + { + $command_tester = $this->get_command_tester('0'); + $status = $command_tester->execute(array('command' => $this->command_name, '--no-ansi' => true)); + $this->assertContains('UPDATE_NEEDED', $command_tester->getDisplay()); + $this->assertSame($status, 1); + } + + public function test_not_up_to_date_verbose() + { + $command_tester = $this->get_command_tester('0'); + $status = $command_tester->execute(array('command' => $this->command_name, '--no-ansi' => true, '--verbose' => true)); + $this->assertContains('UPDATE_NEEDED', $command_tester->getDisplay()); + $this->assertContains('UPDATES_AVAILABLE', $command_tester->getDisplay()); + $this->assertSame($status, 1); + } + + public function test_error() + { + $command_tester = $this->get_command_tester('1'); + $this->version_helper->set_file_location('acme.corp','foo', 'bar.json'); + + $status = $command_tester->execute(array('command' => $this->command_name, '--no-ansi' => true)); + $this->assertContains('VERSIONCHECK_FAIL', $command_tester->getDisplay()); + $this->assertSame($status, 2); + } + + public function get_command_tester($current_version) + { + global $user; + + $user = $this->getMock('\phpbb\user'); + $user->method('lang')->will($this->returnArgument(0)); + + $cache = $this->getMockBuilder('\phpbb\cache\service') + ->disableOriginalConstructor() + ->getMock(); + + $config = new \phpbb\config\config(array('version' => $current_version)); + $this->version_helper = new \phpbb\version_helper($cache, $config, $user); + + $container = new phpbb_mock_container_builder; + $container->set('version_helper', $this->version_helper); + + $application = new Application(); + $application->add(new check($user, $config, $container)); + + $command = $application->find('update:check'); + $this->command_name = $command->getName(); + return new CommandTester($command); + } +} -- cgit v1.2.1 From 376042d845a18058d93d289a1227096794da06d2 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Mon, 24 Aug 2015 10:26:05 +0200 Subject: [ticket/12610] Fix tests PHPBB3-12610 --- tests/console/update/check_test.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'tests/console/update/check_test.php') diff --git a/tests/console/update/check_test.php b/tests/console/update/check_test.php index d257ef6c0a..2101a3f33a 100644 --- a/tests/console/update/check_test.php +++ b/tests/console/update/check_test.php @@ -76,7 +76,10 @@ class phpbb_console_command_check_test extends phpbb_test_case { global $user; - $user = $this->getMock('\phpbb\user'); + $user = $this->getMock('\phpbb\user', array(), array( + new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)), + '\phpbb\datetime' + )); $user->method('lang')->will($this->returnArgument(0)); $cache = $this->getMockBuilder('\phpbb\cache\service') @@ -84,7 +87,7 @@ class phpbb_console_command_check_test extends phpbb_test_case ->getMock(); $config = new \phpbb\config\config(array('version' => $current_version)); - $this->version_helper = new \phpbb\version_helper($cache, $config, $user); + $this->version_helper = new \phpbb\version_helper($cache, $config, new \phpbb\file_downloader(), $user); $container = new phpbb_mock_container_builder; $container->set('version_helper', $this->version_helper); -- cgit v1.2.1 From 8481bd4e1831e3f9911263957637f4095fb088b0 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Mon, 24 Aug 2015 12:33:32 +0200 Subject: [ticket/12610] Use exception_interface PHPBB3-12610 --- tests/console/update/check_test.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'tests/console/update/check_test.php') diff --git a/tests/console/update/check_test.php b/tests/console/update/check_test.php index 2101a3f33a..de57e4df08 100644 --- a/tests/console/update/check_test.php +++ b/tests/console/update/check_test.php @@ -62,6 +62,9 @@ class phpbb_console_command_check_test extends phpbb_test_case $this->assertSame($status, 1); } + /** + * @expectedException phpbb\exception\runtime_exception + */ public function test_error() { $command_tester = $this->get_command_tester('1'); @@ -87,7 +90,7 @@ class phpbb_console_command_check_test extends phpbb_test_case ->getMock(); $config = new \phpbb\config\config(array('version' => $current_version)); - $this->version_helper = new \phpbb\version_helper($cache, $config, new \phpbb\file_downloader(), $user); + $this->version_helper = new \phpbb\version_helper($cache, $config, new \phpbb\file_downloader()); $container = new phpbb_mock_container_builder; $container->set('version_helper', $this->version_helper); -- cgit v1.2.1 From 103d344cd4476b452e42cd7ba0007b5a85caeaaf Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 5 Dec 2016 15:46:05 +0100 Subject: [ticket/12610] Fix tests and use getOption() for console PHPBB3-12610 --- tests/console/update/check_test.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'tests/console/update/check_test.php') diff --git a/tests/console/update/check_test.php b/tests/console/update/check_test.php index de57e4df08..5cadc5cc97 100644 --- a/tests/console/update/check_test.php +++ b/tests/console/update/check_test.php @@ -28,6 +28,9 @@ class phpbb_console_command_check_test extends phpbb_test_case protected $version_helper; + /** @var \phpbb\language\language */ + protected $language; + public function test_up_to_date() { $command_tester = $this->get_command_tester('100000'); @@ -40,7 +43,7 @@ class phpbb_console_command_check_test extends phpbb_test_case { $command_tester = $this->get_command_tester('100000'); $status = $command_tester->execute(array('command' => $this->command_name, '--no-ansi' => true, '--verbose' => true)); - $this->assertContains('UPDATE_NOT_NEEDED', $command_tester->getDisplay()); + $this->assertContains($this->language->lang('UPDATE_NOT_NEEDED'), $command_tester->getDisplay()); $this->assertSame($status, 0); } @@ -49,7 +52,7 @@ class phpbb_console_command_check_test extends phpbb_test_case { $command_tester = $this->get_command_tester('0'); $status = $command_tester->execute(array('command' => $this->command_name, '--no-ansi' => true)); - $this->assertContains('UPDATE_NEEDED', $command_tester->getDisplay()); + $this->assertContains($this->language->lang('UPDATE_NEEDED'), $command_tester->getDisplay()); $this->assertSame($status, 1); } @@ -57,8 +60,8 @@ class phpbb_console_command_check_test extends phpbb_test_case { $command_tester = $this->get_command_tester('0'); $status = $command_tester->execute(array('command' => $this->command_name, '--no-ansi' => true, '--verbose' => true)); - $this->assertContains('UPDATE_NEEDED', $command_tester->getDisplay()); - $this->assertContains('UPDATES_AVAILABLE', $command_tester->getDisplay()); + $this->assertContains($this->language->lang('UPDATE_NEEDED'), $command_tester->getDisplay()); + $this->assertContains($this->language->lang('UPDATES_AVAILABLE'), $command_tester->getDisplay()); $this->assertSame($status, 1); } @@ -77,10 +80,12 @@ class phpbb_console_command_check_test extends phpbb_test_case public function get_command_tester($current_version) { - global $user; + global $user, $phpbb_root_path, $phpEx; + + $this->language = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)); $user = $this->getMock('\phpbb\user', array(), array( - new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)), + $this->language, '\phpbb\datetime' )); $user->method('lang')->will($this->returnArgument(0)); @@ -96,7 +101,7 @@ class phpbb_console_command_check_test extends phpbb_test_case $container->set('version_helper', $this->version_helper); $application = new Application(); - $application->add(new check($user, $config, $container)); + $application->add(new check($user, $config, $container, $this->language)); $command = $application->find('update:check'); $this->command_name = $command->getName(); -- cgit v1.2.1