diff options
22 files changed, 272 insertions, 528 deletions
diff --git a/phpBB/composer.json b/phpBB/composer.json index 0ab30b0837..e74dd120f0 100644 --- a/phpBB/composer.json +++ b/phpBB/composer.json @@ -37,8 +37,6 @@ "twig/twig": "1.13.*" }, "require-dev": { - "behat/mink": "1.4.*", - "behat/mink-goutte-driver": "1.0.*", "fabpot/goutte": "1.0.*", "phpunit/dbunit": "1.3.*", "phpunit/phpunit": "4.1.*", diff --git a/phpBB/composer.lock b/phpBB/composer.lock index 3860a98b31..671daa70e1 100644 --- a/phpBB/composer.lock +++ b/phpBB/composer.lock @@ -3,7 +3,7 @@ "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": "6bc742a2b9feb426db9987d27085f915", + "hash": "27d5da149e0b5d76b76f43210306b666", "packages": [ { "name": "lusitanian/oauth", @@ -255,12 +255,14 @@ ], "authors": [ { - "name": "Symfony Community", - "homepage": "http://symfony.com/contributors" + "name": "Fabien Potencier", + "email": "fabien@symfony.com", + "homepage": "http://fabien.potencier.org", + "role": "Lead Developer" }, { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" } ], "description": "Symfony Debug Component", @@ -719,167 +721,6 @@ ], "packages-dev": [ { - "name": "behat/mink", - "version": "v1.4.3", - "source": { - "type": "git", - "url": "https://github.com/Behat/Mink.git", - "reference": "0817070a6e2ec9f475fad9bfb81a962c462eb934" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/Behat/Mink/zipball/0817070a6e2ec9f475fad9bfb81a962c462eb934", - "reference": "0817070a6e2ec9f475fad9bfb81a962c462eb934", - "shasum": "" - }, - "require": { - "php": ">=5.3.1", - "symfony/css-selector": ">=2.0,<2.4-dev" - }, - "suggest": { - "behat/mink-browserkit-driver": "extremely fast headless driver for Symfony\\Kernel-based apps (Sf2, Silex)", - "behat/mink-goutte-driver": "fast headless driver for any app without JS emulation", - "behat/mink-selenium2-driver": "slow, but JS-enabled driver for any app (requires Selenium2)", - "behat/mink-zombie-driver": "fast and JS-enabled headless driver for any app (requires node.js)" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-develop": "1.4.x-dev" - } - }, - "autoload": { - "psr-0": { - "Behat\\Mink": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Konstantin Kudryashov", - "email": "ever.zet@gmail.com", - "homepage": "http://everzet.com" - } - ], - "description": "Web acceptance testing framework for PHP 5.3", - "homepage": "http://mink.behat.org/", - "keywords": [ - "browser", - "testing", - "web" - ], - "time": "2013-03-02 15:53:18" - }, - { - "name": "behat/mink-browserkit-driver", - "version": "v1.0.5", - "source": { - "type": "git", - "url": "https://github.com/Behat/MinkBrowserKitDriver.git", - "reference": "f2771b5fc4dbc233859addf37a7d150852f78418" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/Behat/MinkBrowserKitDriver/zipball/f2771b5fc4dbc233859addf37a7d150852f78418", - "reference": "f2771b5fc4dbc233859addf37a7d150852f78418", - "shasum": "" - }, - "require": { - "behat/mink": "~1.4.3", - "php": ">=5.3.1", - "symfony/browser-kit": "~2.0", - "symfony/dom-crawler": "~2.0" - }, - "require-dev": { - "silex/silex": "@dev" - }, - "type": "mink-driver", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "psr-0": { - "Behat\\Mink\\Driver": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Konstantin Kudryashov", - "email": "ever.zet@gmail.com", - "homepage": "http://everzet.com" - } - ], - "description": "Symfony2 BrowserKit driver for Mink framework", - "homepage": "http://mink.behat.org/", - "keywords": [ - "Mink", - "Symfony2", - "browser", - "testing" - ], - "time": "2013-04-13 12:17:15" - }, - { - "name": "behat/mink-goutte-driver", - "version": "v1.0.9", - "source": { - "type": "git", - "url": "https://github.com/Behat/MinkGoutteDriver.git", - "reference": "fa1b073b48761464feb0b05e6825da44b20118d8" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/Behat/MinkGoutteDriver/zipball/fa1b073b48761464feb0b05e6825da44b20118d8", - "reference": "fa1b073b48761464feb0b05e6825da44b20118d8", - "shasum": "" - }, - "require": { - "behat/mink-browserkit-driver": ">=1.0.5,<1.2.0", - "fabpot/goutte": "~1.0.1", - "php": ">=5.3.1" - }, - "type": "mink-driver", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "psr-0": { - "Behat\\Mink\\Driver": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Konstantin Kudryashov", - "email": "ever.zet@gmail.com", - "homepage": "http://everzet.com" - } - ], - "description": "Goutte driver for Mink framework", - "homepage": "http://mink.behat.org/", - "keywords": [ - "browser", - "goutte", - "headless", - "testing" - ], - "time": "2013-07-03 18:43:54" - }, - { "name": "fabpot/goutte", "version": "v1.0.3", "source": { @@ -2428,11 +2269,17 @@ "time": "2014-05-17 21:49:26" } ], - "aliases": [], + "aliases": [ + + ], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": [ + + ], "platform": { "php": ">=5.3.3" }, - "platform-dev": [] + "platform-dev": [ + + ] } diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index fb09bc7057..624ce187b9 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -1324,18 +1324,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $ { delete_topics('topic_id', array($topic_id), false); - if ($data['topic_visibility'] == ITEM_APPROVED) - { - $sql_data[FORUMS_TABLE] .= 'forum_posts_approved = forum_posts_approved - 1, forum_topics_approved = forum_topics_approved - 1'; - } - else if ($data['topic_visibility'] == ITEM_UNAPPROVED || $data['post_visibility'] == ITEM_REAPPROVE) - { - $sql_data[FORUMS_TABLE] .= 'forum_posts_unapproved = forum_posts_unapproved - 1, forum_topics_unapproved = forum_topics_unapproved - 1'; - } - else if ($data['topic_visibility'] == ITEM_DELETED) - { - $sql_data[FORUMS_TABLE] .= 'forum_posts_softdeleted = forum_posts_softdeleted - 1, forum_topics_softdeleted = forum_topics_softdeleted - 1'; - } + $phpbb_content_visibility->remove_topic_from_statistic($data, $sql_data); $update_sql = update_post_information('forum', $forum_id, true); if (sizeof($update_sql)) diff --git a/phpBB/phpbb/content_visibility.php b/phpBB/phpbb/content_visibility.php index da4405d676..8bd537586e 100644 --- a/phpBB/phpbb/content_visibility.php +++ b/phpBB/phpbb/content_visibility.php @@ -570,7 +570,7 @@ class content_visibility * Add post to topic and forum statistics * * @param $data array Contains information from the topics table about given topic - * @param $sql_data array Populated with the SQL changes, may be empty at call time + * @param &$sql_data array Populated with the SQL changes, may be empty at call time * @return null */ public function add_post_to_statistic($data, &$sql_data) @@ -591,7 +591,7 @@ class content_visibility * Remove post from topic and forum statistics * * @param $data array Contains information from the topics table about given topic - * @param $sql_data array Populated with the SQL changes, may be empty at call time + * @param &$sql_data array Populated with the SQL changes, may be empty at call time * @return null */ public function remove_post_from_statistic($data, &$sql_data) @@ -623,64 +623,29 @@ class content_visibility /** * Remove topic from forum statistics * - * @param $topic_id int The topic to act on - * @param $forum_id int Forum where the topic is found - * @param $topic_row array Contains information from the topic, may be empty at call time - * @param $sql_data array Populated with the SQL changes, may be empty at call time + * @param $data array Post and topic data + * @param &$sql_data array Populated with the SQL changes, may be empty at call time * @return null */ - public function remove_topic_from_statistic($topic_id, $forum_id, &$topic_row, &$sql_data) + public function remove_topic_from_statistic($data, &$sql_data) { - // Do we need to grab some topic informations? - if (!sizeof($topic_row)) + if ($data['topic_visibility'] == ITEM_APPROVED) { - $sql = 'SELECT topic_type, topic_posts_approved, topic_posts_unapproved, topic_posts_softdeleted, topic_visibility - FROM ' . $this->topics_table . ' - WHERE topic_id = ' . (int) $topic_id; - $result = $this->db->sql_query($sql); - $topic_row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - } - - // If this is an edited topic or the first post the topic gets completely disapproved later on... - $sql_data[$this->forums_table] = (($sql_data[$this->forums_table]) ? $sql_data[$this->forums_table] . ', ' : '') . 'forum_topics_approved = forum_topics_approved - 1'; - $sql_data[$this->forums_table] .= ', forum_posts_approved = forum_posts_approved - ' . $topic_row['topic_posts_approved']; - $sql_data[$this->forums_table] .= ', forum_posts_unapproved = forum_posts_unapproved - ' . $topic_row['topic_posts_unapproved']; - $sql_data[$this->forums_table] .= ', forum_posts_softdeleted = forum_posts_softdeleted - ' . $topic_row['topic_posts_softdeleted']; + $sql_data[FORUMS_TABLE] .= 'forum_posts_approved = forum_posts_approved - 1, forum_topics_approved = forum_topics_approved - 1'; - $this->config->increment('num_topics', -1, false); - $this->config->increment('num_posts', $topic_row['topic_posts_approved'] * (-1), false); - - // Get user post count information - $sql = 'SELECT poster_id, COUNT(post_id) AS num_posts - FROM ' . $this->posts_table . ' - WHERE topic_id = ' . (int) $topic_id . ' - AND post_postcount = 1 - AND post_visibility = ' . ITEM_APPROVED . ' - GROUP BY poster_id'; - $result = $this->db->sql_query($sql); - - $postcounts = array(); - while ($row = $this->db->sql_fetchrow($result)) + if ($data['post_postcount']) + { + $sql_data[$this->users_table] = ((!empty($sql_data[$this->users_table])) ? $sql_data[$this->users_table] . ', ' : '') . 'user_posts = user_posts - 1'; + } + } + else if ($data['topic_visibility'] == ITEM_UNAPPROVED || $data['post_visibility'] == ITEM_REAPPROVE) { - $postcounts[(int) $row['num_posts']][] = (int) $row['poster_id']; + $sql_data[FORUMS_TABLE] .= 'forum_posts_unapproved = forum_posts_unapproved - 1, forum_topics_unapproved = forum_topics_unapproved - 1'; } - $this->db->sql_freeresult($result); - - // Decrement users post count - foreach ($postcounts as $num_posts => $poster_ids) + else if ($data['topic_visibility'] == ITEM_DELETED) { - $sql = 'UPDATE ' . $this->users_table . ' - SET user_posts = 0 - WHERE user_posts < ' . $num_posts . ' - AND ' . $this->db->sql_in_set('user_id', $poster_ids); - $this->db->sql_query($sql); - - $sql = 'UPDATE ' . $this->users_table . ' - SET user_posts = user_posts - ' . $num_posts . ' - WHERE user_posts >= ' . $num_posts . ' - AND ' . $this->db->sql_in_set('user_id', $poster_ids); - $this->db->sql_query($sql); + $sql_data[FORUMS_TABLE] .= 'forum_posts_softdeleted = forum_posts_softdeleted - 1, forum_topics_softdeleted = forum_topics_softdeleted - 1'; } + } } diff --git a/phpBB/phpbb/notification/type/approve_post.php b/phpBB/phpbb/notification/type/approve_post.php index 0aad19d6bf..22c9076adc 100644 --- a/phpBB/phpbb/notification/type/approve_post.php +++ b/phpBB/phpbb/notification/type/approve_post.php @@ -81,14 +81,7 @@ class approve_post extends \phpbb\notification\type\post $users = array(); $users[$post['poster_id']] = array(''); - $auth_read = $this->auth->acl_get_list(array_keys($users), 'f_read', $post['forum_id']); - - if (empty($auth_read)) - { - return array(); - } - - return $this->check_user_notification_options($auth_read[$post['forum_id']]['f_read'], array_merge($options, array( + return $this->get_authorised_recipients(array_keys($users), $post['forum_id'], array_merge($options, array( 'item_type' => self::$notification_option['id'], ))); } diff --git a/phpBB/phpbb/notification/type/approve_topic.php b/phpBB/phpbb/notification/type/approve_topic.php index e649f3920e..77e53a0064 100644 --- a/phpBB/phpbb/notification/type/approve_topic.php +++ b/phpBB/phpbb/notification/type/approve_topic.php @@ -81,14 +81,7 @@ class approve_topic extends \phpbb\notification\type\topic $users = array(); $users[$post['poster_id']] = array(''); - $auth_read = $this->auth->acl_get_list(array_keys($users), 'f_read', $post['forum_id']); - - if (empty($auth_read)) - { - return array(); - } - - return $this->check_user_notification_options($auth_read[$post['forum_id']]['f_read'], array_merge($options, array( + return $this->get_authorised_recipients(array_keys($users), $post['forum_id'], array_merge($options, array( 'item_type' => self::$notification_option['id'], ))); } diff --git a/phpBB/phpbb/notification/type/base.php b/phpBB/phpbb/notification/type/base.php index a11ad76db9..4ead06071e 100644 --- a/phpBB/phpbb/notification/type/base.php +++ b/phpBB/phpbb/notification/type/base.php @@ -533,4 +533,37 @@ abstract class base implements \phpbb\notification\type\type_interface WHERE ' . $where; $this->db->sql_query($sql); } + + /** + * Get a list of users that are authorised to receive notifications + * + * @param array $users Array of users that have subscribed to a notification + * @param int $forum_id Forum ID of the forum + * @param array $options Array of notification options + * @param bool $sort Whether the users array should be sorted. Default: false + * @return array Array of users that are authorised recipients + */ + protected function get_authorised_recipients($users, $forum_id, $options, $sort = false) + { + if (empty($users)) + { + return array(); + } + + $users = array_unique($users); + + if ($sort) + { + sort($users); + } + + $auth_read = $this->auth->acl_get_list($users, 'f_read', $forum_id); + + if (empty($auth_read)) + { + return array(); + } + + return $this->check_user_notification_options($auth_read[$forum_id]['f_read'], $options); + } } diff --git a/phpBB/phpbb/notification/type/bookmark.php b/phpBB/phpbb/notification/type/bookmark.php index c83288cfb8..21180b3b53 100644 --- a/phpBB/phpbb/notification/type/bookmark.php +++ b/phpBB/phpbb/notification/type/bookmark.php @@ -83,21 +83,13 @@ class bookmark extends \phpbb\notification\type\post } $this->db->sql_freeresult($result); - if (empty($users)) - { - return array(); - } - sort($users); + $notify_users = $this->get_authorised_recipients($users, $post['forum_id'], $options, true); - $auth_read = $this->auth->acl_get_list($users, 'f_read', $post['forum_id']); - - if (empty($auth_read)) + if (empty($notify_users)) { return array(); } - $notify_users = $this->check_user_notification_options($auth_read[$post['forum_id']]['f_read'], $options); - // Try to find the users who already have been notified about replies and have not read the topic since and just update their notifications $update_notifications = array(); $sql = 'SELECT n.* diff --git a/phpBB/phpbb/notification/type/post.php b/phpBB/phpbb/notification/type/post.php index 357176ec35..1eba4a6a88 100644 --- a/phpBB/phpbb/notification/type/post.php +++ b/phpBB/phpbb/notification/type/post.php @@ -123,23 +123,13 @@ class post extends \phpbb\notification\type\base } $this->db->sql_freeresult($result); - if (empty($users)) - { - return array(); - } + $notify_users = $this->get_authorised_recipients($users, $post['forum_id'], $options, true); - $users = array_unique($users); - sort($users); - - $auth_read = $this->auth->acl_get_list($users, 'f_read', $post['forum_id']); - - if (empty($auth_read)) + if (empty($notify_users)) { return array(); } - $notify_users = $this->check_user_notification_options($auth_read[$post['forum_id']]['f_read'], $options); - // Try to find the users who already have been notified about replies and have not read the topic since and just update their notifications $update_notifications = array(); $sql = 'SELECT n.* diff --git a/phpBB/phpbb/notification/type/quote.php b/phpBB/phpbb/notification/type/quote.php index 6e672e6fbd..5c3c822ec2 100644 --- a/phpBB/phpbb/notification/type/quote.php +++ b/phpBB/phpbb/notification/type/quote.php @@ -102,22 +102,7 @@ class quote extends \phpbb\notification\type\post } $this->db->sql_freeresult($result); - if (empty($users)) - { - return array(); - } - sort($users); - - $auth_read = $this->auth->acl_get_list($users, 'f_read', $post['forum_id']); - - if (empty($auth_read)) - { - return array(); - } - - $notify_users = $this->check_user_notification_options($auth_read[$post['forum_id']]['f_read'], $options); - - return $notify_users; + return $this->get_authorised_recipients($users, $post['forum_id'], $options, true); } /** diff --git a/phpBB/phpbb/notification/type/topic.php b/phpBB/phpbb/notification/type/topic.php index 289e45bedb..af199fb765 100644 --- a/phpBB/phpbb/notification/type/topic.php +++ b/phpBB/phpbb/notification/type/topic.php @@ -111,19 +111,7 @@ class topic extends \phpbb\notification\type\base } $this->db->sql_freeresult($result); - if (empty($users)) - { - return array(); - } - - $auth_read = $this->auth->acl_get_list($users, 'f_read', $topic['forum_id']); - - if (empty($auth_read)) - { - return array(); - } - - return $this->check_user_notification_options($auth_read[$topic['forum_id']]['f_read'], $options); + return $this->get_authorised_recipients($users, $topic['forum_id'], $options); } /** diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 2856ba02bb..bb4a703cc3 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -31,5 +31,4 @@ require_once 'test_framework/phpbb_test_case_helpers.php'; 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_mink_test_case.php'; require_once 'test_framework/phpbb_functional_test_case.php'; diff --git a/tests/content_visibility/delete_post_test.php b/tests/content_visibility/delete_post_test.php index aa705c52a5..7f31dd9b28 100644 --- a/tests/content_visibility/delete_post_test.php +++ b/tests/content_visibility/delete_post_test.php @@ -67,6 +67,9 @@ class phpbb_content_visibility_delete_post_test extends phpbb_database_test_case array( array('forum_posts_approved' => 2, 'forum_posts_unapproved' => 0, 'forum_posts_softdeleted' => 0, 'forum_topics_approved' => 1, 'forum_topics_unapproved' => 0, 'forum_topics_softdeleted' => 0, 'forum_last_post_id' => 3), ), + array( + array('user_posts' => 3), + ), ), array( 1, 1, 1, @@ -93,6 +96,9 @@ class phpbb_content_visibility_delete_post_test extends phpbb_database_test_case array( array('forum_posts_approved' => 2, 'forum_posts_unapproved' => 0, 'forum_posts_softdeleted' => 0, 'forum_topics_approved' => 1, 'forum_topics_unapproved' => 0, 'forum_topics_softdeleted' => 0, 'forum_last_post_id' => 3), ), + array( + array('user_posts' => 3), + ), ), array( 1, 1, 3, @@ -119,6 +125,9 @@ class phpbb_content_visibility_delete_post_test extends phpbb_database_test_case array( array('forum_posts_approved' => 2, 'forum_posts_unapproved' => 0, 'forum_posts_softdeleted' => 0, 'forum_topics_approved' => 1, 'forum_topics_unapproved' => 0, 'forum_topics_softdeleted' => 0, 'forum_last_post_id' => 2), ), + array( + array('user_posts' => 3), + ), ), array( 1, 1, 2, @@ -145,6 +154,9 @@ class phpbb_content_visibility_delete_post_test extends phpbb_database_test_case array( array('forum_posts_approved' => 2, 'forum_posts_unapproved' => 0, 'forum_posts_softdeleted' => 1, 'forum_topics_approved' => 1, 'forum_topics_unapproved' => 0, 'forum_topics_softdeleted' => 0, 'forum_last_post_id' => 3), ), + array( + array('user_posts' => 3), + ), ), array( 1, 1, 1, @@ -171,6 +183,9 @@ class phpbb_content_visibility_delete_post_test extends phpbb_database_test_case array( array('forum_posts_approved' => 2, 'forum_posts_unapproved' => 0, 'forum_posts_softdeleted' => 1, 'forum_topics_approved' => 1, 'forum_topics_unapproved' => 0, 'forum_topics_softdeleted' => 0, 'forum_last_post_id' => 3), ), + array( + array('user_posts' => 3), + ), ), array( 1, 1, 3, @@ -197,6 +212,9 @@ class phpbb_content_visibility_delete_post_test extends phpbb_database_test_case array( array('forum_posts_approved' => 2, 'forum_posts_unapproved' => 0, 'forum_posts_softdeleted' => 1, 'forum_topics_approved' => 1, 'forum_topics_unapproved' => 0, 'forum_topics_softdeleted' => 0, 'forum_last_post_id' => 2), ), + array( + array('user_posts' => 3), + ), ), array( @@ -222,6 +240,9 @@ class phpbb_content_visibility_delete_post_test extends phpbb_database_test_case array( 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), ), + array( + array('user_posts' => 3), + ), ), array( @@ -257,6 +278,9 @@ class phpbb_content_visibility_delete_post_test extends phpbb_database_test_case array( array('forum_posts_approved' => 0, 'forum_posts_unapproved' => 0, 'forum_posts_softdeleted' => 1, 'forum_topics_approved' => 0, 'forum_topics_unapproved' => 0, 'forum_topics_softdeleted' => 1, 'forum_last_post_id' => 0), ), + array( + array('user_posts' => 3), + ), ), ); } @@ -264,7 +288,7 @@ class phpbb_content_visibility_delete_post_test extends phpbb_database_test_case /** * @dataProvider delete_post_data */ - public function test_delete_post($forum_id, $topic_id, $post_id, $data, $is_soft, $reason, $expected_posts, $expected_topic, $expected_forum) + public function test_delete_post($forum_id, $topic_id, $post_id, $data, $is_soft, $reason, $expected_posts, $expected_topic, $expected_forum, $expected_user) { global $auth, $cache, $config, $db, $phpbb_container, $phpbb_dispatcher, $phpbb_root_path, $phpEx; @@ -313,5 +337,13 @@ class phpbb_content_visibility_delete_post_test extends phpbb_database_test_case $this->assertEquals($expected_forum, $db->sql_fetchrowset($result)); $db->sql_freeresult($result); + + $sql = 'SELECT user_posts + FROM ' . USERS_TABLE . ' + WHERE user_id = ' . (int) $data['poster_id']; + $result = $db->sql_query($sql); + + $this->assertEquals($expected_user, $db->sql_fetchrowset($result)); + $db->sql_freeresult($result); } } diff --git a/tests/functional/fileupload_form_test.php b/tests/functional/fileupload_form_test.php index 29036c821e..e87953367f 100644 --- a/tests/functional/fileupload_form_test.php +++ b/tests/functional/fileupload_form_test.php @@ -42,8 +42,6 @@ class phpbb_functional_fileupload_form_test extends phpbb_functional_test_case unlink($fileinfo->getPathname()); } - - parent::tearDown(); } private function upload_file($filename, $mimetype) diff --git a/tests/functional/fileupload_remote_test.php b/tests/functional/fileupload_remote_test.php index ef39e1d71b..6ece150b23 100644 --- a/tests/functional/fileupload_remote_test.php +++ b/tests/functional/fileupload_remote_test.php @@ -45,8 +45,6 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case global $config, $user; $user = null; $config = array(); - - parent::tearDown(); } public function test_invalid_extension() diff --git a/tests/functional/forgot_password_test.php b/tests/functional/forgot_password_test.php index c95efc5b2e..64fa19557f 100644 --- a/tests/functional/forgot_password_test.php +++ b/tests/functional/forgot_password_test.php @@ -57,7 +57,5 @@ class phpbb_functional_forgot_password_test extends phpbb_functional_test_case 'config[allow_password_reset]' => 1, )); $crawler = self::submit($form); - - parent::tearDown(); } } diff --git a/tests/functional/plupload_test.php b/tests/functional/plupload_test.php index d9faec035c..ee71597ffc 100644 --- a/tests/functional/plupload_test.php +++ b/tests/functional/plupload_test.php @@ -57,8 +57,6 @@ class phpbb_functional_plupload_test extends phpbb_functional_test_case unlink($fileinfo->getPathname()); } - - parent::tearDown(); } public function get_urls() diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 9bb4d69bf4..80e6293ff9 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -11,12 +11,14 @@ * */ use Symfony\Component\BrowserKit\CookieJar; -use Behat\Mink\Driver\Goutte\Client; -use Behat\Mink\Driver\GoutteDriver; -class phpbb_functional_test_case extends phpbb_mink_test_case +require_once __DIR__ . '/../../phpBB/includes/functions_install.php'; + +class phpbb_functional_test_case extends phpbb_test_case { + static protected $client; static protected $cookieJar; + static protected $root_url; protected $cache = null; protected $db = null; @@ -34,6 +36,7 @@ class phpbb_functional_test_case extends phpbb_mink_test_case */ protected $lang = array(); + static protected $config = array(); static protected $already_installed = false; static public function setUpBeforeClass() @@ -43,24 +46,6 @@ class phpbb_functional_test_case extends phpbb_mink_test_case self::$config = phpbb_test_case_helpers::get_test_config(); self::$root_url = self::$config['phpbb_functional_url']; - self::$cookieJar = new CookieJar; - self::$client = new Client(array(), null, self::$cookieJar); - - $client_options = array( - Guzzle\Http\Client::DISABLE_REDIRECTS => true, - 'curl.options' => array( - CURLOPT_TIMEOUT => 120, - ), - ); - - self::$client->setClient(new Guzzle\Http\Client('', $client_options)); - - // Reset the curl handle because it is 0 at this point and not a valid - // resource - self::$client->getClient()->getCurlMulti()->reset(true); - - self::$driver = new GoutteDriver(self::$client); - // 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 @@ -93,6 +78,12 @@ class phpbb_functional_test_case extends phpbb_mink_test_case $this->bootstrap(); + self::$cookieJar = new CookieJar; + self::$client = new Goutte\Client(array(), null, self::$cookieJar); + // Reset the curl handle because it is 0 at this point and not a valid + // resource + self::$client->getClient()->getCurlMulti()->reset(true); + // Clear the language array so that things // that were added in other tests are gone $this->lang = array(); @@ -119,14 +110,13 @@ class phpbb_functional_test_case extends phpbb_mink_test_case protected function tearDown() { + parent::tearDown(); + if ($this->db instanceof \phpbb\db\driver\driver_interface) { // Close the database connections again this test $this->db->sql_close(); } - - self::$cookieJar->clear(); - parent::tearDown(); } /** @@ -266,6 +256,144 @@ class phpbb_functional_test_case extends phpbb_mink_test_case return $extension_manager; } + static protected 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); + } + } + + self::$cookieJar = new CookieJar; + self::$client = new Goutte\Client(array(), null, self::$cookieJar); + // Set client manually so we can increase the cURL timeout + self::$client->setClient(new Guzzle\Http\Client('', array( + Guzzle\Http\Client::DISABLE_REDIRECTS => true, + 'curl.options' => array( + CURLOPT_TIMEOUT => 120, + ), + ))); + + // Reset the curl handle because it is 0 at this point and not a valid + // resource + self::$client->getClient()->getCurlMulti()->reset(true); + + $parseURL = parse_url(self::$config['phpbb_functional_url']); + + $crawler = self::request('GET', 'install/index.php?mode=install'); + self::assertContains('Welcome to Installation', $crawler->filter('#main')->text()); + $form = $crawler->selectButton('submit')->form(); + + // install/index.php?mode=install&sub=requirements + $crawler = self::submit($form); + self::assertContains('Installation compatibility', $crawler->filter('#main')->text()); + $form = $crawler->selectButton('submit')->form(); + + // install/index.php?mode=install&sub=database + $crawler = self::submit($form); + self::assertContains('Database configuration', $crawler->filter('#main')->text()); + $form = $crawler->selectButton('submit')->form(array( + // Installer uses 3.0-style dbms name + 'dbms' => str_replace('phpbb\db\driver\\', '', self::$config['dbms']), + 'dbhost' => self::$config['dbhost'], + 'dbport' => self::$config['dbport'], + 'dbname' => self::$config['dbname'], + 'dbuser' => self::$config['dbuser'], + 'dbpasswd' => self::$config['dbpasswd'], + 'table_prefix' => self::$config['table_prefix'], + )); + + // install/index.php?mode=install&sub=database + $crawler = self::submit($form); + self::assertContains('Successful connection', $crawler->filter('#main')->text()); + $form = $crawler->selectButton('submit')->form(); + + // install/index.php?mode=install&sub=administrator + $crawler = self::submit($form); + self::assertContains('Administrator configuration', $crawler->filter('#main')->text()); + $form = $crawler->selectButton('submit')->form(array( + 'default_lang' => 'en', + 'admin_name' => 'admin', + 'admin_pass1' => 'adminadmin', + 'admin_pass2' => 'adminadmin', + 'board_email' => 'nobody@example.com', + )); + + // install/index.php?mode=install&sub=administrator + $crawler = self::submit($form); + self::assertContains('Tests passed', $crawler->filter('#main')->text()); + $form = $crawler->selectButton('submit')->form(); + + // We have to skip install/index.php?mode=install&sub=config_file + // because that step will create a config.php file if phpBB has the + // permission to do so. We have to create the config file on 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."); + } + + // We also have to create a install lock that is normally created by + // the installer. The file will be removed by the final step of the + // installer. + $install_lock_file = $phpbb_root_path . 'cache/install_lock'; + $lock_created = file_put_contents($install_lock_file, '') !== false; + if (!$lock_created) + { + self::markTestSkipped("Could not create $lock_created file."); + } + @chmod($install_lock_file, 0666); + + // install/index.php?mode=install&sub=advanced + $form_data = $form->getValues(); + unset($form_data['submit']); + + $crawler = self::request('POST', 'install/index.php?mode=install&sub=advanced', $form_data); + self::assertContains('The settings on this page are only necessary to set if you know that you require something different from the default.', $crawler->filter('#main')->text()); + $form = $crawler->selectButton('submit')->form(array( + 'email_enable' => true, + 'smtp_delivery' => true, + 'smtp_host' => 'nxdomain.phpbb.com', + 'smtp_auth' => 'PLAIN', + 'smtp_user' => 'nxuser', + 'smtp_pass' => 'nxpass', + 'cookie_secure' => false, + 'force_server_vars' => false, + 'server_protocol' => $parseURL['scheme'] . '://', + 'server_name' => 'localhost', + 'server_port' => isset($parseURL['port']) ? (int) $parseURL['port'] : 80, + 'script_path' => $parseURL['path'], + )); + + // install/index.php?mode=install&sub=create_table + $crawler = self::submit($form); + self::assertContains('The database tables used by phpBB', $crawler->filter('#main')->text()); + self::assertContains('have been created and populated with some initial data.', $crawler->filter('#main')->text()); + $form = $crawler->selectButton('submit')->form(); + + // install/index.php?mode=install&sub=final + $crawler = self::submit($form); + self::assertContains('You have successfully installed', $crawler->text()); + + copy($config_file, $config_file_test); + } + public function install_ext($extension) { $this->login(); @@ -284,6 +412,12 @@ class phpbb_functional_test_case extends phpbb_mink_test_case $this->logout(); } + static private function recreate_database($config) + { + $db_conn_mgr = new phpbb_database_test_connection_manager($config); + $db_conn_mgr->recreate_db(); + } + /** * Creates a new style * diff --git a/tests/test_framework/phpbb_mink_test_case.php b/tests/test_framework/phpbb_mink_test_case.php deleted file mode 100644 index ba480e35fb..0000000000 --- a/tests/test_framework/phpbb_mink_test_case.php +++ /dev/null @@ -1,183 +0,0 @@ -<?php -/** -* -* This file is part of the phpBB Forum Software package. -* -* @copyright (c) phpBB Limited <https://www.phpbb.com> -* @license GNU General Public License, version 2 (GPL-2.0) -* -* For full copyright and license information, please see -* the docs/CREDITS.txt file. -* -*/ -use \Behat\Mink\Session; - -require_once __DIR__ . '/../../phpBB/includes/functions_install.php'; - -abstract class phpbb_mink_test_case extends phpbb_test_case -{ - static protected $driver; - static protected $client; - static protected $session; - static protected $config = array(); - static protected $root_url; - - public function __construct($name = null, array $data = array(), $dataName = '') - { - parent::__construct($name, $data, $dataName); - - $this->backupStaticAttributesBlacklist += array( - 'phpbb_mink_test_case' => array('config', 'already_installed'), - ); - } - - static public function setUpBeforeClass() - { - parent::setUpBeforeClass(); - } - - public function setUp() - { - parent::setUp(); - - if (!self::$driver) - { - self::markTestSkipped('Mink driver not initialized.'); - } - - if (!self::$session) - { - self::$session = new Session(self::$driver); - } - } - - static protected function recreate_database($config) - { - $db_conn_mgr = new phpbb_database_test_connection_manager($config); - $db_conn_mgr->recreate_db(); - } - - protected function tearDown() - { - self::$session->reset(); - parent::tearDown(); - } - - static protected function visit($path) - { - self::$session->visit(self::$root_url . $path); - return self::$session->getPage(); - } - - static protected function click_submit($submit_button_id = 'submit') - { - self::$session->getPage()->findById($submit_button_id)->click(); - return self::$session->getPage(); - } - - static protected function install_board() - { - global $phpbb_root_path, $phpEx; - - self::recreate_database(self::$config); - self::$session = new Session(self::$driver); - - $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']); - - $page = self::visit('install/index.php?mode=install'); - self::assertContains('Welcome to Installation', $page->findById('main')->getText()); - - // install/index.php?mode=install&sub=requirements - $page = self::click_submit(); - self::assertContains('Installation compatibility', $page->findById('main')->getText()); - - // install/index.php?mode=install&sub=database - $page = self::click_submit(); - self::assertContains('Database configuration', $page->findById('main')->getText()); - - $page->findById('dbms')->setValue(str_replace('phpbb\db\driver\\', '', self::$config['dbms'])); - $page->findById('dbhost')->setValue(self::$config['dbhost']); - $page->findById('dbport')->setValue(self::$config['dbport']); - $page->findById('dbname')->setValue(self::$config['dbname']); - $page->findById('dbuser')->setValue(self::$config['dbuser']); - $page->findById('dbpasswd')->setValue(self::$config['dbpasswd']); - $page->findById('table_prefix')->setValue(self::$config['table_prefix']); - - // install/index.php?mode=install&sub=database - $page = self::click_submit(); - self::assertContains('Successful connection', $page->findById('main')->getText()); - - // install/index.php?mode=install&sub=administrator - $page = self::click_submit(); - self::assertContains('Administrator configuration', $page->findById('main')->getText()); - - $page->findById('admin_name')->setValue('admin'); - $page->findById('admin_pass1')->setValue('adminadmin'); - $page->findById('admin_pass2')->setValue('adminadmin'); - $page->findById('board_email')->setValue('nobody@example.com'); - - // install/index.php?mode=install&sub=administrator - $page = self::click_submit(); - self::assertContains('Tests passed', $page->findById('main')->getText()); - - // install/index.php?mode=install&sub=config_file - $page = self::click_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($page->findById('main')->getText(), 'The configuration file has been written') === false) - { - $page = self::click_submit('dldone'); - } - self::assertContains('The configuration file has been written', $page->findById('main')->getText()); - - // install/index.php?mode=install&sub=advanced - $page = self::click_submit(); - self::assertContains('The settings on this page are only necessary to set if you know that you require something different from the default.', $page->findById('main')->getText()); - - $page->findById('smtp_delivery')->setValue('1'); - $page->findById('smtp_host')->setValue('nxdomain.phpbb.com'); - $page->findById('smtp_user')->setValue('nxuser'); - $page->findById('smtp_pass')->setValue('nxpass'); - $page->findById('server_protocol')->setValue($parseURL['scheme'] . '://'); - $page->findById('server_name')->setValue('localhost'); - $page->findById('server_port')->setValue(isset($parseURL['port']) ? $parseURL['port'] : 80); - $page->findById('script_path')->setValue($parseURL['path']); - - // install/index.php?mode=install&sub=create_table - $page = self::click_submit(); - self::assertContains('The database tables used by phpBB', $page->findById('main')->getText()); - self::assertContains('have been created and populated with some initial data.', $page->findById('main')->getText()); - - // install/index.php?mode=install&sub=final - $page = self::click_submit(); - self::assertContains('You have successfully installed', $page->getText()); - - copy($config_file, $config_file_test); - - self::$session->stop(); - } -} diff --git a/travis/check-executable-files.sh b/travis/check-executable-files.sh index 1d8b33d327..4d420add1c 100755 --- a/travis/check-executable-files.sh +++ b/travis/check-executable-files.sh @@ -27,7 +27,7 @@ then files_skipped="-false" # Files which have to be executable - executable_files="-path ${path}bin/* -o -path ${root}composer.phar" + executable_files="-path ${path}bin/*" incorrect_files=$( \ find ${path} \ diff --git a/travis/setup-php-extensions.sh b/travis/setup-php-extensions.sh index 3655d6e952..c0defe44ef 100755 --- a/travis/setup-php-extensions.sh +++ b/travis/setup-php-extensions.sh @@ -42,12 +42,6 @@ function install_php_extension php_ini_file=$(find_php_ini) -# disable broken opcache on PHP 5.5.7 and 5.5.8 -if [ `php -r "echo (int) version_compare(PHP_VERSION, '5.5.9', '<');"` == "1" ] -then - sed -i '/opcache.so/d' "$php_ini_file" -fi - # apc if [ `php -r "echo (int) version_compare(PHP_VERSION, '5.5.0-dev', '<');"` == "1" ] then diff --git a/travis/setup-webserver.sh b/travis/setup-webserver.sh index ea1929a5b0..ab045431cc 100755 --- a/travis/setup-webserver.sh +++ b/travis/setup-webserver.sh @@ -72,8 +72,11 @@ echo " index index.php index.html; location ~ \.php { - fastcgi_pass unix:$APP_SOCK; - include fastcgi_params; + include fastcgi_params; + fastcgi_split_path_info ^(.+\.php)(/.*)$; + fastcgi_param PATH_INFO \$fastcgi_path_info; + fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name; + fastcgi_pass unix:$APP_SOCK; } } " | sudo tee $NGINX_CONF > /dev/null |