diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/extension/ext/vendor5/foo/composer.json | 23 | ||||
-rw-r--r-- | tests/extension/ext/vendor5/foo/ext.php | 19 | ||||
-rw-r--r-- | tests/extension/manager_test.php | 2 | ||||
-rw-r--r-- | tests/functional/extension_acp_test.php | 9 | ||||
-rw-r--r-- | tests/functional/fileupload_form_test.php | 9 | ||||
-rw-r--r-- | tests/functional/plupload_test.php | 14 | ||||
-rw-r--r-- | tests/functions/fixtures/validate_email.xml | 24 | ||||
-rw-r--r-- | tests/functions/validate_user_email_test.php | 12 | ||||
-rw-r--r-- | tests/template/extension_test.php | 258 | ||||
-rw-r--r-- | tests/template/templates/avatar_user.html | 1 | ||||
-rw-r--r-- | tests/template/templates/extension_config_test.html | 1 | ||||
-rw-r--r-- | tests/template/templates/extension_username_test.html | 1 | ||||
-rw-r--r-- | tests/test_framework/phpbb_functional_test_case.php | 51 | ||||
-rw-r--r-- | tests/text_formatter/s9e/default_formatting_test.php | 2 | ||||
-rw-r--r-- | tests/text_processing/tickets_data/PHPBB3-13921.html | 2 |
15 files changed, 401 insertions, 27 deletions
diff --git a/tests/extension/ext/vendor5/foo/composer.json b/tests/extension/ext/vendor5/foo/composer.json new file mode 100644 index 0000000000..0fa052e188 --- /dev/null +++ b/tests/extension/ext/vendor5/foo/composer.json @@ -0,0 +1,23 @@ +{ + "name": "vendor5/foo", + "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.3.*@dev" + } + } +} diff --git a/tests/extension/ext/vendor5/foo/ext.php b/tests/extension/ext/vendor5/foo/ext.php new file mode 100644 index 0000000000..6bf03f001c --- /dev/null +++ b/tests/extension/ext/vendor5/foo/ext.php @@ -0,0 +1,19 @@ +<?php + +namespace vendor5\foo; + +class ext extends \phpbb\extension\base +{ + static public $enabled; + + public function is_enableable() + { + return array('Reason 1', 'Reason 2'); + } + + public function enable_step($old_state) + { + self::$enabled = true; + return self::$enabled; + } +} diff --git a/tests/extension/manager_test.php b/tests/extension/manager_test.php index 231af81a39..3ab0f608d1 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', 'vendor4/bar'), array_keys($this->extension_manager->all_available())); + $this->assertEquals(array('vendor/moo', 'vendor2/bar', 'vendor2/foo', 'vendor3/foo', 'vendor4/bar', 'vendor5/foo'), 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 b398a73e3f..9a326dba68 100644 --- a/tests/functional/extension_acp_test.php +++ b/tests/functional/extension_acp_test.php @@ -86,7 +86,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(6, $crawler->filter('.ext_disabled')); + $this->assertCount(7, $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()); @@ -165,9 +165,14 @@ class phpbb_functional_extension_acp_test extends phpbb_functional_test_case $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=enable_pre&ext_name=vendor%2Fmoo&sid=' . $this->sid); $this->assertContains($this->lang('EXTENSION_ENABLE_CONFIRM', 'phpBB Moo Extension'), $crawler->filter('#main')->text()); - // Correctly submit the enable form + // Correctly submit the enable form, default not enableable message $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=enable_pre&ext_name=vendor3%2Ffoo&sid=' . $this->sid); $this->assertContainsLang('EXTENSION_NOT_ENABLEABLE', $crawler->filter('.errorbox')->text()); + + // Custom reason messages returned by not enableable extension + $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=enable_pre&ext_name=vendor5%2Ffoo&sid=' . $this->sid); + $this->assertContains('Reason 1', $crawler->filter('.errorbox')->text()); + $this->assertContains('Reason 2', $crawler->filter('.errorbox')->text()); } public function test_disable_pre() diff --git a/tests/functional/fileupload_form_test.php b/tests/functional/fileupload_form_test.php index b0838344de..b2f230b66f 100644 --- a/tests/functional/fileupload_form_test.php +++ b/tests/functional/fileupload_form_test.php @@ -46,6 +46,13 @@ class phpbb_functional_fileupload_form_test extends phpbb_functional_test_case private function upload_file($filename, $mimetype) { + $crawler = self::$client->request( + 'GET', + 'posting.php?mode=reply&f=2&t=1&sid=' . $this->sid + ); + + $file_form_data = array_merge(['add_file' => $this->lang('ADD_FILE')], $this->get_hidden_fields($crawler, 'posting.php?mode=reply&f=2&t=1&sid=' . $this->sid)); + $file = array( 'tmp_name' => $this->path . $filename, 'name' => $filename, @@ -57,7 +64,7 @@ class phpbb_functional_fileupload_form_test extends phpbb_functional_test_case $crawler = self::$client->request( 'POST', 'posting.php?mode=reply&f=2&t=1&sid=' . $this->sid, - array('add_file' => $this->lang('ADD_FILE')), + $file_form_data, array('fileupload' => $file) ); diff --git a/tests/functional/plupload_test.php b/tests/functional/plupload_test.php index c3b2e5b9eb..b7b5b08360 100644 --- a/tests/functional/plupload_test.php +++ b/tests/functional/plupload_test.php @@ -76,6 +76,10 @@ class phpbb_functional_plupload_test extends phpbb_functional_test_case $chunk_size = ceil(filesize($this->path . 'valid.jpg') / self::CHUNKS); $handle = fopen($this->path . 'valid.jpg', 'rb'); + $crawler = self::$client->request('POST', $url . '&sid=' . $this->sid); + + $file_form_data = $this->get_hidden_fields($crawler, $url); + for ($i = 0; $i < self::CHUNKS; $i++) { $chunk = fread($handle, $chunk_size); @@ -94,13 +98,13 @@ class phpbb_functional_plupload_test extends phpbb_functional_test_case $crawler = self::$client->request( 'POST', $url . '&sid=' . $this->sid, - array( + array_merge(array( 'chunk' => $i, 'chunks' => self::CHUNKS, 'name' => md5('valid') . '.jpg', 'real_filename' => 'valid.jpg', 'add_file' => $this->lang('ADD_FILE'), - ), + ), $file_form_data), array('fileupload' => $file), array('X-PHPBB-USING-PLUPLOAD' => '1') ); @@ -134,17 +138,19 @@ class phpbb_functional_plupload_test extends phpbb_functional_test_case 'error' => UPLOAD_ERR_OK, ); + $file_form_data = $this->get_hidden_fields(null, $url); + self::$client->setServerParameter('HTTP_X_PHPBB_USING_PLUPLOAD', '1'); self::$client->request( 'POST', $url . '&sid=' . $this->sid, - array( + array_merge(array( 'chunk' => '0', 'chunks' => '1', 'name' => md5('valid') . '.jpg', 'real_filename' => 'valid.jpg', 'add_file' => $this->lang('ADD_FILE'), - ), + ), $file_form_data), array('fileupload' => $file) ); diff --git a/tests/functions/fixtures/validate_email.xml b/tests/functions/fixtures/validate_email.xml index eb4fd90217..fa139f6f18 100644 --- a/tests/functions/fixtures/validate_email.xml +++ b/tests/functions/fixtures/validate_email.xml @@ -1,5 +1,29 @@ <?xml version="1.0" encoding="UTF-8" ?> <dataset> + <table name="phpbb_banlist"> + <column>ban_id</column> + <column>ban_userid</column> + <column>ban_exclude</column> + <column>ban_end</column> + <column>ban_email</column> + <column>ban_give_reason</column> + <row> + <value>1</value> + <value>0</value> + <value>0</value> + <value>0</value> + <value>banned@example.com</value> + <value></value> + </row> + <row> + <value>2</value> + <value>0</value> + <value>0</value> + <value>0</value> + <value>banned2@example.com</value> + <value>just because</value> + </row> + </table> <table name="phpbb_users"> <column>user_id</column> <column>username</column> diff --git a/tests/functions/validate_user_email_test.php b/tests/functions/validate_user_email_test.php index a05a7808a4..eeb5bfc2a9 100644 --- a/tests/functions/validate_user_email_test.php +++ b/tests/functions/validate_user_email_test.php @@ -28,10 +28,16 @@ class phpbb_functions_validate_user_email_test extends phpbb_database_test_case protected function setUp(): void { + global $cache, $phpbb_dispatcher, $phpbb_root_path, $phpEx; + parent::setUp(); + $cache = new \phpbb\cache\driver\file(); + $cache->purge(); $this->db = $this->new_dbal(); - $this->user = new phpbb_mock_user; + $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); + $language = new phpbb\language\language(new phpbb\language\language_file_loader($phpbb_root_path, $phpEx)); + $this->user = new phpbb\user($language, '\phpbb\datetime'); $this->helper = new phpbb_functions_validate_data_helper($this); } @@ -47,7 +53,6 @@ class phpbb_functions_validate_user_email_test extends phpbb_database_test_case $config['email_check_mx'] = $check_mx; $db = $this->db; $user = $this->user; - $user->optionset('banned_users', array('banned@example.com')); } public static function validate_user_email_data() @@ -58,7 +63,8 @@ class phpbb_functions_validate_user_email_test extends phpbb_database_test_case array('valid_complex', array(), "'%$~test@example.com"), array('invalid', array('EMAIL_INVALID'), 'fööbar@example.com'), array('taken', array('EMAIL_TAKEN'), 'admin@example.com'), - array('banned', array('EMAIL_BANNED'), 'banned@example.com'), + array('banned', ['just because'], 'banned2@example.com'), + array('banned', ['EMAIL_BANNED'], 'banned@example.com') ); } diff --git a/tests/template/extension_test.php b/tests/template/extension_test.php new file mode 100644 index 0000000000..d633001060 --- /dev/null +++ b/tests/template/extension_test.php @@ -0,0 +1,258 @@ +<?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_extension_test extends phpbb_template_template_test_case +{ + protected function setup_engine(array $new_config = array()) + { + global $config, $phpbb_container, $phpbb_dispatcher, $phpbb_root_path, $phpEx; + + $defaults = $this->config_defaults(); + $defaults = array_merge($defaults, [ + 'allow_avatar' => true, + 'allow_avatar_upload' => true, + ]); + $config = new \phpbb\config\config(array_merge($defaults, $new_config)); + $lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); + $this->lang = $lang = new \phpbb\language\language($lang_loader); + $this->user = new \phpbb\user($lang, '\phpbb\datetime'); + + global $auth, $request, $symfony_request, $user; + $user = new phpbb_mock_user(); + $user->optionset('user_id', 2); + $auth = $this->getMockBuilder('phpbb\auth\auth') + ->disableOriginalConstructor() + ->setMethods(['acl_get']) + ->getMock(); + $auth->method('acl_get') + ->willReturn(true); + + $filesystem = new \phpbb\filesystem\filesystem(); + $request = new phpbb_mock_request; + $symfony_request = new \phpbb\symfony_request( + $request + ); + $phpbb_path_helper = new \phpbb\path_helper( + $symfony_request, + $filesystem, + $request, + $phpbb_root_path, + $phpEx + ); + + $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); + $phpbb_container = new phpbb_mock_container_builder(); + $files = new phpbb\files\factory($phpbb_container); + $upload_avatar_driver = new phpbb\avatar\driver\upload($config, $phpbb_root_path, $phpEx, $filesystem, $phpbb_path_helper, $phpbb_dispatcher, $files); + $upload_avatar_driver->set_name('avatar.driver.upload'); + $phpbb_container->set('avatar.manager', new \phpbb\avatar\manager($config, $phpbb_dispatcher, [ + $upload_avatar_driver, + ])); + $phpbb_container->set('path_helper', $phpbb_path_helper); + + $class = new ReflectionClass('\phpbb\avatar\manager'); + $enabled_drivers = $class->getProperty('enabled_drivers'); + $enabled_drivers->setAccessible(true); + $enabled_drivers->setValue(false); + + $this->template_path = $this->test_path . '/templates'; + + $cache_path = $phpbb_root_path . 'cache/twig'; + $context = new \phpbb\template\context(); + $loader = new \phpbb\template\twig\loader($filesystem); + $twig = new \phpbb\template\twig\environment( + $config, + $filesystem, + $phpbb_path_helper, + $cache_path, + null, + $loader, + new \phpbb\event\dispatcher($phpbb_container), + array( + 'cache' => false, + 'debug' => false, + 'auto_reload' => true, + 'autoescape' => false, + ) + ); + $this->template = new phpbb\template\twig\twig( + $phpbb_path_helper, + $config, + $context, + $twig, + $cache_path, + $this->user, + [ + new \phpbb\template\twig\extension($context, $twig, $this->lang), + new \phpbb\template\twig\extension\avatar(), + new \phpbb\template\twig\extension\config($config), + new \phpbb\template\twig\extension\username(), + ] + ); + $twig->setLexer(new \phpbb\template\twig\lexer($twig)); + $this->template->set_custom_style('tests', $this->template_path); + } + + public function data_template_extensions() + { + return [ + [ + 'avatar_user.html', + [ + 'row' => [ + 'user_avatar' => 'great_avatar.png', + 'user_avatar_type' => 'avatar.driver.upload', + 'user_avatar_width' => 90, + 'user_avatar_height' => 90, + ], + 'alt' => 'foo' + ], + [], + [], + '<img class="avatar" src="phpBB/download/file.php?avatar=great_avatar.png" width="90" height="90" alt="foo" />', + [] + ], + [ + 'avatar_user.html', + [ + 'row' => [ + 'user_avatar' => 'great_avatar.png', + 'user_avatar_type' => 'avatar.driver.upload', + 'user_avatar_width' => 90, + 'user_avatar_height' => 90, + ], + 'alt' => 'foo', + 'ignore_config' => true, + 'lazy' => true, + ], + [], + [], + '<img class="avatar" src="phpBB/styles//theme/images/no_avatar.gif" data-src="phpBB/download/file.php?avatar=great_avatar.png" width="90" height="90" alt="foo" />', + [] + ], + [ + 'avatar_user.html', + [ + 'row' => [ + 'user_avatar' => 'foo@bar.com', + 'user_avatar_type' => 'avatar.driver.gravatar', + 'user_avatar_width' => 90, + 'user_avatar_height' => 90, + ], + 'alt' => 'foo' + ], + [], + [], + '', + [] + ], + [ + 'extension_username_test.html', + [ + 'mode' => 'profile', + 'user_id' => 2, + 'username' => 'admin', + 'user_colour' => 'abcdef', + 'guest_username' => 'lol', + ], + [], + [], + 'phpBB/memberlist.php?mode=viewprofile&u=2', + [] + ], + [ + 'extension_username_test.html', + [ + 'mode' => 'profile', + 'user_id' => 2, + 'username' => 'admin', + 'user_colour' => 'abcdef', + 'guest_username' => 'lol', + 'custom_profile_url' => 'http://lol.bar', + ], + [], + [], + 'http://lol.bar&u=2', + [] + ], + [ + 'extension_username_test.html', + [ + 'mode' => 'full', + 'user_id' => 2, + 'username' => 'admin', + 'user_colour' => 'abcdef', + 'guest_username' => 'lol', + ], + [], + [], + '<a href="phpBB/memberlist.php?mode=viewprofile&u=2" style="color: #abcdef;" class="username-coloured">admin</a>', + [] + ], + [ + 'extension_username_test.html', + [ + 'mode' => 'no_profile', + 'user_id' => 2, + 'username' => 'admin', + 'user_colour' => 'abcdef', + 'guest_username' => 'lol', + ], + [], + [], + '<span style="color: #abcdef;" class="username-coloured">admin</span>', + [] + ], + [ + 'extension_config_test.html', + [ + 'config_name' => 'allow_avatar', + ], + [], + [], + '1', + [] + ], + [ + 'extension_config_test.html', + [ + 'config_name' => 'does not exist', + ], + [], + [], + '', + [] + ], + [ + 'extension_config_test.html', + [ + 'config_name' => 'tpl_allow_php', + ], + [], + [], + '', + [] + ], + ]; + } + + /** + * @dataProvider data_template_extensions + */ + public function test_get_user_avatar($file, $vars, $block_vars, $destroy_array, $expected, $lang_vars = []) + { + $this->run_template($file, $vars, $block_vars, $destroy_array, $expected, $lang_vars); + } +} diff --git a/tests/template/templates/avatar_user.html b/tests/template/templates/avatar_user.html new file mode 100644 index 0000000000..bd0b960611 --- /dev/null +++ b/tests/template/templates/avatar_user.html @@ -0,0 +1 @@ +{{ avatar('user', row, alt, ignore_config, lazy) }} diff --git a/tests/template/templates/extension_config_test.html b/tests/template/templates/extension_config_test.html new file mode 100644 index 0000000000..0f12ab2672 --- /dev/null +++ b/tests/template/templates/extension_config_test.html @@ -0,0 +1 @@ +{{ config(config_name) }} diff --git a/tests/template/templates/extension_username_test.html b/tests/template/templates/extension_username_test.html new file mode 100644 index 0000000000..a78bf0df62 --- /dev/null +++ b/tests/template/templates/extension_username_test.html @@ -0,0 +1 @@ +{{ username(mode, user_id, username, user_colour, guest_username, custom_profile_url) }} diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 090ee07d65..4c2afa4f30 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -1232,24 +1232,14 @@ class phpbb_functional_test_case extends phpbb_test_case 'error' => UPLOAD_ERR_OK, ); - $crawler = self::$client->request('POST', $posting_url, array('add_file' => $this->lang('ADD_FILE')), array('fileupload' => $file)); + $file_form_data = array_merge(['add_file' => $this->lang('ADD_FILE')], $this->get_hidden_fields($crawler, $posting_url)); + + $crawler = self::$client->request('POST', $posting_url, $file_form_data, array('fileupload' => $file)); } unset($form_data['upload_files']); } - $hidden_fields = array( - $crawler->filter('[type="hidden"]')->each(function ($node, $i) { - return array('name' => $node->attr('name'), 'value' => $node->attr('value')); - }), - ); - - foreach ($hidden_fields as $fields) - { - foreach($fields as $field) - { - $form_data[$field['name']] = $field['value']; - } - } + $form_data = array_merge($form_data, $this->get_hidden_fields($crawler, $posting_url)); // I use a request because the form submission method does not allow you to send data that is not // contained in one of the actual form fields that the browser sees (i.e. it ignores "hidden" inputs) @@ -1380,4 +1370,37 @@ class phpbb_functional_test_case extends phpbb_test_case return self::request('GET', substr($link, strpos($link, 'mcp.'))); } + + /** + * Get hidden fields for URL + * + * @param Symfony\Component\DomCrawler\Crawler|null $crawler Crawler instance or null + * @param string $url Request URL + * + * @return array Hidden form fields array + */ + protected function get_hidden_fields($crawler, $url) + { + if (!$crawler) + { + $crawler = self::$client->request('GET', $url); + } + $hidden_fields = [ + $crawler->filter('[type="hidden"]')->each(function ($node, $i) { + return ['name' => $node->attr('name'), 'value' => $node->attr('value')]; + }), + ]; + + $file_form_data = []; + + foreach ($hidden_fields as $fields) + { + foreach($fields as $field) + { + $file_form_data[$field['name']] = $field['value']; + } + } + + return $file_form_data; + } } diff --git a/tests/text_formatter/s9e/default_formatting_test.php b/tests/text_formatter/s9e/default_formatting_test.php index a35c9138a5..1aa4f0bc3a 100644 --- a/tests/text_formatter/s9e/default_formatting_test.php +++ b/tests/text_formatter/s9e/default_formatting_test.php @@ -70,7 +70,7 @@ class phpbb_textformatter_s9e_default_formatting_test extends phpbb_test_case ), array( '[size=75]smaller[/size]', - '<span style="font-size:75%;line-height:normal">smaller</span>' + '<span style="font-size: 75%; line-height: normal">smaller</span>' ), array( '[quote]quoted[/quote]', diff --git a/tests/text_processing/tickets_data/PHPBB3-13921.html b/tests/text_processing/tickets_data/PHPBB3-13921.html index 690668ef28..6a9dc7f504 100644 --- a/tests/text_processing/tickets_data/PHPBB3-13921.html +++ b/tests/text_processing/tickets_data/PHPBB3-13921.html @@ -1 +1 @@ -<span style="font-size:200%;line-height:normal"></span><div style="text-align:center"><span style="font-size:200%;line-height:normal">xxx</span></div>
\ No newline at end of file +<span style="font-size: 200%; line-height: normal"></span><div style="text-align:center"><span style="font-size: 200%; line-height: normal">xxx</span></div>
\ No newline at end of file |