diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | .travis.yml | 1 | ||||
-rw-r--r-- | phpBB/phpbb/notification/manager.php | 44 | ||||
-rw-r--r-- | phpBB/search.php | 2 | ||||
-rw-r--r-- | phpBB/viewforum.php | 8 | ||||
-rw-r--r-- | phpunit.xml.dist | 5 | ||||
-rw-r--r-- | tests/bootstrap.php | 5 | ||||
-rw-r--r-- | tests/composer.json | 5 | ||||
-rw-r--r-- | tests/composer.lock | 66 | ||||
-rw-r--r-- | tests/functional/feed_test.php | 37 | ||||
-rw-r--r-- | tests/functional/viewforum_paging_test.php | 256 | ||||
-rw-r--r-- | tests/test_framework/phpbb_functional_test_case.php | 7 | ||||
-rw-r--r-- | tests/test_framework/phpbb_test_case.php | 2 | ||||
-rw-r--r-- | tests/test_framework/phpbb_ui_test_case.php | 192 | ||||
-rw-r--r-- | tests/ui/quick_links_test.php | 27 | ||||
-rwxr-xr-x | travis/install-phpbb-test-dependencies.sh | 16 | ||||
-rw-r--r-- | travis/phpunit-mariadb-travis.xml | 4 | ||||
-rw-r--r-- | travis/phpunit-mysql-travis.xml | 4 | ||||
-rw-r--r-- | travis/phpunit-mysqli-travis.xml | 4 | ||||
-rw-r--r-- | travis/phpunit-postgres-travis.xml | 4 | ||||
-rw-r--r-- | travis/phpunit-sqlite3-travis.xml | 4 | ||||
-rwxr-xr-x | travis/setup-phpbb.sh | 1 |
22 files changed, 655 insertions, 40 deletions
diff --git a/.gitignore b/.gitignore index f9c04980ba..ab6b4aa7ee 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,4 @@ /tests/phpbb_unit_tests.sqlite* /tests/test_config*.php /tests/tmp/* +/tests/vendor diff --git a/.travis.yml b/.travis.yml index cbba07b16d..2e0b68c3de 100644 --- a/.travis.yml +++ b/.travis.yml @@ -34,6 +34,7 @@ install: before_script: - travis/setup-database.sh $DB $TRAVIS_PHP_VERSION + - phantomjs --webdriver=8910 > /dev/null & script: - travis/phing-sniff.sh $DB $TRAVIS_PHP_VERSION diff --git a/phpBB/phpbb/notification/manager.php b/phpBB/phpbb/notification/manager.php index 81b450ebbd..971a53a16a 100644 --- a/phpBB/phpbb/notification/manager.php +++ b/phpBB/phpbb/notification/manager.php @@ -24,6 +24,9 @@ class manager protected $notification_types; /** @var array */ + protected $subscription_types; + + /** @var array */ protected $notification_methods; /** @var ContainerInterface */ @@ -524,33 +527,36 @@ class manager */ public function get_subscription_types() { - $subscription_types = array(); - - foreach ($this->notification_types as $type_name => $data) + if ($this->subscription_types === null) { - $type = $this->get_item_type_class($type_name); + $this->subscription_types = array(); - if ($type instanceof \phpbb\notification\type\type_interface && $type->is_available()) + foreach ($this->notification_types as $type_name => $data) { - $options = array_merge(array( - 'id' => $type->get_type(), - 'lang' => 'NOTIFICATION_TYPE_' . strtoupper($type->get_type()), - 'group' => 'NOTIFICATION_GROUP_MISCELLANEOUS', - ), (($type::$notification_option !== false) ? $type::$notification_option : array())); + $type = $this->get_item_type_class($type_name); + + if ($type instanceof \phpbb\notification\type\type_interface && $type->is_available()) + { + $options = array_merge(array( + 'id' => $type->get_type(), + 'lang' => 'NOTIFICATION_TYPE_' . strtoupper($type->get_type()), + 'group' => 'NOTIFICATION_GROUP_MISCELLANEOUS', + ), (($type::$notification_option !== false) ? $type::$notification_option : array())); - $subscription_types[$options['group']][$options['id']] = $options; + $this->subscription_types[$options['group']][$options['id']] = $options; + } } - } - // Move Miscellaneous to the very last section - if (isset($subscription_types['NOTIFICATION_GROUP_MISCELLANEOUS'])) - { - $miscellaneous = $subscription_types['NOTIFICATION_GROUP_MISCELLANEOUS']; - unset($subscription_types['NOTIFICATION_GROUP_MISCELLANEOUS']); - $subscription_types['NOTIFICATION_GROUP_MISCELLANEOUS'] = $miscellaneous; + // Move Miscellaneous to the very last section + if (isset($this->subscription_types['NOTIFICATION_GROUP_MISCELLANEOUS'])) + { + $miscellaneous = $this->subscription_types['NOTIFICATION_GROUP_MISCELLANEOUS']; + unset($this->subscription_types['NOTIFICATION_GROUP_MISCELLANEOUS']); + $this->subscription_types['NOTIFICATION_GROUP_MISCELLANEOUS'] = $miscellaneous; + } } - return $subscription_types; + return $this->subscription_types; } /** diff --git a/phpBB/search.php b/phpBB/search.php index 0d269c5606..e80a89b382 100644 --- a/phpBB/search.php +++ b/phpBB/search.php @@ -922,7 +922,7 @@ if ($keywords || $author || $author_id || $search_id || $submit) $posts_unapproved = ($row['topic_visibility'] == ITEM_APPROVED && $row['topic_posts_unapproved'] && $auth->acl_get('m_approve', $forum_id)) ? true : false; $topic_deleted = $row['topic_visibility'] == ITEM_DELETED; $u_mcp_queue = ($topic_unapproved || $posts_unapproved) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&mode=' . (($topic_unapproved) ? 'approve_details' : 'unapproved_posts') . "&t=$result_topic_id", true, $user->session_id) : ''; - $u_mcp_queue = (!$u_mcp_queue && $topic_deleted) ? append_sid("{$phpbb_root_path}mcp.$phpEx", "i=queue&mode=deleted_topics&t=$result_topic_id", true, $user->session_id) : ''; + $u_mcp_queue = (!$u_mcp_queue && $topic_deleted) ? append_sid("{$phpbb_root_path}mcp.$phpEx", "i=queue&mode=deleted_topics&t=$result_topic_id", true, $user->session_id) : $u_mcp_queue; $row['topic_title'] = preg_replace('#(?!<.*)(?<!\w)(' . $hilit . ')(?!\w|[^<>]*(?:</s(?:cript|tyle))?>)#is', '<span class="posthilit">$1</span>', $row['topic_title']); diff --git a/phpBB/viewforum.php b/phpBB/viewforum.php index 6379da6802..1f455494f7 100644 --- a/phpBB/viewforum.php +++ b/phpBB/viewforum.php @@ -504,8 +504,8 @@ if ($start > $topics_count / 2) // Select the sort order $direction = (($sort_dir == 'd') ? 'ASC' : 'DESC'); - $sql_limit = $pagination->reverse_limit($start, $sql_limit, $topics_count); - $sql_start = $pagination->reverse_start($start, $sql_limit, $topics_count); + $sql_limit = $pagination->reverse_limit($start, $sql_limit, $topics_count - sizeof($announcement_list)); + $sql_start = $pagination->reverse_start($start, $sql_limit, $topics_count - sizeof($announcement_list)); } else { @@ -694,10 +694,10 @@ if ($s_display_active) // We need to remove the global announcements from the forums total topic count, // otherwise the number is different from the one on the forum list -$total_topic_count = $topics_count - sizeof($global_announce_forums); +$total_topic_count = $topics_count - sizeof($announcement_list); $base_url = append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id" . ((strlen($u_sort_param)) ? "&$u_sort_param" : '')); -$pagination->generate_template_pagination($base_url, 'pagination', 'start', $topics_count, $config['topics_per_page'], $start); +$pagination->generate_template_pagination($base_url, 'pagination', 'start', $total_topic_count, $config['topics_per_page'], $start); $template->assign_vars(array( 'TOTAL_TOPICS' => ($s_display_active) ? false : $user->lang('VIEW_FORUM_TOPICS', (int) $total_topic_count), diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 3475742288..bcc63d6fd9 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -16,6 +16,7 @@ <directory suffix="_test.php">./tests</directory> <exclude>./tests/functional</exclude> <exclude>./tests/lint_test.php</exclude> + <exclude>./tests/ui</exclude> </testsuite> <testsuite name="phpBB Functional Tests"> <directory suffix="_test.php">./tests/functional</directory> @@ -23,6 +24,10 @@ <testsuite name="phpBB Lint Test"> <file>./tests/lint_test.php</file> </testsuite> + <testsuite name="phpBB UI Tests"> + <directory suffix="_test.php" phpVersion="5.3.19" + phpVersionOperator=">=">./tests/ui</directory> + </testsuite> </testsuites> <groups> diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 40c6ef7dfa..65447eb95c 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -33,3 +33,8 @@ require_once 'test_framework/phpbb_test_case.php'; require_once 'test_framework/phpbb_database_test_case.php'; require_once 'test_framework/phpbb_database_test_connection_manager.php'; require_once 'test_framework/phpbb_functional_test_case.php'; + +if (version_compare(PHP_VERSION,'5.3.19', ">=")) +{ + require_once 'test_framework/phpbb_ui_test_case.php'; +} diff --git a/tests/composer.json b/tests/composer.json new file mode 100644 index 0000000000..69512f30a6 --- /dev/null +++ b/tests/composer.json @@ -0,0 +1,5 @@ +{ + "require-dev": { + "facebook/webdriver": "dev-master" + } +} diff --git a/tests/composer.lock b/tests/composer.lock new file mode 100644 index 0000000000..32d90d43fc --- /dev/null +++ b/tests/composer.lock @@ -0,0 +1,66 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file" + ], + "hash": "2affca245bd4946ca7acdf46f100af3c", + "packages": [ + + ], + "packages-dev": [ + { + "name": "facebook/webdriver", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/facebook/php-webdriver.git", + "reference": "b6e002e5bf811a8edba393ce6872322c1b7cf796" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/facebook/php-webdriver/zipball/b6e002e5bf811a8edba393ce6872322c1b7cf796", + "reference": "b6e002e5bf811a8edba393ce6872322c1b7cf796", + "shasum": "" + }, + "require": { + "php": ">=5.3.19" + }, + "require-dev": { + "phpdocumentor/phpdocumentor": "2.*", + "phpunit/phpunit": "3.7.*" + }, + "type": "library", + "autoload": { + "classmap": [ + "lib/" + ] + }, + "notification-url": "http://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "description": "A php client for WebDriver", + "homepage": "https://github.com/facebook/php-webdriver", + "keywords": [ + "facebook", + "php", + "selenium", + "webdriver" + ], + "time": "2014-08-05 02:55:46" + } + ], + "aliases": [ + + ], + "minimum-stability": "stable", + "stability-flags": { + "facebook/webdriver": 20 + }, + "platform": [ + + ], + "platform-dev": [ + + ] +} diff --git a/tests/functional/feed_test.php b/tests/functional/feed_test.php index 7aa2d0da7d..9041c8dc69 100644 --- a/tests/functional/feed_test.php +++ b/tests/functional/feed_test.php @@ -322,15 +322,9 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case $post = $this->create_topic($this->data['forums']['Feeds #news'], 'Feeds #news - Topic #1', 'This is a test topic posted by the testing framework.'); $this->data['topics']['Feeds #news - Topic #1'] = (int) $post['topic_id']; - // Travis is too fast, so we have to wait - sleep(1); - $post = $this->create_topic($this->data['forums']['Feeds #news'], 'Feeds #news - Topic #2', 'This is a test topic posted by the testing framework.'); $crawler = self::request('GET', "viewtopic.php?t={$post['topic_id']}&sid={$this->sid}"); - // Travis is too fast, so we have to wait - sleep(1); - $this->assertContains('Feeds #news - Topic #2', $crawler->filter('html')->text()); $this->data['topics']['Feeds #news - Topic #2'] = (int) $post['topic_id']; $this->data['posts']['Feeds #news - Topic #2'] = (int) $this->get_parameter_from_link($crawler->filter('.post')->selectLink($this->lang('POST', '', ''))->link()->getUri(), 'p'); @@ -456,9 +450,6 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case $post = $this->create_topic($this->data['forums']['Feeds #1'], 'Feeds #1 - Topic #1', 'This is a test topic posted by the testing framework.'); $this->data['topics']['Feeds #1 - Topic #1'] = (int) $post['topic_id']; - // Travis is too fast, so we have to wait - sleep(1); - $post = $this->create_topic($this->data['forums']['Feeds #1.1'], 'Feeds #1.1 - Topic #1', 'This is a test topic posted by the testing framework.'); $this->data['topics']['Feeds #1.1 - Topic #1'] = (int) $post['topic_id']; } @@ -494,9 +485,6 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case $post = $this->create_topic($this->data['forums']['Feeds #1'], 'Feeds #1 - Topic #2', 'This is a test topic posted by the testing framework.'); $this->data['topics']['Feeds #1 - Topic #2'] = (int) $post['topic_id']; - // Travis is too fast, so we have to wait - sleep(1); - // Test creating a reply $post2 = $this->create_post($this->data['forums']['Feeds #1'], $post['topic_id'], 'Re: Feeds #1 - Topic #2', 'This is a test post posted by the testing framework.'); $crawler = self::request('GET', "viewtopic.php?t={$post2['topic_id']}&sid={$this->sid}"); @@ -852,9 +840,7 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case 'Feeds #1.1', ), )); - - // We have to wait because of the flood interval. - sleep(15); + $this->set_flood_interval(0); $this->login('disapprove_user'); $post = $this->create_topic($this->data['forums']['Feeds #1.1'], 'Feeds #1.1 - Topic #3', 'This is a test topic posted by the testing framework.', array(), 'POST_STORED_MOD'); @@ -862,6 +848,27 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case $crawler = self::request('GET', "viewforum.php?f={$this->data['forums']['Feeds #1.1']}&sid={$this->sid}"); $this->assertNotContains('Feeds #1.1 - Topic #3', $crawler->filter('html')->text()); + + $this->logout(); + $this->set_flood_interval(15); + } + + protected function set_flood_interval($flood_interval) + { + $this->login(); + $this->admin_login(); + + $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[flood_interval]"] = $flood_interval; + $form->setValues($values); + $crawler = self::submit($form); + $this->assertGreaterThan(0, $crawler->filter('.successbox')->count()); + + $this->logout(); } public function test_feeds_unapproved_topic_admin() diff --git a/tests/functional/viewforum_paging_test.php b/tests/functional/viewforum_paging_test.php new file mode 100644 index 0000000000..4a574bebbb --- /dev/null +++ b/tests/functional/viewforum_paging_test.php @@ -0,0 +1,256 @@ +<?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 viewforum_paging_test extends phpbb_functional_test_case +{ + protected $data = array(); + + public function test_setup_forums() + { + $this->login(); + $this->admin_login(); + + $crawler = self::request('GET', "adm/index.php?i=acp_forums&mode=manage&sid={$this->sid}"); + $form = $crawler->selectButton('addforum')->form(array( + 'forum_name' => 'Viewforum Pagination Test #1', + )); + $crawler = self::submit($form); + $form = $crawler->selectButton('update')->form(array( + 'forum_perm_from' => 2, + )); + self::submit($form); + + $crawler = self::request('GET', "adm/index.php?i=acp_forums&mode=manage&sid={$this->sid}"); + $form = $crawler->selectButton('addforum')->form(array( + 'forum_name' => 'Viewforum Pagination Test #2', + )); + $crawler = self::submit($form); + $form = $crawler->selectButton('update')->form(array( + 'forum_perm_from' => 2, + )); + self::submit($form); + + $this->set_post_settings(array( + 'flood_interval' => 0, + 'topics_per_page' => 3, + )); + } + + public function test_create_posts() + { + $this->login(); + $this->load_ids(array( + 'forums' => array( + 'Viewforum Pagination Test #1', + 'Viewforum Pagination Test #2', + ), + )); + + $this->assert_forum_details($this->data['forums']['Viewforum Pagination Test #1'], array( + 'forum_posts_approved' => 0, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 0, + 'forum_topics_approved' => 0, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => 0, + ), 'initial comparison'); + + for ($topic_id = 1; $topic_id <= 6; $topic_id++) + { + $this->create_topic($this->data['forums']['Viewforum Pagination Test #1'], 'Viewforum Pagination TestTopic #' . $topic_id, 'This is a test topic posted by the testing framework.'); + } + + $this->create_topic($this->data['forums']['Viewforum Pagination Test #2'], 'Viewforum Pagination TestTopic #GA1', 'This is a test topic posted by the testing framework.', array( + 'topic_type' => POST_GLOBAL, + )); + + $this->assert_forum_details($this->data['forums']['Viewforum Pagination Test #1'], array( + 'forum_posts_approved' => 6, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 0, + 'forum_topics_approved' => 6, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + ), 'after creating topics'); + + $this->assert_forum_details($this->data['forums']['Viewforum Pagination Test #2'], array( + 'forum_posts_approved' => 1, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 0, + 'forum_topics_approved' => 1, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + ), 'after creating GA'); + + // Set flood interval back to 15 + $this->admin_login(); + $this->set_post_settings(array( + 'flood_interval' => 15, + )); + } + + public function test_viewforum_first_page() + { + $this->load_ids(array( + 'forums' => array( + 'Viewforum Pagination Test #1', + 'Viewforum Pagination Test #2', + ), + )); + $crawler = self::request('GET', 'viewforum.php?f=' . $this->data['forums']['Viewforum Pagination Test #1']); + + // Test the topics that are displayed + $topiclists = $crawler->filter('.forumbg .topics'); + $this->assertEquals(2, $topiclists->count()); + $topiclist = $topiclists->eq(0)->filter('li'); + $this->assertStringEndsWith('TestTopic #GA1', $topiclist->eq(0)->filter('.topictitle')->text()); + $topiclist = $topiclists->eq(1)->filter('li'); + $this->assertStringEndsWith('TestTopic #6', $topiclist->eq(0)->filter('.topictitle')->text()); + $this->assertStringEndsWith('TestTopic #5', $topiclist->eq(1)->filter('.topictitle')->text()); + $this->assertStringEndsWith('TestTopic #4', $topiclist->eq(2)->filter('.topictitle')->text()); + + // Test the pagination, should only have: 1 - 2 - Next + $this->assertEquals(2, $crawler->filter('div.pagination')->count()); + $top_pagination = $crawler->filter('div.pagination')->eq(0); + $this->assertEquals(3, $top_pagination->filter('li')->count(), 'Number of pagination items on page 1 does not match'); + $this->assertContains('1', $top_pagination->filter('li')->eq(0)->text()); + $this->assertContains('2', $top_pagination->filter('li')->eq(1)->text()); + $this->assertContainsLang('NEXT', $top_pagination->filter('li')->eq(2)->text()); + } + + public function test_viewforum_second_page() + { + $this->load_ids(array( + 'forums' => array( + 'Viewforum Pagination Test #1', + 'Viewforum Pagination Test #2', + ), + )); + $crawler = self::request('GET', 'viewforum.php?f=' . $this->data['forums']['Viewforum Pagination Test #1'] . '&start=3'); + + // Test the topics that are displayed + $topiclists = $crawler->filter('.forumbg .topics'); + $this->assertEquals(2, $topiclists->count()); + $topiclist = $topiclists->eq(0)->filter('li'); + $this->assertStringEndsWith('TestTopic #GA1', $topiclist->eq(0)->filter('.topictitle')->text()); + $topiclist = $topiclists->eq(1)->filter('li'); + $this->assertStringEndsWith('TestTopic #3', $topiclist->eq(0)->filter('.topictitle')->text()); + $this->assertStringEndsWith('TestTopic #2', $topiclist->eq(1)->filter('.topictitle')->text()); + $this->assertStringEndsWith('TestTopic #1', $topiclist->eq(2)->filter('.topictitle')->text()); + + // Test the pagination, should only have: Previous - 1 - 2 + $this->assertEquals(2, $crawler->filter('div.pagination')->count()); + $top_pagination = $crawler->filter('div.pagination')->eq(0); + $this->assertEquals(3, $top_pagination->filter('li')->count(), 'Number of pagination items on page 2 does not match'); + $this->assertContainsLang('PREVIOUS', $top_pagination->filter('li')->eq(0)->text()); + $this->assertContains('1', $top_pagination->filter('li')->eq(1)->text()); + $this->assertContains('2', $top_pagination->filter('li')->eq(2)->text()); + } + + protected function assert_forum_details($forum_id, $details, $additional_error_message = '') + { + $this->db = $this->get_db(); + + $sql = 'SELECT ' . implode(', ', array_keys($details)) . ' + FROM phpbb_forums + WHERE forum_id = ' . (int) $forum_id; + $result = $this->db->sql_query($sql); + $data = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + $this->assertEquals($details, $data, "Forum {$forum_id} does not match expected {$additional_error_message}"); + } + + /** + * Sets the post setting via the ACP page + * + * @param array $settings + */ + protected function set_post_settings($settings) + { + $crawler = self::request('GET', 'adm/index.php?sid=' . $this->sid . '&i=acp_board&mode=post'); + + $form = $crawler->selectButton('Submit')->form(); + $values = $form->getValues(); + + foreach ($settings as $setting => $value) + { + $values["config[{$setting}]"] = $value; + } + $form->setValues($values); + $crawler = self::submit($form); + $this->assertGreaterThan(0, $crawler->filter('.successbox')->count()); + } + + /** + * Loads forum, topic and post IDs + * + * @param array $data + */ + protected function load_ids($data) + { + $this->db = $this->get_db(); + + if (!empty($data['forums'])) + { + $sql = 'SELECT * + FROM phpbb_forums + WHERE ' . $this->db->sql_in_set('forum_name', $data['forums']); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + if (in_array($row['forum_name'], $data['forums'])) + { + $this->data['forums'][$row['forum_name']] = (int) $row['forum_id']; + } + } + $this->db->sql_freeresult($result); + } + + if (!empty($data['topics'])) + { + $sql = 'SELECT * + FROM phpbb_topics + WHERE ' . $this->db->sql_in_set('topic_title', $data['topics']); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + if (in_array($row['topic_title'], $data['topics'])) + { + $this->data['topics'][$row['topic_title']] = (int) $row['topic_id']; + } + } + $this->db->sql_freeresult($result); + } + + if (!empty($data['posts'])) + { + $sql = 'SELECT * + FROM phpbb_posts + WHERE ' . $this->db->sql_in_set('post_subject', $data['posts']); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + if (in_array($row['post_subject'], $data['posts'])) + { + $this->data['posts'][$row['post_subject']] = (int) $row['post_id']; + } + } + $this->db->sql_freeresult($result); + } + } +} diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 840ff981cb..51bae7a723 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -38,6 +38,7 @@ class phpbb_functional_test_case extends phpbb_test_case static protected $config = array(); static protected $already_installed = false; + static protected $last_post_timestamp = 0; static public function setUpBeforeClass() { @@ -1098,6 +1099,12 @@ class phpbb_functional_test_case extends phpbb_test_case */ protected function submit_message($posting_url, $posting_contains, $form_data) { + if (time() == self::$last_post_timestamp) + { + // Travis is too fast, so we have to wait to not mix up the post/topic order + sleep(1); + } + self::$last_post_timestamp = time(); $crawler = self::request('GET', $posting_url); $this->assertContains($this->lang($posting_contains), $crawler->filter('html')->text()); diff --git a/tests/test_framework/phpbb_test_case.php b/tests/test_framework/phpbb_test_case.php index c39f7835d1..01d26fb67d 100644 --- a/tests/test_framework/phpbb_test_case.php +++ b/tests/test_framework/phpbb_test_case.php @@ -26,7 +26,7 @@ class phpbb_test_case extends PHPUnit_Framework_TestCase 'PHP_Token_Stream' => array('customTokens'), 'PHP_Token_Stream_CachingFactory' => array('cache'), - 'phpbb_database_test_case' => array('already_connected'), + 'phpbb_database_test_case' => array('already_connected', 'last_post_timestamp'), ); } diff --git a/tests/test_framework/phpbb_ui_test_case.php b/tests/test_framework/phpbb_ui_test_case.php new file mode 100644 index 0000000000..702b15d50a --- /dev/null +++ b/tests/test_framework/phpbb_ui_test_case.php @@ -0,0 +1,192 @@ +<?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 __DIR__ . '/../vendor/facebook/webdriver/lib/__init__.php'; +require_once __DIR__ . '/../../phpBB/includes/functions_install.php'; + +class phpbb_ui_test_case extends phpbb_test_case +{ + static protected $host = '127.0.0.1'; + static protected $port = 8910; + + /** + * @var \RemoteWebDriver + */ + static protected $webDriver; + + static protected $config; + static protected $root_url; + static protected $already_installed = false; + + static public function setUpBeforeClass() + { + parent::setUpBeforeClass(); + + self::$config = phpbb_test_case_helpers::get_test_config(); + self::$root_url = self::$config['phpbb_functional_url']; + + // Important: this is used both for installation and by + // test cases for querying the tables. + // Therefore table prefix must be set before a board is + // installed, and also before each test case is run. + self::$config['table_prefix'] = 'phpbb_'; + + if (!isset(self::$config['phpbb_functional_url'])) + { + 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 = array(\WebDriverCapabilityType::BROWSER_NAME => 'firefox'); + self::$webDriver = RemoteWebDriver::create(self::$host . ':' . self::$port, $capabilities); + } catch (WebDriverCurlException $e) { + self::markTestSkipped('PhantomJS webserver is not running.'); + } + } + + if (!self::$already_installed) + { + self::install_board(); + self::$already_installed = true; + } + } + + static public function visit($path) + { + self::$webDriver->get(self::$root_url . $path); + } + + static protected function recreate_database($config) + { + $db_conn_mgr = new phpbb_database_test_connection_manager($config); + $db_conn_mgr->recreate_db(); + } + + static public function find_element($type, $value) + { + return self::$webDriver->findElement(WebDriverBy::$type($value)); + } + + static public function submit($type = 'id', $value = 'submit') + { + $element = self::find_element($type, $value); + $element->click(); + } + + static public function install_board() + { + global $phpbb_root_path, $phpEx; + + self::recreate_database(self::$config); + + $config_file = $phpbb_root_path . "config.$phpEx"; + $config_file_dev = $phpbb_root_path . "config_dev.$phpEx"; + $config_file_test = $phpbb_root_path . "config_test.$phpEx"; + + if (file_exists($config_file)) + { + if (!file_exists($config_file_dev)) + { + rename($config_file, $config_file_dev); + } + else + { + unlink($config_file); + } + } + + $parseURL = parse_url(self::$config['phpbb_functional_url']); + + self::visit('install/index.php?mode=install&language=en'); + self::assertContains('Welcome to Installation', self::find_element('id', 'main')->getText()); + + // install/index.php?mode=install&sub=requirements + self::submit(); + self::assertContains('Installation compatibility', self::find_element('id', 'main')->getText()); + + // install/index.php?mode=install&sub=database + self::submit(); + self::assertContains('Database configuration', self::find_element('id', 'main')->getText()); + + self::find_element('id','dbms')->sendKeys(str_replace('phpbb\db\driver\\', '', self::$config['dbms'])); + self::find_element('id','dbhost')->sendKeys(self::$config['dbhost']); + self::find_element('id','dbport')->sendKeys(self::$config['dbport']); + self::find_element('id','dbname')->sendKeys(self::$config['dbname']); + self::find_element('id','dbuser')->sendKeys(self::$config['dbuser']); + self::find_element('id','dbpasswd')->sendKeys(self::$config['dbpasswd']); + + // Need to clear default phpbb_ prefix + self::find_element('id','table_prefix')->clear(); + self::find_element('id','table_prefix')->sendKeys(self::$config['table_prefix']); + + // install/index.php?mode=install&sub=database + self::submit(); + self::assertContains('Successful connection', self::find_element('id','main')->getText()); + + // install/index.php?mode=install&sub=administrator + self::submit(); + self::assertContains('Administrator configuration', self::find_element('id','main')->getText()); + + self::find_element('id','admin_name')->sendKeys('admin'); + self::find_element('id','admin_pass1')->sendKeys('adminadmin'); + self::find_element('id','admin_pass2')->sendKeys('adminadmin'); + self::find_element('id','board_email')->sendKeys('nobody@example.com'); + + // install/index.php?mode=install&sub=administrator + self::submit(); + self::assertContains('Tests passed', self::find_element('id','main')->getText()); + + // install/index.php?mode=install&sub=config_file + self::submit(); + + // Installer has created a config.php file, we will overwrite it with a + // config file of our own in order to get the DEBUG constants defined + $config_php_data = phpbb_create_config_file_data(self::$config, self::$config['dbms'], true, false, true); + $config_created = file_put_contents($config_file, $config_php_data) !== false; + if (!$config_created) + { + self::markTestSkipped("Could not write $config_file file."); + } + + if (strpos(self::find_element('id','main')->getText(), 'The configuration file has been written') === false) + { + self::submit('id', 'dldone'); + } + self::assertContains('The configuration file has been written', self::find_element('id','main')->getText()); + + // install/index.php?mode=install&sub=advanced + self::submit(); + self::assertContains('The settings on this page are only necessary to set if you know that you require something different from the default.', self::find_element('id','main')->getText()); + + self::find_element('id','smtp_delivery')->sendKeys('1'); + self::find_element('id','smtp_host')->sendKeys('nxdomain.phpbb.com'); + self::find_element('id','smtp_user')->sendKeys('nxuser'); + self::find_element('id','smtp_pass')->sendKeys('nxpass'); + self::find_element('id','server_protocol')->sendKeys($parseURL['scheme'] . '://'); + self::find_element('id','server_name')->sendKeys('localhost'); + self::find_element('id','server_port')->sendKeys(isset($parseURL['port']) ? $parseURL['port'] : 80); + self::find_element('id','script_path')->sendKeys($parseURL['path']); + + // install/index.php?mode=install&sub=create_table + self::submit(); + self::assertContains('The database tables used by phpBB', self::find_element('id','main')->getText()); + self::assertContains('have been created and populated with some initial data.', self::find_element('id','main')->getText()); + + // install/index.php?mode=install&sub=final + self::submit(); + self::assertContains('You have successfully installed', self::find_element('id', 'main')->getText()); + + copy($config_file, $config_file_test); + } +} diff --git a/tests/ui/quick_links_test.php b/tests/ui/quick_links_test.php new file mode 100644 index 0000000000..5bddb44a8b --- /dev/null +++ b/tests/ui/quick_links_test.php @@ -0,0 +1,27 @@ +<?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 ui +*/ +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()); + } +} diff --git a/travis/install-phpbb-test-dependencies.sh b/travis/install-phpbb-test-dependencies.sh new file mode 100755 index 0000000000..25743ff2b1 --- /dev/null +++ b/travis/install-phpbb-test-dependencies.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# +# 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. +# +set -e +set -x + +cd tests +php ../composer.phar install --dev --no-interaction --prefer-source +cd .. diff --git a/travis/phpunit-mariadb-travis.xml b/travis/phpunit-mariadb-travis.xml index aa245a8224..53a206b9b0 100644 --- a/travis/phpunit-mariadb-travis.xml +++ b/travis/phpunit-mariadb-travis.xml @@ -16,10 +16,14 @@ <directory suffix="_test.php">../tests</directory> <exclude>../tests/functional</exclude> <exclude>../tests/lint_test.php</exclude> + <exclude>../tests/ui</exclude> </testsuite> <testsuite name="phpBB Functional Tests"> <directory suffix="_test.php" phpVersion="5.3.19" phpVersionOperator=">=">../tests/functional</directory> </testsuite> + <testsuite name="phpBB UI Tests"> + <directory suffix="_test.php" phpVersion="5.3.19" phpVersionOperator=">=">../tests/ui</directory> + </testsuite> </testsuites> <groups> diff --git a/travis/phpunit-mysql-travis.xml b/travis/phpunit-mysql-travis.xml index 21122ccaeb..d0d3e3c0c0 100644 --- a/travis/phpunit-mysql-travis.xml +++ b/travis/phpunit-mysql-travis.xml @@ -16,10 +16,14 @@ <directory suffix="_test.php">../tests</directory> <exclude>../tests/functional</exclude> <exclude>../tests/lint_test.php</exclude> + <exclude>../tests/ui</exclude> </testsuite> <testsuite name="phpBB Functional Tests"> <directory suffix="_test.php" phpVersion="5.3.19" phpVersionOperator=">=">../tests/functional</directory> </testsuite> + <testsuite name="phpBB UI Tests"> + <directory suffix="_test.php" phpVersion="5.3.19" phpVersionOperator=">=">../tests/ui</directory> + </testsuite> </testsuites> <groups> diff --git a/travis/phpunit-mysqli-travis.xml b/travis/phpunit-mysqli-travis.xml index 60c279d774..4c963895fc 100644 --- a/travis/phpunit-mysqli-travis.xml +++ b/travis/phpunit-mysqli-travis.xml @@ -16,6 +16,7 @@ <directory suffix="_test.php">../tests</directory> <exclude>../tests/functional</exclude> <exclude>../tests/lint_test.php</exclude> + <exclude>../tests/ui</exclude> </testsuite> <testsuite name="phpBB Lint Test"> <file>../tests/lint_test.php</file> @@ -23,6 +24,9 @@ <testsuite name="phpBB Functional Tests"> <directory suffix="_test.php" phpVersion="5.3.19" phpVersionOperator=">=">../tests/functional</directory> </testsuite> + <testsuite name="phpBB UI Tests"> + <directory suffix="_test.php" phpVersion="5.3.19" phpVersionOperator=">=">../tests/ui</directory> + </testsuite> </testsuites> <groups> diff --git a/travis/phpunit-postgres-travis.xml b/travis/phpunit-postgres-travis.xml index 956278e90c..fa497a1264 100644 --- a/travis/phpunit-postgres-travis.xml +++ b/travis/phpunit-postgres-travis.xml @@ -16,10 +16,14 @@ <directory suffix="_test.php">../tests</directory> <exclude>../tests/functional</exclude> <exclude>../tests/lint_test.php</exclude> + <exclude>../tests/ui</exclude> </testsuite> <testsuite name="phpBB Functional Tests"> <directory suffix="_test.php" phpVersion="5.3.19" phpVersionOperator=">=">../tests/functional</directory> </testsuite> + <testsuite name="phpBB UI Tests"> + <directory suffix="_test.php" phpVersion="5.3.19" phpVersionOperator=">=">../tests/ui</directory> + </testsuite> </testsuites> <groups> diff --git a/travis/phpunit-sqlite3-travis.xml b/travis/phpunit-sqlite3-travis.xml index 72b8b8c8ca..5baab791e0 100644 --- a/travis/phpunit-sqlite3-travis.xml +++ b/travis/phpunit-sqlite3-travis.xml @@ -16,10 +16,14 @@ <directory suffix="_test.php">../tests</directory> <exclude>../tests/functional</exclude> <exclude>../tests/lint_test.php</exclude> + <exclude>../tests/ui</exclude> </testsuite> <testsuite name="phpBB Functional Tests"> <directory suffix="_test.php" phpVersion="5.3.19" phpVersionOperator=">=">../tests/functional</directory> </testsuite> + <testsuite name="phpBB UI Tests"> + <directory suffix="_test.php" phpVersion="5.3.19" phpVersionOperator=">=">../tests/ui</directory> + </testsuite> </testsuites> <groups> diff --git a/travis/setup-phpbb.sh b/travis/setup-phpbb.sh index d829772196..205f23b876 100755 --- a/travis/setup-phpbb.sh +++ b/travis/setup-phpbb.sh @@ -33,6 +33,7 @@ fi if [ `php -r "echo (int) version_compare(PHP_VERSION, '5.3.19', '>=');"` == "1" ] then travis/setup-webserver.sh + travis/install-phpbb-test-dependencies.sh fi cd phpBB |