diff options
Diffstat (limited to 'tests')
47 files changed, 1355 insertions, 73 deletions
diff --git a/tests/bbcode/parser_test.php b/tests/bbcode/parser_test.php index 5677e49636..4e85737c4f 100644 --- a/tests/bbcode/parser_test.php +++ b/tests/bbcode/parser_test.php @@ -66,11 +66,6 @@ class phpbb_bbcode_parser_test extends \phpbb_test_case '[code:]unparsed code[/code:]', ), array( - 'Test default bbcodes: simple php code', - '[code=php]unparsed code[/code]', - '[code=php:]<span class="syntaxdefault">unparsed code</span>[/code:]', - ), - array( 'Test default bbcodes: simple list', '[list]no item[/list]', '[list:]no item[/list:u:]', diff --git a/tests/controller/common_helper_route.php b/tests/controller/common_helper_route.php index 367c15a667..ea2bc042b1 100644 --- a/tests/controller/common_helper_route.php +++ b/tests/controller/common_helper_route.php @@ -114,6 +114,7 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case $cache_path, null, $loader, + new \phpbb\event\dispatcher($container), array( 'cache' => false, 'debug' => false, diff --git a/tests/di/create_container_test.php b/tests/di/create_container_test.php index aba7a3560b..1fd2cbd7ee 100644 --- a/tests/di/create_container_test.php +++ b/tests/di/create_container_test.php @@ -46,6 +46,7 @@ namespace { $container = $this->builder->get_container(); $this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container); + $this->assertFalse($container->hasParameter('container_exception')); // Checks the core services $this->assertTrue($container->hasParameter('core')); @@ -54,7 +55,7 @@ namespace $this->assertTrue($container->isFrozen()); // Checks inject_config - $this->assertTrue($container->hasParameter('dbal.dbhost')); + $this->assertTrue($container->hasParameter('core.table_prefix')); // Checks use_extensions $this->assertTrue($container->hasParameter('enabled')); diff --git a/tests/di/fixtures/config/production/container/environment.yml b/tests/di/fixtures/config/production/container/environment.yml index 4216b187cc..8281d9e941 100644 --- a/tests/di/fixtures/config/production/container/environment.yml +++ b/tests/di/fixtures/config/production/container/environment.yml @@ -10,6 +10,9 @@ services: arguments: - '@service_container' + dbal.conn.driver: + synthetic: true + dispatcher: class: phpbb\db\driver\container_mock diff --git a/tests/di/fixtures/config/test/container/environment.yml b/tests/di/fixtures/config/test/container/environment.yml index 7d528fed19..252117dd32 100644 --- a/tests/di/fixtures/config/test/container/environment.yml +++ b/tests/di/fixtures/config/test/container/environment.yml @@ -10,6 +10,9 @@ services: arguments: - '@service_container' + dbal.conn.driver: + synthetic: true + dispatcher: class: phpbb\db\driver\container_mock diff --git a/tests/di/fixtures/other_config/production/container/environment.yml b/tests/di/fixtures/other_config/production/container/environment.yml index 1170145b66..c0d2f87bab 100644 --- a/tests/di/fixtures/other_config/production/container/environment.yml +++ b/tests/di/fixtures/other_config/production/container/environment.yml @@ -10,6 +10,9 @@ services: arguments: - '@service_container' + dbal.conn.driver: + synthetic: true + dispatcher: class: phpbb\db\driver\container_mock diff --git a/tests/di/fixtures/other_config/test/container/environment.yml b/tests/di/fixtures/other_config/test/container/environment.yml index 6c36977d4d..b9f6d05018 100644 --- a/tests/di/fixtures/other_config/test/container/environment.yml +++ b/tests/di/fixtures/other_config/test/container/environment.yml @@ -10,6 +10,9 @@ services: arguments: - '@service_container' + dbal.conn.driver: + synthetic: true + dispatcher: class: phpbb\db\driver\container_mock diff --git a/tests/email/email_parsing_test.php b/tests/email/email_parsing_test.php index 351a38514f..8fdfe3035e 100644 --- a/tests/email/email_parsing_test.php +++ b/tests/email/email_parsing_test.php @@ -81,6 +81,7 @@ class phpbb_email_parsing_test extends phpbb_test_case $cache_path, null, new \phpbb\template\twig\loader($filesystem, ''), + new \phpbb\event\dispatcher($phpbb_container), array( 'cache' => false, 'debug' => false, diff --git a/tests/event/fixtures/trigger_many_vars.test b/tests/event/fixtures/trigger_many_vars.test index a624138588..5e0720d13b 100644 --- a/tests/event/fixtures/trigger_many_vars.test +++ b/tests/event/fixtures/trigger_many_vars.test @@ -34,7 +34,7 @@ * posting page via $template->assign_vars() * @var object message_parser The message parser object * @since 3.1.0-a1 - * @change 3.1.0-b3 Added vars post_data, moderators, mode, page_title, + * @changed 3.1.0-b3 Added vars post_data, moderators, mode, page_title, * s_topic_icons, form_enctype, s_action, s_hidden_fields, * post_id, topic_id, forum_id, submit, preview, save, load, * delete, cancel, refresh, error, page_data, message_parser diff --git a/tests/extension/metadata_manager_test.php b/tests/extension/metadata_manager_test.php index ce675f0d36..533da68c57 100644 --- a/tests/extension/metadata_manager_test.php +++ b/tests/extension/metadata_manager_test.php @@ -70,6 +70,7 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case $cache_path, null, $loader, + new \phpbb\event\dispatcher($container), array( 'cache' => false, 'debug' => false, @@ -78,8 +79,6 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case ) ); - $container = new phpbb_mock_container_builder(); - $this->migrator = new \phpbb\db\migrator( $container, $this->config, @@ -364,9 +363,7 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case { return new phpbb_mock_metadata_manager( $ext_name, - $this->config, - $this->extension_manager, - $this->phpbb_root_path + $this->extension_manager->get_extension_path($ext_name, true) ); } } diff --git a/tests/feed/attachments_base_test.php b/tests/feed/attachments_base_test.php new file mode 100644 index 0000000000..dd432d13f5 --- /dev/null +++ b/tests/feed/attachments_base_test.php @@ -0,0 +1,99 @@ +<?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__) . '/attachments_mock_feed.php'); + +class phpbb_feed_attachments_base_test extends phpbb_database_test_case +{ + protected $filesystem; + + /** @var \phpbb_feed_attachments_mock_feed */ + protected $attachments_mocks_feed; + + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__) . '/../extension/fixtures/extensions.xml'); + } + + public function setUp() + { + global $phpbb_root_path, $phpEx; + + $this->filesystem = new \phpbb\filesystem(); + $config = new \phpbb\config\config(array()); + $user = new \phpbb\user( + new \phpbb\language\language( + new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx) + ), + '\phpbb\datetime' + ); + $feed_helper = new \phpbb\feed\helper($config, $user, $phpbb_root_path, $phpEx); + $db = $this->new_dbal(); + $cache = new \phpbb_mock_cache(); + $auth = new \phpbb\auth\auth(); + $content_visibility = new \phpbb\content_visibility( + $auth, + $config, + new \phpbb_mock_event_dispatcher(), + $db, + $user, + $phpbb_root_path, + $phpEx, + FORUMS_TABLE, + POSTS_TABLE, + TOPICS_TABLE, + USERS_TABLE + ); + + $this->attachments_mocks_feed = new \phpbb_feed_attachments_mock_feed( + $feed_helper, + $config, + $db, + $cache, + $user, + $auth, + $content_visibility, + new \phpbb_mock_event_dispatcher(), + $phpEx + ); + } + + public function data_fetch_attachments() + { + return array( + array(array(0), array(0)), + array(array(), array(1)), + array(array(), array(), 'RuntimeException') + ); + } + + /** + * @dataProvider data_fetch_attachments + */ + public function test_fetch_attachments($post_ids, $topic_ids, $expected_exception = false) + { + $this->attachments_mocks_feed->post_ids = $post_ids; + $this->attachments_mocks_feed->topic_ids = $topic_ids; + + if ($expected_exception !== false) + { + $this->setExpectedException($expected_exception); + + $this->attachments_mocks_feed->get_sql(); + } + else + { + $this->assertTrue($this->attachments_mocks_feed->get_sql()); + } + } +} diff --git a/tests/feed/attachments_mock_feed.php b/tests/feed/attachments_mock_feed.php new file mode 100644 index 0000000000..fb67a48f7c --- /dev/null +++ b/tests/feed/attachments_mock_feed.php @@ -0,0 +1,36 @@ +<?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. + * + */ + +/** + * Board wide feed (aka overall feed) + * + * This will give you the newest {$this->num_items} posts + * from the whole board. + */ +class phpbb_feed_attachments_mock_feed extends \phpbb\feed\attachments_base +{ + public $topic_ids = array(); + public $post_ids = array(); + + function get_sql() + { + parent::fetch_attachments($this->post_ids, $this->topic_ids); + + return true; + } + + public function adjust_item(&$item_row, &$row) + { + return array(); + } +} diff --git a/tests/functional/acp_bbcodes_test.php b/tests/functional/acp_bbcodes_test.php new file mode 100644 index 0000000000..58681dfa07 --- /dev/null +++ b/tests/functional/acp_bbcodes_test.php @@ -0,0 +1,46 @@ +<?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_acp_bbcodes_test extends phpbb_functional_test_case +{ + public function test_htmlspecialchars() + { + $this->login(); + $this->admin_login(); + + // Create the BBCode + $crawler = self::request('GET', 'adm/index.php?i=acp_bbcodes&sid=' . $this->sid . '&mode=bbcodes&action=add'); + $form = $crawler->selectButton('Submit')->form(array( + 'bbcode_match' => '[mod="{TEXT1}"]{TEXT2}[/mod]', + 'bbcode_tpl' => '<div>{TEXT1}</div><div>{TEXT2}</div>' + )); + self::submit($form); + + // Test it in the "new topic" preview + $crawler = self::request('GET', 'posting.php?mode=post&f=2&sid=' . $this->sid); + $form = $crawler->selectButton('Preview')->form(array( + 'subject' => 'subject', + 'message' => '[mod=a]b[/mod][mod="c"]d[/mod]' + )); + $crawler = self::submit($form); + + $html = $crawler->filter('#preview')->html(); + $this->assertContains('<div>a</div>', $html); + $this->assertContains('<div>b</div>', $html); + $this->assertContains('<div>c</div>', $html); + $this->assertContains('<div>d</div>', $html); + } +} diff --git a/tests/functional/acp_smilies_test.php b/tests/functional/acp_smilies_test.php new file mode 100644 index 0000000000..ebe8717fa7 --- /dev/null +++ b/tests/functional/acp_smilies_test.php @@ -0,0 +1,43 @@ +<?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_acp_smilies_test extends phpbb_functional_test_case +{ + public function test_htmlspecialchars() + { + $this->login(); + $this->admin_login(); + + // Create the BBCode + $crawler = self::request('GET', 'adm/index.php?i=acp_icons&sid=' . $this->sid . '&mode=smilies&action=edit&id=1'); + $form = $crawler->selectButton('Submit')->form(array( + 'code[icon_e_biggrin.gif]' => '>:D', + 'emotion[icon_e_biggrin.gif]' => '>:D' + )); + self::submit($form); + + // Test it in the "new topic" preview + $crawler = self::request('GET', 'posting.php?mode=post&f=2&sid=' . $this->sid); + $form = $crawler->selectButton('Preview')->form(array( + 'subject' => 'subject', + 'message' => '>:D' + )); + $crawler = self::submit($form); + + $html = $crawler->filter('#preview')->html(); + $this->assertRegexp('(<img [^>]+ alt=">:D" title=">:D"[^>]*>)', $html); + } +} diff --git a/tests/functional/fileupload_remote_test.php b/tests/functional/fileupload_remote_test.php index b70d49cddd..88f8999005 100644 --- a/tests/functional/fileupload_remote_test.php +++ b/tests/functional/fileupload_remote_test.php @@ -100,8 +100,8 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case $upload = new \phpbb\files\upload($this->filesystem, $this->factory, $this->language, $this->php_ini, $this->request, $this->phpbb_root_path); $upload->set_error_prefix('') ->set_allowed_extensions(array('gif')) - ->set_max_filesize(1000); - $file = $upload->handle_upload('files.types.remote', self::$root_url . 'styles/prosilver/theme/images/forum_read.gif'); + ->set_max_filesize(2000); + $file = $upload->handle_upload('files.types.remote', self::$root_url . 'develop/test.gif'); $this->assertEquals(0, sizeof($file->error)); $this->assertTrue(file_exists($file->get('filename'))); $this->assertTrue($file->is_uploaded()); @@ -114,7 +114,7 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case $upload->set_error_prefix('') ->set_allowed_extensions(array('gif')) ->set_max_filesize(100); - $file = $upload->handle_upload('files.types.remote', self::$root_url . 'styles/prosilver/theme/images/forum_read.gif'); + $file = $upload->handle_upload('files.types.remote', self::$root_url . 'develop/test.gif'); $this->assertEquals(1, sizeof($file->error)); $this->assertEquals('WRONG_FILESIZE', $file->error[0]); } diff --git a/tests/functional/posting_test.php b/tests/functional/posting_test.php index 9dd8a1dc91..8e6328d1d3 100644 --- a/tests/functional/posting_test.php +++ b/tests/functional/posting_test.php @@ -87,6 +87,24 @@ class phpbb_functional_posting_test extends phpbb_functional_test_case } /** + * @see https://tracker.phpbb.com/browse/PHPBB3-14962 + */ + public function test_edit() + { + $this->login(); + $this->create_topic(2, 'Test Topic post', 'Test topic post'); + + $url = self::$client->getCrawler()->selectLink('Edit')->link()->getUri(); + $post_id = $this->get_parameter_from_link($url, 'p'); + $crawler = self::request('GET', "posting.php?mode=edit&f=2&p={$post_id}&sid={$this->sid}"); + $form = $crawler->selectButton('Submit')->form(); + $form->setValues(array('message' => 'Edited post')); + $crawler = self::submit($form); + + $this->assertContains('Edited post', $crawler->filter("#post_content{$post_id} .content")->text()); + } + + /** * @testdox max_quote_depth is applied to the text populating the posting form */ public function test_quote_depth_form() @@ -246,4 +264,45 @@ class phpbb_functional_posting_test extends phpbb_functional_test_case // Test that the preview contains the correct link $this->assertEquals($url, $crawler->filter('#preview a')->attr('href')); } + + public function test_allowed_schemes_links() + { + $text = 'http://example.org/ tcp://localhost:22/ServiceName'; + + $this->login(); + $this->admin_login(); + + // Post with default settings + $crawler = self::request('GET', 'posting.php?mode=post&f=2'); + $form = $crawler->selectButton('Preview')->form(array( + 'subject' => 'Test subject', + 'message' => $text, + )); + $crawler = self::submit($form); + $this->assertContains( + '<a href="http://example.org/" class="postlink">http://example.org/</a> tcp://localhost:22/ServiceName', + $crawler->filter('#preview .content')->html() + ); + + // Update allowed schemes + $crawler = self::request('GET', 'adm/index.php?sid=' . $this->sid . '&i=acp_board&mode=post'); + $form = $crawler->selectButton('Submit')->form(); + $values = $form->getValues(); + $values['config[allowed_schemes_links]'] = 'https,tcp'; + $form->setValues($values); + $crawler = self::submit($form); + $this->assertEquals(1, $crawler->filter('.successbox')->count()); + + // Post with new settings + $crawler = self::request('GET', 'posting.php?mode=post&f=2'); + $form = $crawler->selectButton('Preview')->form(array( + 'subject' => 'Test subject', + 'message' => $text, + )); + $crawler = self::submit($form); + $this->assertContains( + 'http://example.org/ <a href="tcp://localhost:22/ServiceName" class="postlink">tcp://localhost:22/ServiceName</a>', + $crawler->filter('#preview .content')->html() + ); + } } diff --git a/tests/functional/visibility_softdelete_test.php b/tests/functional/visibility_softdelete_test.php index 39efc99a35..6450c00c1e 100644 --- a/tests/functional/visibility_softdelete_test.php +++ b/tests/functional/visibility_softdelete_test.php @@ -564,7 +564,7 @@ class phpbb_functional_visibility_softdelete_test extends phpbb_functional_test_ $this->assertContainsLang('SPLIT_TOPIC_EXPLAIN', $crawler->text()); $form = $crawler->selectButton('Submit')->form(array( - 'subject' => 'Soft Delete Topic #2', + 'subject' => 'Soft Delete Topic #2 with bang', )); $form['to_forum_id']->select($this->data['forums']['Soft Delete #2']); $form['post_id_list'][1]->tick(); @@ -597,6 +597,11 @@ class phpbb_functional_visibility_softdelete_test extends phpbb_functional_test_ 'forum_topics_softdeleted' => 1, 'forum_last_post_id' => 0, ), 'after restoring #2'); + + // Assert new topic title is indexed as well + $this->add_lang('search'); + self::request('GET', "search.php?keywords=bang&sid={$this->sid}"); + $this->assertContains(sprintf($this->lang['FOUND_SEARCH_MATCHES'][1], 1), self::get_content()); } public function test_move_topic_back() @@ -609,7 +614,7 @@ class phpbb_functional_visibility_softdelete_test extends phpbb_functional_test_ ), 'topics' => array( 'Soft Delete Topic #1', - 'Soft Delete Topic #2', + 'Soft Delete Topic #2 with bang', ), 'posts' => array( 'Soft Delete Topic #1', @@ -618,7 +623,7 @@ class phpbb_functional_visibility_softdelete_test extends phpbb_functional_test_ ), )); - $crawler = $this->get_quickmod_page($this->data['topics']['Soft Delete Topic #2'], 'MOVE_TOPIC'); + $crawler = $this->get_quickmod_page($this->data['topics']['Soft Delete Topic #2 with bang'], 'MOVE_TOPIC'); $form = $crawler->selectButton('Yes')->form(); $form['to_forum_id']->select($this->data['forums']['Soft Delete #1']); $crawler = self::submit($form); @@ -644,7 +649,7 @@ class phpbb_functional_visibility_softdelete_test extends phpbb_functional_test_ ), 'topics' => array( 'Soft Delete Topic #1', - 'Soft Delete Topic #2', + 'Soft Delete Topic #2 with bang', ), 'posts' => array( 'Soft Delete Topic #1', @@ -664,7 +669,7 @@ class phpbb_functional_visibility_softdelete_test extends phpbb_functional_test_ ), 'before merging #1'); $this->add_lang('viewtopic'); - $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Soft Delete Topic #2']}&sid={$this->sid}"); + $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Soft Delete Topic #2 with bang']}&sid={$this->sid}"); $bookmark_tag = $crawler->filter('a.bookmark-link'); $this->assertContainsLang('BOOKMARK_TOPIC', $bookmark_tag->text()); @@ -673,10 +678,10 @@ class phpbb_functional_visibility_softdelete_test extends phpbb_functional_test_ $this->assertContainsLang('BOOKMARK_ADDED', $crawler_bookmark->text()); $this->add_lang('mcp'); - $crawler = $this->get_quickmod_page($this->data['topics']['Soft Delete Topic #2'], 'MERGE_TOPIC', $crawler); + $crawler = $this->get_quickmod_page($this->data['topics']['Soft Delete Topic #2 with bang'], 'MERGE_TOPIC', $crawler); $this->assertContainsLang('SELECT_MERGE', $crawler->text()); - $crawler = self::request('GET', "mcp.php?f={$this->data['forums']['Soft Delete #1']}&t={$this->data['topics']['Soft Delete Topic #2']}&i=main&mode=forum_view&action=merge_topic&to_topic_id={$this->data['topics']['Soft Delete Topic #1']}"); + $crawler = self::request('GET', "mcp.php?f={$this->data['forums']['Soft Delete #1']}&t={$this->data['topics']['Soft Delete Topic #2 with bang']}&i=main&mode=forum_view&action=merge_topic&to_topic_id={$this->data['topics']['Soft Delete Topic #1']}"); $this->assertContainsLang('MERGE_TOPICS_CONFIRM', $crawler->text()); $form = $crawler->selectButton('Yes')->form(); diff --git a/tests/functions_privmsgs/get_max_setting_from_group_test.php b/tests/functions_privmsgs/get_max_setting_from_group_test.php index 3eb7866802..fbabf1222a 100644 --- a/tests/functions_privmsgs/get_max_setting_from_group_test.php +++ b/tests/functions_privmsgs/get_max_setting_from_group_test.php @@ -33,12 +33,12 @@ class phpbb_functions_privmsgs_get_max_setting_from_group_test extends phpbb_dat static public function get_max_setting_from_group_data() { return array( - array(1, 0, 'message_limit'), + array(1, 2, 'message_limit'), array(2, 2, 'message_limit'), array(3, 0, 'message_limit'), array(4, 0, 'message_limit'), array(5, 2, 'message_limit'), - array(1, 0, 'max_recipients'), + array(1, 4, 'max_recipients'), array(2, 4, 'max_recipients'), array(3, 0, 'max_recipients'), array(4, 5, 'max_recipients'), diff --git a/tests/mcp/fixtures/post_ip.xml b/tests/mcp/fixtures/post_ip.xml new file mode 100644 index 0000000000..fad2193396 --- /dev/null +++ b/tests/mcp/fixtures/post_ip.xml @@ -0,0 +1,73 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> + <table name="phpbb_posts"> + <column>post_id</column> + <column>poster_id</column> + <column>post_edit_user</column> + <column>post_delete_user</column> + <column>post_username</column> + <column>topic_id</column> + <column>forum_id</column> + <column>post_visibility</column> + <column>post_time</column> + <column>post_text</column> + <column>post_reported</column> + <column>poster_ip</column> + <row> + <value>1</value> + <value>2</value> + <value>2</value> + <value>2</value> + <value></value> + <value>1</value> + <value>1</value> + <value>1</value> + <value>1</value> + <value></value> + <value>1</value> + <value>127.0.0.1</value> + </row> + <row> + <value>2</value> + <value>1</value> + <value>1</value> + <value>1</value> + <value>Other</value> + <value>2</value> + <value>2</value> + <value>1</value> + <value>1</value> + <value></value> + <value>1</value> + <value>127.0.0.2</value> + </row> + <row> + <value>3</value> + <value>2</value> + <value>2</value> + <value>2</value> + <value></value> + <value>3</value> + <value>3</value> + <value>1</value> + <value>1</value> + <value></value> + <value>1</value> + <value>127.0.0.3</value> + </row> + <row> + <value>4</value> + <value>1</value> + <value>1</value> + <value>1</value> + <value>Other</value> + <value>4</value> + <value>4</value> + <value>1</value> + <value>1</value> + <value></value> + <value>1</value> + <value>127.0.0.1</value> + </row> + </table> +</dataset> diff --git a/tests/mcp/post_ip_test.php b/tests/mcp/post_ip_test.php new file mode 100644 index 0000000000..72a9f62774 --- /dev/null +++ b/tests/mcp/post_ip_test.php @@ -0,0 +1,67 @@ +<?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__) . '/../../phpBB/includes/mcp/mcp_post.php'; + +class phpbb_mcp_post_ip_test extends phpbb_database_test_case +{ + /** @var \phpbb\db\driver\driver_interface */ + protected $db; + + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/post_ip.xml'); + } + + protected function setUp() + { + parent::setUp(); + + $this->db = $this->new_dbal(); + } + + public function data_get_num_ips() + { + return array( + array(2, 1), + array(2, 2), + array(0, 3), + ); + } + + /** + * @dataProvider data_get_num_ips + */ + public function test_get_num_ips($expected, $poster_id) + { + $this->assertSame($expected, phpbb_get_num_ips_for_poster($this->db, $poster_id)); + } + + public function data_get_num_posters() + { + return array( + array(2, '127.0.0.1'), + array(1, '127.0.0.2'), + array(1, '127.0.0.3'), + array(0, '127.0.0.4'), + ); + } + + /** + * @dataProvider data_get_num_posters + */ + public function test_get_num_posters($expected, $ip) + { + $this->assertSame($expected, phpbb_get_num_posters_for_ip($this->db, $ip)); + } +} diff --git a/tests/mock/extension_manager.php b/tests/mock/extension_manager.php index 2ce61c5149..0d6d110647 100644 --- a/tests/mock/extension_manager.php +++ b/tests/mock/extension_manager.php @@ -15,10 +15,15 @@ class phpbb_mock_extension_manager extends \phpbb\extension\manager { public function __construct($phpbb_root_path, $extensions = array(), $container = null) { + global $phpEx; + + $lang = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)); $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = 'php'; $this->extensions = $extensions; $this->filesystem = new \phpbb\filesystem\filesystem(); $this->container = $container; + $this->config = new \phpbb\config\config(array()); + $this->user = new \phpbb\user($lang,'\phpbb\datetime'); } } diff --git a/tests/mock/phpbb_di_container_builder.php b/tests/mock/phpbb_di_container_builder.php index 23dc3d1e8b..c78b41d8ec 100644 --- a/tests/mock/phpbb_di_container_builder.php +++ b/tests/mock/phpbb_di_container_builder.php @@ -27,4 +27,12 @@ class phpbb_mock_phpbb_di_container_builder extends \phpbb\di\container_builder { return $this->phpbb_root_path . '../../tmp/autoload.' . $this->php_ext; } + + /** + * {@inheritdoc} + */ + protected function inject_dbal_driver() + { + return; + } } diff --git a/tests/pagination/pagination_test.php b/tests/pagination/pagination_test.php index 30b25913f7..2d7d1671a8 100644 --- a/tests/pagination/pagination_test.php +++ b/tests/pagination/pagination_test.php @@ -219,6 +219,12 @@ class phpbb_pagination_pagination_test extends phpbb_template_template_test_case 0, 'PAGE_OF-1-1', ), + array( + '10', + '10', + '0', + 'PAGE_OF-1-1', + ), ); } diff --git a/tests/template/template_allfolder_test.php b/tests/template/template_allfolder_test.php index 9a0a42fabd..63a6ef08ea 100644 --- a/tests/template/template_allfolder_test.php +++ b/tests/template/template_allfolder_test.php @@ -67,6 +67,7 @@ class phpbb_template_allfolder_test extends phpbb_template_template_test_case $cache_path, $this->extension_manager, $loader, + new \phpbb\event\dispatcher($container), array( 'cache' => false, 'debug' => false, diff --git a/tests/template/template_events_test.php b/tests/template/template_events_test.php index e245c90aee..3a93c91e11 100644 --- a/tests/template/template_events_test.php +++ b/tests/template/template_events_test.php @@ -161,6 +161,7 @@ Zeta test event in all', $cache_path, $this->extension_manager, $loader, + new \phpbb\event\dispatcher($container), array( 'cache' => false, 'debug' => false, diff --git a/tests/template/template_includecss_test.php b/tests/template/template_includecss_test.php index 764652c9c2..bc871aa612 100644 --- a/tests/template/template_includecss_test.php +++ b/tests/template/template_includecss_test.php @@ -53,6 +53,7 @@ class phpbb_template_template_includecss_test extends phpbb_template_template_te $cache_path, null, $loader, + new \phpbb\event\dispatcher($container), array( 'cache' => false, 'debug' => false, diff --git a/tests/template/template_test.php b/tests/template/template_test.php index 63e7cb869a..f86572cae8 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -558,7 +558,7 @@ class phpbb_template_template_test extends phpbb_template_template_test_case $this->template->assign_display('test', 'VARIABLE', false); - $this->assertEquals("pass\npass\npass\n<!-- DUMMY var -->", $this->display('container'), "Testing assign_display($file)"); + $this->assertEquals("pass\npass\npass\n<!-- DUMMY var -->", $this->display('container'), "Testing assign_display(\$file)"); } public function test_append_var_without_assign_var() @@ -680,22 +680,139 @@ EOT ), array( 'outer', + array('VARIABLE' => 'changed'), + 0, + 'change', + <<<EOT +outer - 0 - changed +middle - 0 +middle - 1 +outer - 1 +middle - 0 +middle - 1 +outer - 2 +middle - 0 +middle - 1 +EOT +, + 'Test changing at 0 on top level block', + ), + array( + 'outer', + array('VARIABLE' => 'changed'), + array('S_ROW_NUM' => 2), + 'change', + <<<EOT +outer - 0 +middle - 0 +middle - 1 +outer - 1 +middle - 0 +middle - 1 +outer - 2 - changed +middle - 0 +middle - 1 +EOT +, + 'Test changing at KEY on top level block', + ), + array( + 'outer.middle', + array('VARIABLE' => 'before'), + false, + 'insert', + <<<EOT +outer - 0 +middle - 0 +middle - 1 +outer - 1 +middle - 0 +middle - 1 +outer - 2 +middle - 0 - before +middle - 1 +middle - 2 +EOT +, + 'Test inserting before on middle level block', + ), + array( + 'outer.middle', + array('VARIABLE' => 'after'), + true, + 'insert', + <<<EOT +outer - 0 +middle - 0 +middle - 1 +outer - 1 +middle - 0 +middle - 1 +outer - 2 +middle - 0 +middle - 1 +middle - 2 - after +EOT +, + 'Test inserting after on middle level block', + ), + array( + 'outer[1].middle', array('VARIABLE' => 'pos #1'), + 1, + 'insert', + <<<EOT +outer - 0 +middle - 0 +middle - 1 +outer - 1 +middle - 0 +middle - 1 - pos #1 +middle - 2 +outer - 2 +middle - 0 +middle - 1 +EOT +, + 'Test inserting at 1 on middle level block', + ), + array( + 'outer[].middle', + array('VARIABLE' => 'changed'), 0, 'change', <<<EOT -outer - 0 - pos #1 +outer - 0 middle - 0 middle - 1 outer - 1 middle - 0 middle - 1 outer - 2 +middle - 0 - changed +middle - 1 +EOT +, + 'Test changing at beginning of last top level block', + ), + array( + 'outer.middle', + array('VARIABLE' => 'changed'), + array('S_ROW_NUM' => 1), + 'change', + <<<EOT +outer - 0 +middle - 0 +middle - 1 +outer - 1 middle - 0 middle - 1 +outer - 2 +middle - 0 +middle - 1 - changed EOT , - 'Test inserting at 1 on top level block', + 'Test changing at beginning of last top level block', ), ); } @@ -753,8 +870,104 @@ EOT $expect = 'outer - 0[outer|4]outer - 1[outer|4]middle - 0[middle|1]outer - 2 - test[outer|4]middle - 0[middle|2]middle - 1[middle|2]outer - 3[outer|4]middle - 0[middle|3]middle - 1[middle|3]middle - 2[middle|3]'; $this->assertEquals($expect, str_replace(array("\n", "\r", "\t"), '', $this->display('test')), 'Ensuring S_NUM_ROWS is correct after modification'); + + $this->template->alter_block_array('outer.middle', array()); + + $expect = 'outer - 0[outer|4]outer - 1[outer|4]middle - 0[middle|1]outer - 2 - test[outer|4]middle - 0[middle|2]middle - 1[middle|2]outer - 3[outer|4]middle - 0[middle|4]middle - 1[middle|4]middle - 2[middle|4]middle - 3[middle|4]'; + $this->assertEquals($expect, str_replace(array("\n", "\r", "\t"), '', $this->display('test')), 'Ensuring S_NUM_ROWS is correct after insertion at middle level'); + + $this->template->alter_block_array('outer.middle', array('VARIABLE' => 'test'), 2, 'change'); + + $expect = 'outer - 0[outer|4]outer - 1[outer|4]middle - 0[middle|1]outer - 2 - test[outer|4]middle - 0[middle|2]middle - 1[middle|2]outer - 3[outer|4]middle - 0[middle|4]middle - 1[middle|4]middle - 2 - test[middle|4]middle - 3[middle|4]'; + $this->assertEquals($expect, str_replace(array("\n", "\r", "\t"), '', $this->display('test')), 'Ensuring S_NUM_ROWS is correct after modification at middle level'); } + public function test_find_key_index() + { + $this->template->set_filenames(array('test' => 'loop_nested.html')); + + $this->template->assign_var('TEST_MORE', true); + + // @todo Change this + $this->template->assign_block_vars('outer', array('VARIABLE' => 'zero')); + $this->template->assign_block_vars('outer', array('VARIABLE' => 'one')); + $this->template->assign_block_vars('outer.middle', array('VARIABLE' => '1A')); + $this->template->assign_block_vars('outer', array('VARIABLE' => 'two')); + $this->template->assign_block_vars('outer.middle', array('VARIABLE' => '2A')); + $this->template->assign_block_vars('outer.middle', array('VARIABLE' => '2B')); + $this->template->assign_block_vars('outer', array('VARIABLE' => 'three')); + $this->template->assign_block_vars('outer.middle', array('VARIABLE' => '3A')); + $this->template->assign_block_vars('outer.middle', array('VARIABLE' => '3B')); + $this->template->assign_block_vars('outer.middle', array('VARIABLE' => '3C')); + + $expect = 'outer - 0 - zero[outer|4]outer - 1 - one[outer|4]middle - 0 - 1A[middle|1]outer - 2 - two[outer|4]middle - 0 - 2A[middle|2]middle - 1 - 2B[middle|2]outer - 3 - three[outer|4]middle - 0 - 3A[middle|3]middle - 1 - 3B[middle|3]middle - 2 - 3C[middle|3]'; + $this->assertEquals($expect, str_replace(array("\n", "\r", "\t"), '', $this->display('test')), 'Ensuring template is built correctly before modification'); + + $this->template->find_key_index('outer', false); + + $this->assertEquals(0, $this->template->find_key_index('outer', false), 'Find index at the beginning of outer loop'); + $this->assertEquals(1, $this->template->find_key_index('outer', 1), 'Find index by index in outer loop'); + $this->assertEquals(2, $this->template->find_key_index('outer', array('VARIABLE' => 'two')), 'Find index by key in outer loop'); + $this->assertEquals(3, $this->template->find_key_index('outer', true), 'Find index at the end of outer loop'); + $this->assertEquals(false, $this->template->find_key_index('outer', 7), 'Find index out of bounds of outer loop'); + + $this->assertEquals(false, $this->template->find_key_index('outer[0].middle', false), 'Find index at the beginning of middle loop, no middle block'); + $this->assertEquals(false, $this->template->find_key_index('outer[1].middle', 1), 'Find index by index in inner loop, out of bounds'); + $this->assertEquals(1, $this->template->find_key_index('outer[2].middle', array('VARIABLE' => '2B')), 'Find index by key in middle loop'); + $this->assertEquals(2, $this->template->find_key_index('outer.middle', true), 'Find index at the end of middle loop'); + + $this->assertEquals(false, $this->template->find_key_index('outer.wrong', true), 'Wrong middle block name'); + $this->assertEquals(false, $this->template->find_key_index('wrong.middle', false), 'Wrong outer block name'); + } + + public function test_delete_alter_block_array() + { + $this->template->set_filenames(array('test' => 'loop_nested.html')); + + $this->template->assign_var('TEST_MORE', true); + + // @todo Change this + $this->template->assign_block_vars('outer', array('VARIABLE' => 'zero')); + $this->template->assign_block_vars('outer', array('VARIABLE' => 'one')); + $this->template->assign_block_vars('outer.middle', array('VARIABLE' => '1A')); + $this->template->assign_block_vars('outer', array('VARIABLE' => 'two')); + $this->template->assign_block_vars('outer.middle', array('VARIABLE' => '2A')); + $this->template->assign_block_vars('outer.middle', array('VARIABLE' => '2B')); + $this->template->assign_block_vars('outer', array('VARIABLE' => 'three')); + $this->template->assign_block_vars('outer.middle', array('VARIABLE' => '3A')); + $this->template->assign_block_vars('outer.middle', array('VARIABLE' => '3B')); + $this->template->assign_block_vars('outer.middle', array('VARIABLE' => '3C')); + + $expect = 'outer - 0 - zero[outer|4]outer - 1 - one[outer|4]middle - 0 - 1A[middle|1]outer - 2 - two[outer|4]middle - 0 - 2A[middle|2]middle - 1 - 2B[middle|2]outer - 3 - three[outer|4]middle - 0 - 3A[middle|3]middle - 1 - 3B[middle|3]middle - 2 - 3C[middle|3]'; + $this->assertEquals($expect, str_replace(array("\n", "\r", "\t"), '', $this->display('test')), 'Ensuring template is built correctly before modification'); + + $this->template->alter_block_array('outer', array(), false, 'delete'); + + $expect = 'outer - 0 - one[outer|3]middle - 0 - 1A[middle|1]outer - 1 - two[outer|3]middle - 0 - 2A[middle|2]middle - 1 - 2B[middle|2]outer - 2 - three[outer|3]middle - 0 - 3A[middle|3]middle - 1 - 3B[middle|3]middle - 2 - 3C[middle|3]'; + $this->assertEquals($expect, str_replace(array("\n", "\r", "\t"), '', $this->display('test')), 'Deleting at the beginning of outer loop'); + + $this->template->alter_block_array('outer[0].middle', array(), true, 'delete'); + + $expect = 'outer - 0 - one[outer|3]outer - 1 - two[outer|3]middle - 0 - 2A[middle|2]middle - 1 - 2B[middle|2]outer - 2 - three[outer|3]middle - 0 - 3A[middle|3]middle - 1 - 3B[middle|3]middle - 2 - 3C[middle|3]'; + $this->assertEquals($expect, str_replace(array("\n", "\r", "\t"), '', $this->display('test')), 'Deleting at the end of first middle loop, delete complete loop'); + + $this->template->alter_block_array('outer', array(), 1, 'delete'); + + $expect = 'outer - 0 - one[outer|2]outer - 1 - three[outer|2]middle - 0 - 3A[middle|3]middle - 1 - 3B[middle|3]middle - 2 - 3C[middle|3]'; + $this->assertEquals($expect, str_replace(array("\n", "\r", "\t"), '', $this->display('test')), 'Deleting by index at top level'); + + $this->template->alter_block_array('outer.middle', array(), 1, 'delete'); + + $expect = 'outer - 0 - one[outer|2]outer - 1 - three[outer|2]middle - 0 - 3A[middle|2]middle - 1 - 3C[middle|2]'; + $this->assertEquals($expect, str_replace(array("\n", "\r", "\t"), '', $this->display('test')), 'Deleting by index at middle level'); + + $this->template->alter_block_array('outer', array(), 4, 'delete'); + + $expect = 'outer - 0 - one[outer|2]outer - 1 - three[outer|2]middle - 0 - 3A[middle|2]middle - 1 - 3C[middle|2]'; + $this->assertEquals($expect, str_replace(array("\n", "\r", "\t"), '', $this->display('test')), 'Deleting by index out of bounds, ignored'); + } + + public function assign_block_vars_array_data() { return array( diff --git a/tests/template/template_test_case.php b/tests/template/template_test_case.php index e52d3b76dd..8adbafb1b2 100644 --- a/tests/template/template_test_case.php +++ b/tests/template/template_test_case.php @@ -105,6 +105,7 @@ class phpbb_template_template_test_case extends phpbb_test_case $cache_path, null, $loader, + new \phpbb\event\dispatcher($container), array( 'cache' => false, 'debug' => false, diff --git a/tests/template/template_test_case_with_tree.php b/tests/template/template_test_case_with_tree.php index ff35d16120..75e3918f44 100644 --- a/tests/template/template_test_case_with_tree.php +++ b/tests/template/template_test_case_with_tree.php @@ -48,6 +48,7 @@ class phpbb_template_template_test_case_with_tree extends phpbb_template_templat $cache_path, null, $loader, + new \phpbb\event\dispatcher($container), array( 'cache' => false, 'debug' => false, diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index d5e78d1d60..eb56049515 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -291,6 +291,13 @@ class phpbb_functional_test_case extends phpbb_test_case } } + $install_config_file = $phpbb_root_path . 'store/install_config.php'; + + if (file_exists($install_config_file)) + { + unlink($install_config_file); + } + $container_builder = new \phpbb\di\container_builder($phpbb_root_path, $phpEx); $container = $container_builder ->with_environment('installer') @@ -304,6 +311,7 @@ class phpbb_functional_test_case extends phpbb_test_case ], 'cache.driver.class' => 'phpbb\cache\driver\file' ]) + ->with_config(new \phpbb\config_php_file($phpbb_root_path, $phpEx)) ->without_compiled_container() ->get_container(); diff --git a/tests/test_framework/phpbb_ui_test_case.php b/tests/test_framework/phpbb_ui_test_case.php index e3f636679c..b875d3212b 100644 --- a/tests/test_framework/phpbb_ui_test_case.php +++ b/tests/test_framework/phpbb_ui_test_case.php @@ -78,14 +78,11 @@ class phpbb_ui_test_case extends phpbb_test_case self::markTestSkipped('phpbb_functional_url was not set in test_config and wasn\'t set as PHPBB_FUNCTIONAL_URL environment variable either.'); } - if (!self::$webDriver) - { - try { - $capabilities = DesiredCapabilities::firefox(); - self::$webDriver = RemoteWebDriver::create(self::$host . ':' . self::$port, $capabilities); - } catch (WebDriverCurlException $e) { - self::markTestSkipped('PhantomJS webserver is not running.'); - } + try { + $capabilities = DesiredCapabilities::firefox(); + self::$webDriver = RemoteWebDriver::create(self::$host . ':' . self::$port, $capabilities); + } catch (WebDriverCurlException $e) { + self::markTestSkipped('PhantomJS webserver is not running.'); } if (!self::$already_installed) @@ -146,9 +143,14 @@ class phpbb_ui_test_case extends phpbb_test_case } } - static public function visit($path) + public function getDriver() + { + return self::$webDriver; + } + + public function visit($path) { - self::$webDriver->get(self::$root_url . $path); + $this->getDriver()->get(self::$root_url . $path); } static protected function recreate_database($config) @@ -157,14 +159,14 @@ class phpbb_ui_test_case extends phpbb_test_case $db_conn_mgr->recreate_db(); } - static public function find_element($type, $value) + public function find_element($type, $value) { - return self::$webDriver->findElement(WebDriverBy::$type($value)); + return $this->getDriver()->findElement(WebDriverBy::$type($value)); } - static public function submit($type = 'id', $value = 'submit') + public function submit($type = 'id', $value = 'submit') { - $element = self::find_element($type, $value); + $element = $this->find_element($type, $value); $element->click(); } @@ -305,21 +307,21 @@ class phpbb_ui_test_case extends phpbb_test_case $ext_path = str_replace('/', '%2F', $extension); $this->visit('adm/index.php?i=acp_extensions&mode=main&action=enable_pre&ext_name=' . $ext_path . '&sid=' . $this->sid); - $this->assertNotEmpty(count(self::find_element('cssSelector', '.submit-buttons'))); + $this->assertNotEmpty(count($this->find_element('cssSelector', '.submit-buttons'))); - self::find_element('cssSelector', "input[value='Enable']")->submit(); + $this->find_element('cssSelector', "input[value='Enable']")->submit(); $this->add_lang('acp/extensions'); try { - $meta_refresh = self::find_element('cssSelector', 'meta[http-equiv="refresh"]'); + $meta_refresh = $this->find_element('cssSelector', 'meta[http-equiv="refresh"]'); // Wait for extension to be fully enabled while (sizeof($meta_refresh)) { preg_match('#url=.+/(adm+.+)#', $meta_refresh->getAttribute('content'), $match); - self::$webDriver->execute(array('method' => 'post', 'url' => $match[1])); - $meta_refresh = self::find_element('cssSelector', 'meta[http-equiv="refresh"]'); + $this->getDriver()->execute(array('method' => 'post', 'url' => $match[1])); + $meta_refresh = $this->find_element('cssSelector', 'meta[http-equiv="refresh"]'); } } catch (\Facebook\WebDriver\Exception\NoSuchElementException $e) @@ -327,7 +329,7 @@ class phpbb_ui_test_case extends phpbb_test_case // Probably no refresh triggered } - $this->assertContainsLang('EXTENSION_ENABLE_SUCCESS', self::find_element('cssSelector', 'div.successbox')->getText()); + $this->assertContainsLang('EXTENSION_ENABLE_SUCCESS', $this->find_element('cssSelector', 'div.successbox')->getText()); $this->logout(); } @@ -415,7 +417,7 @@ class phpbb_ui_test_case extends phpbb_test_case } $this->visit('ucp.php?sid=' . $this->sid . '&mode=logout'); - $this->assertContains($this->lang('REGISTER'), self::$webDriver->getPageSource()); + $this->assertContains($this->lang('REGISTER'), $this->getDriver()->getPageSource()); unset($this->sid); } @@ -435,17 +437,17 @@ class phpbb_ui_test_case extends phpbb_test_case return; } - self::$webDriver->manage()->deleteAllCookies(); + $this->getDriver()->manage()->deleteAllCookies(); $this->visit('adm/index.php?sid=' . $this->sid); - $this->assertContains($this->lang('LOGIN_ADMIN_CONFIRM'), self::$webDriver->getPageSource()); + $this->assertContains($this->lang('LOGIN_ADMIN_CONFIRM'), $this->getDriver()->getPageSource()); - self::find_element('cssSelector', 'input[name=username]')->clear()->sendKeys($username); - self::find_element('cssSelector', 'input[type=password]')->sendKeys($username . $username); - self::find_element('cssSelector', 'input[name=login]')->click(); + $this->find_element('cssSelector', 'input[name=username]')->clear()->sendKeys($username); + $this->find_element('cssSelector', 'input[type=password]')->sendKeys($username . $username); + $this->find_element('cssSelector', 'input[name=login]')->click(); $this->assertContains($this->lang('ADMIN_PANEL'), $this->find_element('cssSelector', 'h1')->getText()); - $cookies = self::$webDriver->manage()->getCookies(); + $cookies = $this->getDriver()->manage()->getCookies(); // The session id is stored in a cookie that ends with _sid - we assume there is only one such cookie foreach ($cookies as $cookie) @@ -550,19 +552,19 @@ class phpbb_ui_test_case extends phpbb_test_case { $this->add_lang('ucp'); - self::$webDriver->manage()->deleteAllCookies(); + $this->getDriver()->manage()->deleteAllCookies(); $this->visit('ucp.php'); - $this->assertContains($this->lang('LOGIN_EXPLAIN_UCP'), self::$webDriver->getPageSource()); + $this->assertContains($this->lang('LOGIN_EXPLAIN_UCP'), $this->getDriver()->getPageSource()); - self::$webDriver->manage()->deleteAllCookies(); + $this->getDriver()->manage()->deleteAllCookies(); - self::find_element('cssSelector', 'input[name=username]')->sendKeys($username); - self::find_element('cssSelector', 'input[name=password]')->sendKeys($username . $username); - self::find_element('cssSelector', 'input[name=login]')->click(); + $this->find_element('cssSelector', 'input[name=username]')->sendKeys($username); + $this->find_element('cssSelector', 'input[name=password]')->sendKeys($username . $username); + $this->find_element('cssSelector', 'input[name=login]')->click(); $this->assertNotContains($this->lang('LOGIN'), $this->find_element('className', 'navbar')->getText()); - $cookies = self::$webDriver->manage()->getCookies(); + $cookies = $this->getDriver()->manage()->getCookies(); // The session id is stored in a cookie that ends with _sid - we assume there is only one such cookie foreach ($cookies as $cookie) @@ -586,6 +588,6 @@ class phpbb_ui_test_case extends phpbb_test_case // Change the Path to your own settings $screenshot = time() . ".png"; - self::$webDriver->takeScreenshot($screenshot); + $this->getDriver()->takeScreenshot($screenshot); } } diff --git a/tests/text_formatter/s9e/default_formatting_test.php b/tests/text_formatter/s9e/default_formatting_test.php index e25c3246b5..a0c57214e4 100644 --- a/tests/text_formatter/s9e/default_formatting_test.php +++ b/tests/text_formatter/s9e/default_formatting_test.php @@ -298,7 +298,7 @@ class phpbb_textformatter_s9e_default_formatting_test extends phpbb_test_case ), array( "Emoji: \xF0\x9F\x98\x80", - 'Emoji: <img alt="' . "\xF0\x9F\x98\x80" . '" class="smilies" draggable="false" width="18" height="18" src="//cdn.jsdelivr.net/emojione/assets/svg/1f600.svg">' + 'Emoji: <img alt="' . "\xF0\x9F\x98\x80" . '" class="emoji smilies" draggable="false" src="//cdn.jsdelivr.net/emojione/assets/svg/1f600.svg">' ), array( "Emoji: \xF0\x9F\x98\x80", diff --git a/tests/text_processing/generate_text_for_display_test.php b/tests/text_processing/generate_text_for_display_test.php index b8b5b18561..9c7152a008 100644 --- a/tests/text_processing/generate_text_for_display_test.php +++ b/tests/text_processing/generate_text_for_display_test.php @@ -100,7 +100,7 @@ class phpbb_text_processing_generate_text_for_display_test extends phpbb_test_ca $renderer->set_viewcensors(false); $this->assertSame('apple', $renderer->render($original)); - $this->assertSame('banana', generate_text_for_display($original, '', '', 0, truee)); + $this->assertSame('banana', generate_text_for_display($original, '', '', 0, true)); $this->assertSame('apple', $renderer->render($original), 'The original setting was not restored'); } diff --git a/tests/text_processing/tickets_data/PHPBB3-14790.html b/tests/text_processing/tickets_data/PHPBB3-14790.html new file mode 100644 index 0000000000..7624b2d36c --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-14790.html @@ -0,0 +1,4 @@ +<span style="color: #0000FF"></span><ul><li><span style="color: #0000FF">text</span></li> +<li><span style="color: #0000FF">text</span></li> +<li><span style="color: #0000FF">text</span></li> +<li><span style="color: #0000FF">text</span></li></ul>
\ No newline at end of file diff --git a/tests/text_processing/tickets_data/PHPBB3-14790.txt b/tests/text_processing/tickets_data/PHPBB3-14790.txt new file mode 100644 index 0000000000..1cd83d97d8 --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-14790.txt @@ -0,0 +1,4 @@ +[color=#0000FF][list][*]text +[*]text +[*]text +[*]text[/list][/color]
\ No newline at end of file diff --git a/tests/text_processing/tickets_data/PHPBB3-15008.before.php b/tests/text_processing/tickets_data/PHPBB3-15008.before.php new file mode 100644 index 0000000000..a3243e74cd --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-15008.before.php @@ -0,0 +1,18 @@ +<?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. +* +*/ + +function before_assert_phpbb3_15008($vars) +{ + extract($vars); + $parser->disable_smilies(); +} diff --git a/tests/text_processing/tickets_data/PHPBB3-15008.html b/tests/text_processing/tickets_data/PHPBB3-15008.html new file mode 100644 index 0000000000..7642eb63ee --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-15008.html @@ -0,0 +1 @@ +No smilies :) or shortnames :strawberry:
\ No newline at end of file diff --git a/tests/text_processing/tickets_data/PHPBB3-15008.txt b/tests/text_processing/tickets_data/PHPBB3-15008.txt new file mode 100644 index 0000000000..7642eb63ee --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-15008.txt @@ -0,0 +1 @@ +No smilies :) or shortnames :strawberry:
\ No newline at end of file diff --git a/tests/text_processing/tickets_data/PHPBB3-15016.html b/tests/text_processing/tickets_data/PHPBB3-15016.html new file mode 100644 index 0000000000..47b66ad771 --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-15016.html @@ -0,0 +1 @@ +<img class="smilies" src="phpBB/images/smilies/icon_lol.gif" width="15" height="17" alt=")--(" title=")--("> <img class="smilies" src="phpBB/images/smilies/icon_lol.gif" width="15" height="17" alt=")-(" title=")-("> <img class="smilies" src="phpBB/images/smilies/icon_lol.gif" width="15" height="17" alt=")--" title=")--">
\ No newline at end of file diff --git a/tests/text_processing/tickets_data/PHPBB3-15016.txt b/tests/text_processing/tickets_data/PHPBB3-15016.txt new file mode 100644 index 0000000000..081d9e3dc9 --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-15016.txt @@ -0,0 +1 @@ +)--( )-( )--
\ No newline at end of file diff --git a/tests/text_processing/tickets_data/PHPBB3-15016.xml b/tests/text_processing/tickets_data/PHPBB3-15016.xml new file mode 100644 index 0000000000..644481861e --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-15016.xml @@ -0,0 +1,43 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> + <table name="phpbb_smilies"> + <column>smiley_id</column> + <column>code</column> + <column>emotion</column> + <column>smiley_url</column> + <column>smiley_width</column> + <column>smiley_height</column> + <column>smiley_order</column> + <column>display_on_posting</column> + <row> + <value>1</value> + <value>)--(</value> + <value>)--(</value> + <value>icon_lol.gif</value> + <value>15</value> + <value>17</value> + <value>22</value> + <value>1</value> + </row> + <row> + <value>2</value> + <value>)--</value> + <value>)--</value> + <value>icon_lol.gif</value> + <value>15</value> + <value>17</value> + <value>22</value> + <value>1</value> + </row> + <row> + <value>3</value> + <value>)-(</value> + <value>)-(</value> + <value>icon_lol.gif</value> + <value>15</value> + <value>17</value> + <value>22</value> + <value>1</value> + </row> + </table> +</dataset> diff --git a/tests/text_processing/tickets_data/PHPBB3-15163.html b/tests/text_processing/tickets_data/PHPBB3-15163.html new file mode 100644 index 0000000000..a1af10187c --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-15163.html @@ -0,0 +1 @@ +<img class="smilies" src="phpBB/images/smilies/icon_lol.gif" width="15" height="17" alt="--{E" title="--{E">
\ No newline at end of file diff --git a/tests/text_processing/tickets_data/PHPBB3-15163.txt b/tests/text_processing/tickets_data/PHPBB3-15163.txt new file mode 100644 index 0000000000..126402d66a --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-15163.txt @@ -0,0 +1 @@ +--{E
\ No newline at end of file diff --git a/tests/text_processing/tickets_data/PHPBB3-15163.xml b/tests/text_processing/tickets_data/PHPBB3-15163.xml new file mode 100644 index 0000000000..f3e04c230f --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-15163.xml @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> + <table name="phpbb_smilies"> + <column>smiley_id</column> + <column>code</column> + <column>emotion</column> + <column>smiley_url</column> + <column>smiley_width</column> + <column>smiley_height</column> + <column>smiley_order</column> + <column>display_on_posting</column> + <row> + <value>1</value> + <value>--{E</value> + <value>--{E</value> + <value>icon_lol.gif</value> + <value>15</value> + <value>17</value> + <value>22</value> + <value>1</value> + </row> + </table> +</dataset> diff --git a/tests/ui/permission_roles_test.php b/tests/ui/permission_roles_test.php index 3501124fc1..de54cc788d 100644 --- a/tests/ui/permission_roles_test.php +++ b/tests/ui/permission_roles_test.php @@ -25,19 +25,19 @@ class ui_permission_roles_test extends phpbb_ui_test_case $this->visit('adm/index.php?i=acp_permissions&mode=setting_forum_local&sid=' . $this->sid); // Select forums - $elements = self::find_element('cssSelector', 'select#forum') + $elements = $this->find_element('cssSelector', 'select#forum') ->findElements(\Facebook\WebDriver\WebDriverBy::tagName('option')); foreach ($elements as $element) { $element->click(); } - self::find_element('cssSelector', 'form#select_victim') + $this->find_element('cssSelector', 'form#select_victim') ->findElement(\Facebook\WebDriver\WebDriverBy::cssSelector('input[type=submit]')) ->click(); // Select administrators and guests - $groups_form = self::find_element('cssSelector', 'form#groups'); + $groups_form = $this->find_element('cssSelector', 'form#groups'); $elements = $groups_form ->findElement(\Facebook\WebDriver\WebDriverBy::cssSelector('select')) ->findElements(\Facebook\WebDriver\WebDriverBy::tagName('option')); @@ -51,7 +51,7 @@ class ui_permission_roles_test extends phpbb_ui_test_case } $groups_form->findElement(\Facebook\WebDriver\WebDriverBy::cssSelector('input[name=submit_edit_options]'))->click(); - $first_fieldset = self::find_element('cssSelector', '#perm11'); + $first_fieldset = $this->find_element('cssSelector', '#perm11'); $this->assertEquals('none', $first_fieldset->findElement(\Facebook\WebDriver\WebDriverBy::cssSelector('div.dropdown'))->getCSSValue('display')); $first_fieldset ->findElement(\Facebook\WebDriver\WebDriverBy::cssSelector('span.dropdown-toggle')) @@ -74,14 +74,14 @@ class ui_permission_roles_test extends phpbb_ui_test_case $this->assertEquals($this->lang('ROLE_FORUM_LIMITED'), $first_fieldset->findElement(\Facebook\WebDriver\WebDriverBy::cssSelector('span.dropdown-toggle'))->getText()); // Check that admin settings didn't get changed - $second_fieldset = self::find_element('cssSelector', '#perm10'); + $second_fieldset = $this->find_element('cssSelector', '#perm10'); $this->assertEquals('none', $second_fieldset->findElement(\Facebook\WebDriver\WebDriverBy::cssSelector('div.dropdown'))->getCSSValue('display')); // Full access = 14 $this->assertEquals(14, $second_fieldset->findElement(\Facebook\WebDriver\WebDriverBy::cssSelector('input[type=hidden]'))->getAttribute('value')); $this->assertEquals($this->lang('ROLE_FORUM_FULL'), $second_fieldset->findElement(\Facebook\WebDriver\WebDriverBy::cssSelector('span.dropdown-toggle'))->getText()); // Check that category settings were not modified - $category_fieldset = self::find_element('cssSelector', '#perm00'); + $category_fieldset = $this->find_element('cssSelector', '#perm00'); $this->assertEquals('none', $category_fieldset->findElement(\Facebook\WebDriver\WebDriverBy::cssSelector('div.dropdown'))->getCSSValue('display')); // No settings $this->assertEquals('', $category_fieldset->findElement(\Facebook\WebDriver\WebDriverBy::cssSelector('input[type=hidden]'))->getAttribute('value')); diff --git a/tests/ui/quick_links_test.php b/tests/ui/quick_links_test.php index 582aeafcae..171ef3ca53 100644 --- a/tests/ui/quick_links_test.php +++ b/tests/ui/quick_links_test.php @@ -19,8 +19,8 @@ class quick_links_test extends phpbb_ui_test_case public function test_quick_links() { $this->visit('index.php'); - $this->assertEmpty(self::find_element('className', 'dropdown')->getText()); - self::find_element('className', 'dropdown-toggle')->click(); - $this->assertNotNull(self::find_element('className', 'dropdown')->getText()); + $this->assertEmpty($this->find_element('className', 'dropdown')->getText()); + $this->find_element('className', 'dropdown-toggle')->click(); + $this->assertNotNull($this->find_element('className', 'dropdown')->getText()); } } diff --git a/tests/version/version_test.php b/tests/version/version_test.php index 93d47a40a6..2a0240f847 100644 --- a/tests/version/version_test.php +++ b/tests/version/version_test.php @@ -341,4 +341,506 @@ class phpbb_version_helper_test extends phpbb_test_case $this->assertSame($expected, $version_helper->get_latest_on_current_branch()); } + + public function get_update_on_branch_data() + { + return array( + array( + '1.0.0', + array( + '1.0' => array( + 'current' => '1.0.1', + ), + '1.1' => array( + 'current' => '1.1.1', + ), + ), + array( + 'current' => '1.0.1', + ), + ), + array( + '1.0.1', + array( + '1.0' => array( + 'current' => '1.0.1', + ), + '1.1' => array( + 'current' => '1.1.1', + ), + ), + array(), + ), + array( + '1.0.1-a1', + array( + '1.0' => array( + 'current' => '1.0.1-a2', + ), + '1.1' => array( + 'current' => '1.1.0', + ), + ), + array( + 'current' => '1.0.1-a2', + ), + ), + array( + '1.1.0', + array( + '1.0' => array( + 'current' => '1.0.1', + ), + '1.1' => array( + 'current' => '1.1.1', + ), + ), + array( + 'current' => '1.1.1', + ), + ), + array( + '1.1.1', + array( + '1.0' => array( + 'current' => '1.0.1', + ), + '1.1' => array( + 'current' => '1.1.1', + ), + ), + array(), + ), + array( + '1.1.0-a1', + array( + '1.0' => array( + 'current' => '1.0.1', + ), + '1.1' => array( + 'current' => '1.1.0-a2', + ), + ), + array( + 'current' => '1.1.0-a2', + ), + ), + array( + '1.1.0', + array(), + array(), + ), + // Latest safe release is 1.0.1 + array( + '1.0.0', + array( + '1.0' => array( + 'current' => '1.0.1', + 'security' => '1.0.1', + ), + '1.1' => array( + 'current' => '1.1.1', + ), + ), + array( + 'current' => '1.0.1', + 'security' => '1.0.1', + ), + ), + // Latest safe release is 1.0.0 + array( + '1.0.0', + array( + '1.0' => array( + 'current' => '1.0.1', + 'security' => '1.0.0', + ), + '1.1' => array( + 'current' => '1.1.1', + ), + ), + array( + 'current' => '1.0.1', + 'security' => '1.0.0', + ), + ), + // Latest safe release is 1.1.0 + array( + '1.0.0', + array( + '1.0' => array( + 'current' => '1.0.1', + 'security' => '1.1.0', + ), + '1.1' => array( + 'current' => '1.1.1', + ), + ), + array( + 'current' => '1.1.1', + ), + ), + // Latest 1.0 release is EOL + array( + '1.0.0', + array( + '1.0' => array( + 'current' => '1.0.1', + 'eol' => true, + ), + '1.1' => array( + 'current' => '1.1.1', + ), + ), + array( + 'current' => '1.1.1', + ), + ), + // All are EOL -- somewhat undefined behavior + array( + '1.0.0', + array( + '1.0' => array( + 'current' => '1.0.1', + 'eol' => true, + ), + '1.1' => array( + 'current' => '1.1.1', + 'eol' => true, + ), + ), + array(), + ), + ); + } + + /** + * @dataProvider get_update_on_branch_data + */ + public function test_get_update_on_branch($current_version, $versions, $expected) + { + global $phpbb_root_path, $phpEx; + + $lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); + $lang = new \phpbb\language\language($lang_loader); + + $version_helper = $this + ->getMockBuilder('\phpbb\version_helper') + ->setMethods(array( + 'get_versions_matching_stability', + )) + ->setConstructorArgs(array( + $this->cache, + new \phpbb\config\config(array( + 'version' => $current_version, + )), + new \phpbb\file_downloader(), + new \phpbb\user($lang, '\phpbb\datetime'), + )) + ->getMock() + ; + + $version_helper->expects($this->any()) + ->method('get_versions_matching_stability') + ->will($this->returnValue($versions)); + + $this->assertSame($expected, $version_helper->get_update_on_branch()); + } + + public function get_ext_update_on_branch_data() + { + return array( + // Single branch, check version for current branch + array( + '3.1.0', + '1.0.0', + array( + '3.1' => array( + 'current' => '1.0.1', + ), + ), + array( + 'current' => '1.0.1', + ), + ), + array( + '3.1.0', + '1.0.1', + array( + '3.1' => array( + 'current' => '1.0.1', + ), + ), + array(), + ), + array( + '3.2.0', + '1.0.0', + array( + '3.2' => array( + 'current' => '1.1.1', + ), + ), + array( + 'current' => '1.1.1', + ), + ), + array( + '3.2.0', + '1.1.1', + array( + '3.2' => array( + 'current' => '1.1.1', + ), + ), + array(), + ), + // Single branch, check for newest version when branches don't match up + array( + '3.1.0', + '1.0.0', + array( + '3.2' => array( + 'current' => '1.1.1', + ), + ), + array( + 'current' => '1.1.1', + ), + ), + array( + '3.1.0', + '1.1.1', + array( + '3.2' => array( + 'current' => '1.1.1', + ), + ), + array(), + ), + array( + '3.2.0', + '1.0.0', + array( + '3.1' => array( + 'current' => '1.0.1', + ), + ), + array( + 'current' => '1.0.1', + ), + ), + array( + '3.2.0', + '1.0.1', + array( + '3.1' => array( + 'current' => '1.0.1', + ), + ), + array(), + ), + array( + '3.3.0', + '1.0.0', + array( + '3.2' => array( + 'current' => '1.1.1', + ), + ), + array( + 'current' => '1.1.1', + ), + ), + array( + '3.3.0', + '1.1.1', + array( + '3.2' => array( + 'current' => '1.1.1', + ), + ), + array(), + ), + // Multiple branches, check version for current branch + array( + '3.1.0', + '1.0.0', + array( + '3.1' => array( + 'current' => '1.0.1', + ), + '3.2' => array( + 'current' => '1.1.1', + ), + ), + array( + 'current' => '1.0.1', + ), + ), + array( + '3.1.0', + '1.0.1', + array( + '3.1' => array( + 'current' => '1.0.1', + ), + '3.2' => array( + 'current' => '1.1.1', + ), + ), + array(), + ), + array( + '3.1.0', + '1.1.1', + array( + '3.1' => array( + 'current' => '1.0.1', + ), + '3.2' => array( + 'current' => '1.1.1', + ), + ), + array(), + ), + array( + '3.2.0', + '1.0.0', + array( + '3.1' => array( + 'current' => '1.0.1', + ), + '3.2' => array( + 'current' => '1.1.1', + ), + ), + array( + 'current' => '1.1.1', + ), + ), + array( + '3.2.0', + '1.0.1', + array( + '3.1' => array( + 'current' => '1.0.1', + ), + '3.2' => array( + 'current' => '1.1.1', + ), + ), + array( + 'current' => '1.1.1', + ), + ), + array( + '3.2.0', + '1.1.1', + array( + '3.1' => array( + 'current' => '1.0.1', + ), + '3.2' => array( + 'current' => '1.1.1', + ), + ), + array(), + ), + // Multiple branches, check for newest version when branches don't match up + array( + '3.3.0', + '1.0.0', + array( + '3.1' => array( + 'current' => '1.0.1', + ), + '3.2' => array( + 'current' => '1.1.1', + ), + ), + array( + 'current' => '1.1.1', + ), + ), + array( + '3.3.0', + '1.0.1', + array( + '3.1' => array( + 'current' => '1.0.1', + ), + '3.2' => array( + 'current' => '1.1.1', + ), + ), + array( + 'current' => '1.1.1', + ), + ), + array( + '3.3.0', + '1.1.0', + array( + '3.1' => array( + 'current' => '1.0.1', + ), + '3.2' => array( + 'current' => '1.1.1', + ), + ), + array( + 'current' => '1.1.1', + ), + ), + array( + '3.3.0', + '1.1.1', + array( + '3.1' => array( + 'current' => '1.0.1', + ), + '3.2' => array( + 'current' => '1.1.1', + ), + ), + array(), + ), + ); + } + + /** + * @dataProvider get_ext_update_on_branch_data + */ + public function test_get_ext_update_on_branch($phpbb_version, $ext_version, $versions, $expected) + { + global $phpbb_root_path, $phpEx; + + $lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); + $lang = new \phpbb\language\language($lang_loader); + + $version_helper = $this + ->getMockBuilder('\phpbb\version_helper') + ->setMethods(array( + 'get_versions_matching_stability', + )) + ->setConstructorArgs(array( + $this->cache, + new \phpbb\config\config(array( + 'version' => $phpbb_version, + )), + new \phpbb\file_downloader(), + new \phpbb\user($lang, '\phpbb\datetime'), + )) + ->getMock() + ; + + $version_helper->expects($this->any()) + ->method('get_versions_matching_stability') + ->will($this->returnValue($versions)); + + $version_helper->set_current_version($ext_version); + + $this->assertSame($expected, $version_helper->get_ext_update_on_branch()); + } } |