diff options
Diffstat (limited to 'tests')
17 files changed, 539 insertions, 4 deletions
diff --git a/tests/console/config/config_test.php b/tests/console/config/config_test.php new file mode 100644 index 0000000000..7c098af004 --- /dev/null +++ b/tests/console/config/config_test.php @@ -0,0 +1,251 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @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; + +class phpbb_console_command_config_test extends phpbb_test_case +{ + protected $config; + protected $command_name; + protected $user; + + public function setUp() + { + $this->config = new \phpbb\config\config(array()); + + $this->user = $this->getMock('\phpbb\user', array(), array('\phpbb\datetime')); + $this->user->method('lang')->will($this->returnArgument(0)); + } + + public function test_set_dynamic() + { + $this->assertEmpty($this->config); + + $command_tester = $this->get_command_tester('set'); + $command_tester->execute(array( + 'command' => $this->command_name, + 'key' => 'test_key', + 'value' => 'test_value', + '--dynamic' => true, + )); + + $this->assertSame($this->config['test_key'], 'test_value'); + } + + public function test_set_no_dynamic() + { + $this->assertEmpty($this->config); + + $command_tester = $this->get_command_tester('set'); + $command_tester->execute(array( + 'command' => $this->command_name, + 'key' => 'test_key', + 'value' => 'test_value', + '--dynamic' => false, + )); + + $this->assertSame($this->config['test_key'], 'test_value'); + } + + public function test_set_atomic_dynamic() + { + $this->assertEmpty($this->config); + + $this->config->set('test_key', 'old_value', true); + $this->assertSame($this->config['test_key'], 'old_value'); + + $command_tester = $this->get_command_tester('set_atomic'); + $command_tester->execute(array( + 'command' => $this->command_name, + 'key' => 'test_key', + 'old' => 'old_value', + 'new' => 'new_value', + '--dynamic' => true, + )); + + $this->assertSame($this->config['test_key'], 'new_value'); + } + + public function test_set_atomic_no_dynamic() + { + $this->assertEmpty($this->config); + + $this->config->set('test_key', 'old_value', false); + $this->assertSame($this->config['test_key'], 'old_value'); + + $command_tester = $this->get_command_tester('set_atomic'); + $command_tester->execute(array( + 'command' => $this->command_name, + 'key' => 'test_key', + 'old' => 'old_value', + 'new' => 'new_value', + '--dynamic' => false, + )); + + $this->assertSame($this->config['test_key'], 'new_value'); + } + + public function test_set_atomic_error_dynamic() + { + $this->assertEmpty($this->config); + + $this->config->set('test_key', 'wrong_value', true); + $this->assertSame($this->config['test_key'], 'wrong_value'); + + $command_tester = $this->get_command_tester('set_atomic'); + $command_tester->execute(array( + 'command' => $this->command_name, + 'key' => 'test_key', + 'old' => 'old_value', + 'new' => 'new_value', + '--dynamic' => true, + )); + + $this->assertSame($this->config['test_key'], 'wrong_value'); + } + + public function test_get_no_new_line() + { + $this->config->set('test_key', 'test_value', false); + $this->assertSame($this->config['test_key'], 'test_value'); + + $command_tester = $this->get_command_tester('get'); + $command_tester->execute(array( + 'command' => $this->command_name, + 'key' => 'test_key', + '--no-newline' => true, + )); + + $this->assertSame($this->config['test_key'], $command_tester->getDisplay()); + } + + public function test_get_new_line() + { + $this->config->set('test_key', 'test_value', false); + $this->assertSame($this->config['test_key'], 'test_value'); + + $command_tester = $this->get_command_tester('get'); + $command_tester->execute(array( + 'command' => $this->command_name, + 'key' => 'test_key', + '--no-newline' => false, + )); + + $this->assertSame($this->config['test_key'] . PHP_EOL, $command_tester->getDisplay()); + } + + public function test_get_error() + { + $this->config->set('test_key', 'test_value', false); + $this->assertSame($this->config['test_key'], 'test_value'); + + $command_tester = $this->get_command_tester('get'); + $command_tester->execute(array( + 'command' => $this->command_name, + 'key' => 'wrong_key', + '--no-newline' => false, + )); + + $this->assertContains('CLI_CONFIG_NOT_EXISTS', $command_tester->getDisplay()); + } + + public function test_increment_dynamic() + { + $this->config->set('test_key', 0, false); + $this->assertSame($this->config['test_key'], 0); + + $command_tester = $this->get_command_tester('increment'); + $command_tester->execute(array( + 'command' => $this->command_name, + 'key' => 'test_key', + 'increment' => 2, + '--dynamic' => true, + )); + + $this->assertContains('CLI_CONFIG_INCREMENT_SUCCESS', $command_tester->getDisplay()); + $this->assertSame(2, $this->config['test_key']); + } + + public function test_increment_no_dynamic() + { + $this->config->set('test_key', 0, false); + $this->assertSame($this->config['test_key'], 0); + + $command_tester = $this->get_command_tester('increment'); + $command_tester->execute(array( + 'command' => $this->command_name, + 'key' => 'test_key', + 'increment' => 2, + '--dynamic' => false, + )); + + $this->assertContains('CLI_CONFIG_INCREMENT_SUCCESS', $command_tester->getDisplay()); + $this->assertSame(2, $this->config['test_key']); + } + + public function test_increment_no_set() + { + $this->assertEmpty($this->config); + + $command_tester = $this->get_command_tester('increment'); + $command_tester->execute(array( + 'command' => $this->command_name, + 'key' => 'test_key', + 'increment' => 2, + '--dynamic' => true, + )); + + $this->assertContains('CLI_CONFIG_INCREMENT_SUCCESS', $command_tester->getDisplay()); + $this->assertSame(2, $this->config['test_key']); + } + + public function test_delete_ok() + { + $this->config->set('test_key', 'test_value', false); + $this->assertSame($this->config['test_key'], 'test_value'); + + $command_tester = $this->get_command_tester('delete'); + $command_tester->execute(array( + 'command' => $this->command_name, + 'key' => 'test_key', + )); + + $this->assertContains('CLI_CONFIG_DELETE_SUCCESS', $command_tester->getDisplay()); + $this->assertEmpty($this->config); + } + + public function test_delete_error() + { + $this->assertEmpty($this->config); + + $command_tester = $this->get_command_tester('delete'); + $command_tester->execute(array( + 'command' => $this->command_name, + 'key' => 'wrong_key', + )); + + $this->assertContains('CLI_CONFIG_NOT_EXISTS', $command_tester->getDisplay()); + $this->assertEmpty($this->config); + } + + public function get_command_tester($class_name) + { + $command_complete_name = '\phpbb\console\command\config' . '\\' . $class_name; + $application = new Application(); + $application->add(new $command_complete_name($this->user, $this->config)); + $command = $application->find('config:' . $this->command_name); + $this->command_name = $command->getName(); + return new CommandTester($command); + } +} diff --git a/tests/extension/ext/vendor4/bar/composer.json b/tests/extension/ext/vendor4/bar/composer.json new file mode 100644 index 0000000000..1a2fddc3f4 --- /dev/null +++ b/tests/extension/ext/vendor4/bar/composer.json @@ -0,0 +1,23 @@ +{ + "name": "vendor4/bar", + "type": "phpbb-extension", + "description": "An example/sample extension to be used for testing purposes in phpBB Development.", + "version": "1.0.0", + "time": "2012-02-15 01:01:01", + "license": "GPL-2.0", + "authors": [{ + "name": "John Smith", + "email": "email@phpbb.com", + "homepage": "http://phpbb.com", + "role": "N/A" + }], + "require": { + "php": ">=5.3" + }, + "extra": { + "display-name": "phpBB Bar Extension", + "soft-require": { + "phpbb/phpbb": "3.1.*@dev" + } + } +} diff --git a/tests/extension/ext/vendor4/bar/styles/all/template/foobar_body.html b/tests/extension/ext/vendor4/bar/styles/all/template/foobar_body.html new file mode 100644 index 0000000000..c8f8cf957e --- /dev/null +++ b/tests/extension/ext/vendor4/bar/styles/all/template/foobar_body.html @@ -0,0 +1 @@ +All folder diff --git a/tests/extension/manager_test.php b/tests/extension/manager_test.php index 5ec8e60a68..5c7cad89f6 100644 --- a/tests/extension/manager_test.php +++ b/tests/extension/manager_test.php @@ -36,7 +36,7 @@ class phpbb_extension_manager_test extends phpbb_database_test_case public function test_all_available() { // barfoo and vendor3/bar should not listed due to missing composer.json. barfoo also has incorrect dir structure. - $this->assertEquals(array('vendor/moo', 'vendor2/bar', 'vendor2/foo', 'vendor3/foo'), array_keys($this->extension_manager->all_available())); + $this->assertEquals(array('vendor/moo', 'vendor2/bar', 'vendor2/foo', 'vendor3/foo', 'vendor4/bar'), array_keys($this->extension_manager->all_available())); } public function test_all_enabled() diff --git a/tests/functional/extension_acp_test.php b/tests/functional/extension_acp_test.php index 6490c1ead3..7be8957ec7 100644 --- a/tests/functional/extension_acp_test.php +++ b/tests/functional/extension_acp_test.php @@ -84,7 +84,7 @@ class phpbb_functional_extension_acp_test extends phpbb_functional_test_case $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&sid=' . $this->sid); $this->assertCount(1, $crawler->filter('.ext_enabled')); - $this->assertCount(5, $crawler->filter('.ext_disabled')); + $this->assertCount(6, $crawler->filter('.ext_disabled')); $this->assertContains('phpBB Foo Extension', $crawler->filter('.ext_enabled')->eq(0)->text()); $this->assertContainsLang('EXTENSION_DISABLE', $crawler->filter('.ext_enabled')->eq(0)->text()); diff --git a/tests/functional/extension_controller_test.php b/tests/functional/extension_controller_test.php index 532a160a47..18eb9ad4c6 100644 --- a/tests/functional/extension_controller_test.php +++ b/tests/functional/extension_controller_test.php @@ -26,6 +26,8 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c 'foo/bar/event/', 'foo/bar/language/en/', 'foo/bar/styles/prosilver/template/', + 'foo/foo/config/', + 'foo/foo/controller/', ); static public function setUpBeforeClass() @@ -65,6 +67,18 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c } /** + * Check a controller for extension foo/bar. + */ + public function test_routing_resources() + { + $this->phpbb_extension_manager->enable('foo/foo'); + $crawler = self::request('GET', 'app.php/foo/foo', array(), false); + self::assert_response_status_code(); + $this->assertContains("foo/foo controller handle() method", $crawler->filter('body')->text()); + $this->phpbb_extension_manager->purge('foo/foo'); + } + + /** * Check the output of a controller using the template system */ public function test_controller_with_template() diff --git a/tests/functional/fileupload_form_test.php b/tests/functional/fileupload_form_test.php index e87953367f..b8c48389e0 100644 --- a/tests/functional/fileupload_form_test.php +++ b/tests/functional/fileupload_form_test.php @@ -107,9 +107,9 @@ class phpbb_functional_fileupload_form_test extends phpbb_functional_test_case $crawler = $this->upload_file('disallowed.jpg', 'image/jpeg'); - // Hitting the ATTACHED_IMAGE_NOT_IMAGE error means we passed the + // Hitting the UNABLE_GET_IMAGE_SIZE error means we passed the // DISALLOWED_CONTENT check - $this->assertContains($this->lang('ATTACHED_IMAGE_NOT_IMAGE'), $crawler->text()); + $this->assertContainsLang('UNABLE_GET_IMAGE_SIZE', $crawler->text()); } public function test_too_large() diff --git a/tests/functional/fixtures/ext/foo/foo/composer.json b/tests/functional/fixtures/ext/foo/foo/composer.json new file mode 100644 index 0000000000..d85c76a6a2 --- /dev/null +++ b/tests/functional/fixtures/ext/foo/foo/composer.json @@ -0,0 +1,24 @@ +{ + "name": "foo/foo", + "type": "phpbb-extension", + "description": "Testing extensions", + "homepage": "", + "version": "1.0.0", + "time": "2013-03-21 01:01:01", + "license": "GPL-2.0", + "authors": [{ + "name": "Tristan Darricau", + "email": "nicofuma@phpbb.com", + "homepage": "http://www.phpbb.com", + "role": "Developer" + }], + "require": { + "php": ">=5.3" + }, + "extra": { + "display-name": "phpBB 3.1 Extension Testing", + "soft-require": { + "phpbb/phpbb": "3.1.*@dev" + } + } +} diff --git a/tests/functional/fixtures/ext/foo/foo/config/resource.yml b/tests/functional/fixtures/ext/foo/foo/config/resource.yml new file mode 100644 index 0000000000..ed1d018016 --- /dev/null +++ b/tests/functional/fixtures/ext/foo/foo/config/resource.yml @@ -0,0 +1,3 @@ +foo_foo_controller: + pattern: /foo + defaults: { _controller: foo_foo.controller:handle } diff --git a/tests/functional/fixtures/ext/foo/foo/config/routing.yml b/tests/functional/fixtures/ext/foo/foo/config/routing.yml new file mode 100644 index 0000000000..c2c401687d --- /dev/null +++ b/tests/functional/fixtures/ext/foo/foo/config/routing.yml @@ -0,0 +1,3 @@ +foo_foo.general: + resource: "resource.yml" + prefix: /foo diff --git a/tests/functional/fixtures/ext/foo/foo/config/services.yml b/tests/functional/fixtures/ext/foo/foo/config/services.yml new file mode 100644 index 0000000000..b3c7719715 --- /dev/null +++ b/tests/functional/fixtures/ext/foo/foo/config/services.yml @@ -0,0 +1,3 @@ +services: + foo_foo.controller: + class: foo\foo\controller\controller diff --git a/tests/functional/fixtures/ext/foo/foo/controller/controller.php b/tests/functional/fixtures/ext/foo/foo/controller/controller.php new file mode 100644 index 0000000000..771eaeacfc --- /dev/null +++ b/tests/functional/fixtures/ext/foo/foo/controller/controller.php @@ -0,0 +1,13 @@ +<?php + +namespace foo\foo\controller; + +use Symfony\Component\HttpFoundation\Response; + +class controller +{ + public function handle() + { + return new Response('foo/foo controller handle() method', 200); + } +} diff --git a/tests/functional/fixtures/ext/foo/foo/ext.php b/tests/functional/fixtures/ext/foo/foo/ext.php new file mode 100644 index 0000000000..80acda74fe --- /dev/null +++ b/tests/functional/fixtures/ext/foo/foo/ext.php @@ -0,0 +1,8 @@ +<?php + +namespace foo\foo; + +class ext extends \phpbb\extension\base +{ + +} diff --git a/tests/functional/ucp_preferences_test.php b/tests/functional/ucp_preferences_test.php new file mode 100644 index 0000000000..7ef325dc4b --- /dev/null +++ b/tests/functional/ucp_preferences_test.php @@ -0,0 +1,85 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +/** +* @group functional +*/ +class phpbb_functional_ucp_preferences_test extends phpbb_functional_test_case +{ + public function test_submitting_preferences_view() + { + $this->add_lang('ucp'); + $this->login(); + + $crawler = self::request('GET', 'ucp.php?i=ucp_prefs&mode=view'); + $this->assertContainsLang('UCP_PREFS_VIEW', $crawler->filter('#cp-main h2')->text()); + + $form = $crawler->selectButton('Submit')->form(array( + 'topic_sk' => 'a', + 'topic_sd' => 'a', + 'topic_st' => '1', + 'post_sk' => 'a', + 'post_sd' => 'a', + 'post_st' => '1', + )); + + $crawler = self::submit($form); + $this->assertContainsLang('PREFERENCES_UPDATED', $crawler->filter('#message')->text()); + } + + public function test_submitting_invalid_preferences_view() + { + $this->add_lang('ucp'); + $this->login(); + + $crawler = self::request('GET', 'ucp.php?i=ucp_prefs&mode=view'); + $this->assertContainsLang('UCP_PREFS_VIEW', $crawler->filter('#cp-main h2')->text()); + $form = $crawler->selectButton('Submit')->form(); + + if (!method_exists($form, 'disableValidation')) + { + $this->markTestIncomplete('The crawler cannot select invalid values, until Symfony 2.4!'); + } + + $form = $form->disableValidation(); + $form['topic_sk']->select('z'); + $form['topic_sd']->select('z'); + $form['topic_st']->select('test'); + $form['post_sk']->select('z'); + $form['post_sd']->select('z'); + $form['post_st']->select('test'); + + $crawler = self::submit($form); + $this->assertContainsLang('WRONG_DATA_POST_SD', $crawler->filter('#cp-main')->text()); + $this->assertContainsLang('WRONG_DATA_POST_SK', $crawler->filter('#cp-main')->text()); + $this->assertContainsLang('WRONG_DATA_TOPIC_SD', $crawler->filter('#cp-main')->text()); + $this->assertContainsLang('WRONG_DATA_TOPIC_SK', $crawler->filter('#cp-main')->text()); + } + + public function test_read_preferences_view() + { + $this->add_lang('ucp'); + $this->login(); + + $crawler = self::request('GET', 'ucp.php?i=ucp_prefs&mode=view'); + $this->assertContainsLang('UCP_PREFS_VIEW', $crawler->filter('#cp-main h2')->text()); + $form = $crawler->selectButton('Submit')->form(); + + $this->assertEquals('a', $form->get('topic_sk')->getValue()); + $this->assertEquals('a', $form->get('topic_sd')->getValue()); + $this->assertEquals('1', $form->get('topic_st')->getValue()); + $this->assertEquals('a', $form->get('post_sk')->getValue()); + $this->assertEquals('a', $form->get('post_sd')->getValue()); + $this->assertEquals('1', $form->get('post_st')->getValue()); + } +} diff --git a/tests/mimetype/guesser_test.php b/tests/mimetype/guesser_test.php index b74a9f236e..fa53e6c8c4 100644 --- a/tests/mimetype/guesser_test.php +++ b/tests/mimetype/guesser_test.php @@ -206,4 +206,25 @@ class guesser_test extends \phpbb_test_case $this->assertInstanceOf('\phpbb\mimetype\content_guesser', $guessers[0]); $this->assertInstanceOf('\phpbb\mimetype\extension_guesser', $guessers[3]); } + + public function data_choose_mime_type() + { + return array( + array('application/octet-stream', 'application/octet-stream', null), + array('application/octet-stream', 'application/octet-stream', 'application/octet-stream'), + array('binary', 'application/octet-stream', 'binary'), + array('image/jpeg', 'application/octet-stream', 'image/jpeg'), + array('image/jpeg', 'binary', 'image/jpeg'), + array('image/jpeg', 'image/jpg', 'image/jpeg'), + array('image/jpeg', 'image/jpeg', 'binary'), + ); + } + + /** + * @dataProvider data_choose_mime_type + */ + public function test_choose_mime_type($expected, $mime_type, $guess) + { + $this->assertSame($expected, $this->guesser->choose_mime_type($mime_type, $guess)); + } } diff --git a/tests/path_helper/path_helper_test.php b/tests/path_helper/path_helper_test.php index 27e94d6a07..3832307897 100644 --- a/tests/path_helper/path_helper_test.php +++ b/tests/path_helper/path_helper_test.php @@ -205,6 +205,18 @@ class phpbb_path_helper_test extends phpbb_test_case array('test' => 'xyz', 'var' => 'value'), 'test=xyz&var=value', ), + array( + array('test' => null), + 'test', + ), + array( + array('test' => null, 'var' => null), + 'test&var', + ), + array( + array('test' => 'xyz', 'var' => null, 'bar' => 'value'), + 'test=xyz&var&bar=value', + ), ); } @@ -254,6 +266,21 @@ class phpbb_path_helper_test extends phpbb_test_case true, array('base' => 'mcp.php', 'params' => array('f' => '3')), ), + array( + 'index.php?ready', + false, + array('base' => 'index.php', 'params' => array('ready' => null)), + ), + array( + 'index.php?i=1&ready', + true, + array('base' => 'index.php', 'params' => array('i' => '1', 'ready' => null)), + ), + array( + 'index.php?ready&i=1', + false, + array('base' => 'index.php', 'params' => array('ready' => null, 'i' => '1')), + ), ); } diff --git a/tests/template/template_allfolder_test.php b/tests/template/template_allfolder_test.php new file mode 100644 index 0000000000..b4ad84e9c3 --- /dev/null +++ b/tests/template/template_allfolder_test.php @@ -0,0 +1,59 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @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__) . '/template_test_case.php'; + +class phpbb_template_allfolder_test extends phpbb_template_template_test_case +{ + public function test_allfolder() + { + $this->setup_engine_for_allfolder(); + + $this->run_template('foobar_body.html', array(), array(), array(), "All folder"); + } + + protected function setup_engine_for_allfolder(array $new_config = array()) + { + global $phpbb_root_path, $phpEx; + + $defaults = $this->config_defaults(); + $config = new \phpbb\config\config(array_merge($defaults, $new_config)); + $this->user = new \phpbb\user('\phpbb\datetime'); + + $path_helper = new \phpbb\path_helper( + new \phpbb\symfony_request( + new phpbb_mock_request() + ), + new \phpbb\filesystem(), + $this->getMock('\phpbb\request\request'), + $phpbb_root_path, + $phpEx + ); + + $this->extension_manager = new phpbb_mock_extension_manager( + dirname(__FILE__) . '/', + array( + 'vendor4/bar' => array( + 'ext_name' => 'vendor4/bar', + 'ext_active' => '1', + 'ext_path' => 'ext/vendor4/bar/', + ), + ) + ); + + $this->template_path = $this->test_path . '/templates'; + $this->ext_template_path = 'tests/extension/ext/vendor4/bar/styles/all/template'; + $this->template = new \phpbb\template\twig\twig($path_helper, $config, $this->user, new \phpbb\template\context(), $this->extension_manager); + $this->template->set_custom_style('all', array($this->template_path, $this->ext_template_path)); + } +} |