diff --git a/phpBB/adm/style/acp_main.html b/phpBB/adm/style/acp_main.html index 6e28c7a0cc..9a9b3ff2b9 100644 --- a/phpBB/adm/style/acp_main.html +++ b/phpBB/adm/style/acp_main.html @@ -17,6 +17,7 @@

{L_VERSIONCHECK_FAIL}

+

{VERSIONCHECK_FAIL_REASON}

{L_VERSIONCHECK_FORCE_UPDATE} · {L_MORE_INFORMATION}

diff --git a/phpBB/adm/style/acp_update.html b/phpBB/adm/style/acp_update.html index 00d37515b3..0cc995959b 100644 --- a/phpBB/adm/style/acp_update.html +++ b/phpBB/adm/style/acp_update.html @@ -1,52 +1,46 @@ - - -

{L_VERSION_CHECK}

+

{L_VERSION_CHECK}

-

{L_VERSION_CHECK_EXPLAIN}

+

{L_VERSION_CHECK_EXPLAIN}

- -
-

{L_VERSION_UP_TO_DATE_ACP} - {L_VERSIONCHECK_FORCE_UPDATE}

-
- -
-

{L_VERSION_NOT_UP_TO_DATE_ACP} - {L_VERSIONCHECK_FORCE_UPDATE}

-
- + +
+

{L_VERSION_UP_TO_DATE_ACP} - {L_VERSIONCHECK_FORCE_UPDATE}

+
+ +
+

{L_VERSION_NOT_UP_TO_DATE_ACP} - {L_VERSIONCHECK_FORCE_UPDATE}

+
+ - -
-

{UPGRADE_INSTRUCTIONS}

-
- - -
- +
+
-
{AUTO_VERSION}{CURRENT_VERSION}
-
-
-
-
{LATEST_VERSION}
+
{CURRENT_VERSION}
+
+ + +
+ +
+
+
{updates_available.current}
+
+
+
+
{updates_available.announcement}
+
+ - - {L_UPDATE_INSTRUCTIONS_INCOMPLETE} -

- {UPDATE_INSTRUCTIONS} -

- - - {UPDATE_INSTRUCTIONS} -

- - + + {UPDATE_INSTRUCTIONS} +

diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml index 2cf9dbed3e..90a2f3b187 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/services.yml @@ -324,3 +324,11 @@ services: - %core.root_path% - %core.php_ext% - %tables.users% + + version_helper: + class: phpbb\version_helper + scope: prototype + arguments: + - @cache + - @config + - @user diff --git a/phpBB/includes/acp/acp_main.php b/phpBB/includes/acp/acp_main.php index f01cba0bcc..fd45027b49 100644 --- a/phpBB/includes/acp/acp_main.php +++ b/phpBB/includes/acp/acp_main.php @@ -25,7 +25,7 @@ class acp_main function main($id, $mode) { global $config, $db, $cache, $user, $auth, $template, $request; - global $phpbb_root_path, $phpbb_admin_path, $phpEx; + global $phpbb_root_path, $phpbb_admin_path, $phpEx, $phpbb_container; // Show restore permissions notice if ($user->data['user_perm_from'] && $auth->acl_get('a_switchperm')) @@ -432,17 +432,19 @@ class acp_main )); } - $latest_version_info = false; - if (($latest_version_info = obtain_latest_version_info(request_var('versioncheck_force', false))) === false) + $version_helper = $phpbb_container->get('version_helper'); + try { - $template->assign_var('S_VERSIONCHECK_FAIL', true); - } - else - { - $latest_version_info = explode("\n", $latest_version_info); + $recheck = $request->variable('versioncheck_force', false); + $updates_available = $version_helper->get_suggested_updates($recheck); + $template->assign_var('S_VERSION_UP_TO_DATE', empty($updates_available)); + } + catch (\RuntimeException $e) + { $template->assign_vars(array( - 'S_VERSION_UP_TO_DATE' => phpbb_version_compare(trim($latest_version_info[0]), $config['version'], '<='), + 'S_VERSIONCHECK_FAIL' => true, + 'VERSIONCHECK_FAIL_REASON' => ($e->getMessage() !== $user->lang('VERSIONCHECK_FAIL')) ? $e->getMessage() : '', )); } diff --git a/phpBB/includes/acp/acp_update.php b/phpBB/includes/acp/acp_update.php index 6b5407067d..e50409bd37 100644 --- a/phpBB/includes/acp/acp_update.php +++ b/phpBB/includes/acp/acp_update.php @@ -24,64 +24,42 @@ class acp_update function main($id, $mode) { - global $config, $db, $user, $auth, $template, $cache; - global $phpbb_root_path, $phpbb_admin_path, $phpEx; + global $config, $user, $template, $request; + global $phpbb_root_path, $phpEx, $phpbb_container; $user->add_lang('install'); $this->tpl_name = 'acp_update'; $this->page_title = 'ACP_VERSION_CHECK'; - // Get current and latest version - $errstr = ''; - $errno = 0; - - $info = obtain_latest_version_info(request_var('versioncheck_force', false)); - - if (empty($info)) + $version_helper = $phpbb_container->get('version_helper'); + try { - trigger_error('VERSIONCHECK_FAIL', E_USER_WARNING); + $recheck = $request->variable('versioncheck_force', false); + $updates_available = $version_helper->get_suggested_updates($recheck); + } + catch (\RuntimeException $e) + { + $template->assign_var('S_VERSIONCHECK_FAIL', true); + + $updates_available = array(); } - $info = explode("\n", $info); - $latest_version = trim($info[0]); + foreach ($updates_available as $branch => $version_data) + { + $template->assign_block_vars('updates_available', $version_data); + } - $announcement_url = trim($info[1]); - $announcement_url = (strpos($announcement_url, '&') === false) ? str_replace('&', '&', $announcement_url) : $announcement_url; $update_link = append_sid($phpbb_root_path . 'install/index.' . $phpEx, 'mode=update'); - // next feature release - $next_feature_version = $next_feature_announcement_url = false; - if (isset($info[2]) && trim($info[2]) !== '') - { - $next_feature_version = trim($info[2]); - $next_feature_announcement_url = trim($info[3]); - } - - // Determine automatic update... - $sql = 'SELECT config_value - FROM ' . CONFIG_TABLE . " - WHERE config_name = 'version_update_from'"; - $result = $db->sql_query($sql); - $version_update_from = (string) $db->sql_fetchfield('config_value'); - $db->sql_freeresult($result); - - $current_version = (!empty($version_update_from)) ? $version_update_from : $config['version']; - $template->assign_vars(array( - 'S_UP_TO_DATE' => phpbb_version_compare($latest_version, $config['version'], '<='), - 'S_UP_TO_DATE_AUTO' => phpbb_version_compare($latest_version, $current_version, '<='), - 'S_VERSION_CHECK' => true, - 'U_ACTION' => $this->u_action, - 'U_VERSIONCHECK_FORCE' => append_sid($this->u_action . '&versioncheck_force=1'), + 'S_UP_TO_DATE' => empty($updates_available), + 'U_ACTION' => $this->u_action, + 'U_VERSIONCHECK_FORCE' => append_sid($this->u_action . '&versioncheck_force=1'), - 'LATEST_VERSION' => $latest_version, - 'CURRENT_VERSION' => $config['version'], - 'AUTO_VERSION' => $version_update_from, - 'NEXT_FEATURE_VERSION' => $next_feature_version, + 'CURRENT_VERSION' => $config['version'], - 'UPDATE_INSTRUCTIONS' => sprintf($user->lang['UPDATE_INSTRUCTIONS'], $announcement_url, $update_link), - 'UPGRADE_INSTRUCTIONS' => $next_feature_version ? $user->lang('UPGRADE_INSTRUCTIONS', $next_feature_version, $next_feature_announcement_url) : false, + 'UPDATE_INSTRUCTIONS' => sprintf($user->lang['UPDATE_INSTRUCTIONS'], $update_link), )); } } diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index 0e28b48d8a..b31b268db7 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -3041,7 +3041,7 @@ function get_remote_file($host, $directory, $filename, &$errstr, &$errno, $port return $file_info; } -/** +/* * Tidy Warnings * Remove all warnings which have now expired from the database * The duration of a warning can be defined by the administrator @@ -3150,45 +3150,6 @@ function add_permission_language() } } -/** - * Obtains the latest version information - * - * @param bool $force_update Ignores cached data. Defaults to false. - * @param bool $warn_fail Trigger a warning if obtaining the latest version information fails. Defaults to false. - * @param int $ttl Cache version information for $ttl seconds. Defaults to 86400 (24 hours). - * - * @return string | false Version info on success, false on failure. - */ -function obtain_latest_version_info($force_update = false, $warn_fail = false, $ttl = 86400) -{ - global $cache; - - $info = $cache->get('versioncheck'); - - if ($info === false || $force_update) - { - $errstr = ''; - $errno = 0; - - $info = get_remote_file('version.phpbb.com', '/phpbb', - ((defined('PHPBB_QA')) ? '30x_qa.txt' : '30x.txt'), $errstr, $errno); - - if (empty($info)) - { - $cache->destroy('versioncheck'); - if ($warn_fail) - { - trigger_error($errstr, E_USER_WARNING); - } - return false; - } - - $cache->put('versioncheck', $info, $ttl); - } - - return $info; -} - /** * Enables a particular flag in a bitfield column of a given table. * diff --git a/phpBB/install/install_update.php b/phpBB/install/install_update.php index dc6e57c851..5891efb375 100644 --- a/phpBB/install/install_update.php +++ b/phpBB/install/install_update.php @@ -154,14 +154,23 @@ class install_update extends module )); // Get current and latest version - if (($latest_version = $cache->get('_version_info')) === false) + $version_helper = $phpbb_container->get('version_helper'); + try { - $this->latest_version = $this->get_file('version_info'); - $cache->put('_version_info', $this->latest_version); + $this->latest_version = $version_helper->get_latest_on_current_branch(true); } - else + catch (\RuntimeException $e) { - $this->latest_version = $latest_version; + $this->latest_version = false; + + $update_info = array(); + include($phpbb_root_path . 'install/update/index.' . $phpEx); + $info = (empty($update_info) || !is_array($update_info)) ? false : $update_info; + + if ($info !== false) + { + $this->latest_version = (!empty($info['version']['to'])) ? trim($info['version']['to']) : false; + } } // For the current version we trick a bit. ;) @@ -1606,37 +1615,6 @@ class install_update extends module switch ($mode) { - case 'version_info': - global $phpbb_root_path, $phpEx; - - $info = get_remote_file('version.phpbb.com', '/phpbb', - ((defined('PHPBB_QA')) ? '30x_qa.txt' : '30x.txt'), $errstr, $errno); - - if ($info !== false) - { - $info = explode("\n", $info); - $info = trim($info[0]); - } - - if ($this->test_update !== false) - { - $info = $this->test_update; - } - - // If info is false the fsockopen function may not be working. Instead get the latest version from our update file (and pray it is up-to-date) - if ($info === false) - { - $update_info = array(); - include($phpbb_root_path . 'install/update/index.' . $phpEx); - $info = (empty($update_info) || !is_array($update_info)) ? false : $update_info; - - if ($info !== false) - { - $info = (!empty($info['version']['to'])) ? trim($info['version']['to']) : false; - } - } - break; - case 'update_info': global $phpbb_root_path, $phpEx; diff --git a/phpBB/language/en/install.php b/phpBB/language/en/install.php index 03c9562983..081361f661 100644 --- a/phpBB/language/en/install.php +++ b/phpBB/language/en/install.php @@ -490,6 +490,7 @@ $lang = array_merge($lang, array( 'PREVIOUS_VERSION' => 'Previous version', 'PROGRESS' => 'Progress', + 'RELEASE_ANNOUNCEMENT' => 'Announcement', 'RESULT' => 'Result', 'RUN_DATABASE_SCRIPT' => 'Update my database now', @@ -532,7 +533,7 @@ $lang = array_merge($lang, array(

Release announcement

-

Please read the release announcement for the latest version before you continue your update process, it may contain useful information. It also contains full download links as well as the change log.

+

Please read the release announcement for the latest version before you continue your update process, it may contain useful information. It also contains full download links as well as the change log.


@@ -547,17 +548,11 @@ $lang = array_merge($lang, array(

Once uploaded your board will be offline for normal users due to the install directory you uploaded now present.

- Now start the update process by pointing your browser to the install folder.
+ Now start the update process by pointing your browser to the install folder.

You will then be guided through the update process. You will be notified once the update is complete.

', - 'UPDATE_INSTRUCTIONS_INCOMPLETE' => ' - -

Incomplete update detected

- -

phpBB detected an incomplete automatic update. Please make sure you followed every step within the automatic update tool. Below you will find the link again, or go directly to your install directory.

- ', 'UPDATE_METHOD' => 'Update method', 'UPDATE_METHOD_EXPLAIN' => 'You are now able to choose your preferred update method. Using the FTP upload will present you with a form you need to enter your FTP account details into. With this method the files will be automatically moved to the new location and backups of the old files being created by appending .bak to the filename. If you choose to download the modified files you are able to unpack and upload them to their correct location manually later.', 'UPDATE_REQUIRES_FILE' => 'The updater requires that the following file is present: %s', @@ -567,7 +562,6 @@ $lang = array_merge($lang, array( 'UPDATING_DATA' => 'Updating data', 'UPDATING_TO_LATEST_STABLE' => 'Updating database to latest stable release', 'UPDATED_VERSION' => 'Updated version', - 'UPGRADE_INSTRUCTIONS' => 'A new feature release %1$s is available. Please read the release announcement to learn about what it has to offer, and how to upgrade.', 'UPLOAD_METHOD' => 'Upload method', 'UPDATE_DB_SUCCESS' => 'Database update was successful.', diff --git a/phpBB/phpbb/version_helper.php b/phpBB/phpbb/version_helper.php new file mode 100644 index 0000000000..e2fdf6ce63 --- /dev/null +++ b/phpBB/phpbb/version_helper.php @@ -0,0 +1,271 @@ +cache = $cache; + $this->config = $config; + $this->user = $user; + + if (defined('PHPBB_QA')) + { + $this->force_stability = 'unstable'; + } + + $this->current_version = $this->config['version']; + } + + /** + * Set location to the file + * + * @param string $host Host (e.g. version.phpbb.com) + * @param string $path Path to file (e.g. /phpbb) + * @param string $file File name (Default: versions.json) + * @return version_helper + */ + public function set_file_location($host, $path, $file = 'versions.json') + { + $this->host = $host; + $this->path = $path; + $this->file = $file; + + return $this; + } + + /** + * Set current version + * + * @param string $version The current version + * @return version_helper + */ + public function set_current_version($version) + { + $this->current_version = $version; + + return $this; + } + + /** + * Over-ride the stability to force check to include unstable versions + * + * @param null|string Null to not force stability, 'unstable' or 'stable' to + * force the corresponding stability + * @return version_helper + */ + public function force_stability($stability) + { + $this->force_stability = $stability; + + return $this; + } + + /** + * Wrapper for version_compare() that allows using uppercase A and B + * for alpha and beta releases. + * + * See http://www.php.net/manual/en/function.version-compare.php + * + * @param string $version1 First version number + * @param string $version2 Second version number + * @param string $operator Comparison operator (optional) + * + * @return mixed Boolean (true, false) if comparison operator is specified. + * Integer (-1, 0, 1) otherwise. + */ + public function compare($version1, $version2, $operator = null) + { + return phpbb_version_compare($version1, $version2, $operator); + } + + /** + * Check whether or not a version is "stable" + * + * Stable means only numbers OR a pl release + * + * @param string $version + * @return bool Bool true or false + */ + public function is_stable($version) + { + $matches = false; + preg_match('/^[\d\.]+/', $version, $matches); + + if (empty($matches[0])) + { + return false; + } + + return $this->compare($version, $matches[0], '>='); + } + + /** + * Gets the latest version for the current branch the user is on + * + * @param bool $force_update Ignores cached data. Defaults to false. + * @return string + * @throws \RuntimeException + */ + public function get_latest_on_current_branch($force_update = false) + { + $versions = $this->get_versions_matching_stability($force_update); + + $self = $this; + $current_version = $this->current_version; + + // Filter out any versions less than to the current version + $versions = array_filter($versions, function($data) use ($self, $current_version) { + return $self->compare($data['current'], $current_version, '>='); + }); + + // Get the lowest version from the previous list. + return array_reduce($versions, function($value, $data) use ($self) { + if ($value === null || $self->compare($data['current'], $value, '<')) + { + return $data['current']; + } + + return $value; + }); + } + + /** + * Obtains the latest version information + * + * @param bool $force_update Ignores cached data. Defaults to false. + * @return string + * @throws \RuntimeException + */ + public function get_suggested_updates($force_update = false) + { + $versions = $this->get_versions_matching_stability($force_update); + + $self = $this; + $current_version = $this->current_version; + + // Filter out any versions less than or equal to the current version + return array_filter($versions, function($data) use ($self, $current_version) { + return $self->compare($data['current'], $current_version, '>'); + }); + } + + /** + * Obtains the latest version information matching the stability of the current install + * + * @param bool $force_update Ignores cached data. Defaults to false. + * @return string Version info + * @throws \RuntimeException + */ + public function get_versions_matching_stability($force_update = false) + { + $info = $this->get_versions($force_update); + + if ($this->force_stability !== null) + { + return ($this->force_stability === 'unstable') ? $info['unstable'] : $info['stable']; + } + + return ($this->is_stable($this->current_version)) ? $info['stable'] : $info['unstable']; + } + + /** + * Obtains the latest version information + * + * @param bool $force_update Ignores cached data. Defaults to false. + * @return string Version info, includes stable and unstable data + * @throws \RuntimeException + */ + public function get_versions($force_update = false) + { + $cache_file = 'versioncheck_' . $this->host . $this->path . $this->file; + + $info = $this->cache->get($cache_file); + + if ($info === false || $force_update) + { + $errstr = $errno = ''; + $info = get_remote_file($this->host, $this->path, $this->file, $errstr, $errno); + + if (!empty($errstr)) + { + throw new \RuntimeException($errstr); + } + + $info = json_decode($info, true); + + if (empty($info['stable']) || empty($info['unstable'])) + { + $this->user->add_lang('acp/common'); + + throw new \RuntimeException($this->user->lang('VERSIONCHECK_FAIL')); + } + + // Replace & with & on announcement links + foreach ($info as $stability => $branches) + { + foreach ($branches as $branch => $branch_data) + { + $info[$stability][$branch]['announcement'] = str_replace('&', '&', $branch_data['announcement']); + } + } + + $this->cache->put($cache_file, $info, 86400); // 24 hours + } + + return $info; + } +} diff --git a/tests/version/version_fetch_test.php b/tests/version/version_fetch_test.php new file mode 100644 index 0000000000..7b3ba5e717 --- /dev/null +++ b/tests/version/version_fetch_test.php @@ -0,0 +1,58 @@ +cache = $this->getMockBuilder('\phpbb\cache\service') + ->disableOriginalConstructor() + ->getMock(); + + $this->version_helper = new \phpbb\version_helper( + $this->cache, + new \phpbb\config\config(array( + 'version' => '3.1.0', + )), + new \phpbb\user() + ); + } + + public function test_version_phpbb_com() + { + global $phpbb_root_path, $phpEx; + include_once($phpbb_root_path . 'includes/functions.' . $phpEx); + + if (!phpbb_checkdnsrr('version.phpbb.com', 'A')) + { + $this->markTestSkipped(sprintf( + 'Could not find a DNS record for hostname %s. ' . + 'Assuming network is down.', + 'version.phpbb.com' + )); + } + + $this->version_helper->get_versions(); + + // get_versions checks to make sure we got a valid versions file or + // throws an exception if we did not. We don't need to test anything + // here, but adding an assertion so we do not get a warning about no + // assertions in this test + $this->assertSame(true, true); + } +} diff --git a/tests/version/version_test.php b/tests/version/version_test.php new file mode 100644 index 0000000000..2e2398bd45 --- /dev/null +++ b/tests/version/version_test.php @@ -0,0 +1,318 @@ +cache = $this->getMockBuilder('\phpbb\cache\service') + ->disableOriginalConstructor() + ->getMock(); + + $this->version_helper = new \phpbb\version_helper( + $this->cache, + new \phpbb\config\config(array( + 'version' => '3.1.0', + )), + new \phpbb\user() + ); + } + + public function is_stable_data() + { + return array( + array( + '3.0.0-a1', + false, + ), + array( + '3.0.0-b1', + false, + ), + array( + '3.0.0-rc1', + false, + ), + array( + '3.0.0-RC1', + false, + ), + array( + '3.0.0', + true, + ), + array( + '3.0.0-pl1', + true, + ), + array( + '3.0.0.1-pl1', + true, + ), + array( + '3.1-dev', + false, + ), + array( + 'foobar', + false, + ), + ); + } + + /** + * @dataProvider is_stable_data + */ + public function test_is_stable($version, $expected) + { + $this->assertSame($expected, $this->version_helper->is_stable($version)); + } + + public function get_suggested_updates_data() + { + return array( + array( + '1.0.0', + array( + '1.0' => array( + 'current' => '1.0.1', + ), + '1.1' => array( + 'current' => '1.1.1', + ), + ), + array( + '1.0' => array( + 'current' => '1.0.1', + ), + '1.1' => array( + 'current' => '1.1.1', + ), + ), + ), + array( + '1.0.1', + array( + '1.0' => array( + 'current' => '1.0.1', + ), + '1.1' => array( + 'current' => '1.1.1', + ), + ), + array( + '1.1' => array( + 'current' => '1.1.1', + ), + ), + ), + array( + '1.0.1-a1', + array( + '1.0' => array( + 'current' => '1.0.1-a2', + ), + '1.1' => array( + 'current' => '1.1.0', + ), + ), + array( + '1.0' => array( + 'current' => '1.0.1-a2', + ), + '1.1' => array( + 'current' => '1.1.0', + ), + ), + ), + array( + '1.1.0', + array( + '1.0' => array( + 'current' => '1.0.1', + ), + '1.1' => array( + 'current' => '1.1.1', + ), + ), + array( + '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( + '1.1' => array( + 'current' => '1.1.0-a2', + ), + ), + ), + ); + } + + /** + * @dataProvider get_suggested_updates_data + */ + public function test_get_suggested_updates($current_version, $versions, $expected) + { + $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\user(), + )) + ->getMock() + ; + + $version_helper->expects($this->any()) + ->method('get_versions_matching_stability') + ->will($this->returnValue($versions)); + + $this->assertSame($expected, $version_helper->get_suggested_updates()); + } + + public function get_latest_on_current_branch_data() + { + return array( + array( + '1.0.0', + array( + '1.0' => array( + 'current' => '1.0.1', + ), + '1.1' => array( + 'current' => '1.1.1', + ), + ), + '1.0.1', + ), + array( + '1.0.1', + array( + '1.0' => array( + 'current' => '1.0.1', + ), + '1.1' => array( + 'current' => '1.1.1', + ), + ), + '1.0.1', + ), + array( + '1.0.1-a1', + array( + '1.0' => array( + 'current' => '1.0.1-a2', + ), + '1.1' => array( + 'current' => '1.1.0', + ), + ), + '1.0.1-a2', + ), + array( + '1.1.0', + array( + '1.0' => array( + 'current' => '1.0.1', + ), + '1.1' => array( + 'current' => '1.1.1', + ), + ), + '1.1.1', + ), + array( + '1.1.1', + array( + '1.0' => array( + 'current' => '1.0.1', + ), + '1.1' => array( + 'current' => '1.1.1', + ), + ), + '1.1.1', + ), + array( + '1.1.0-a1', + array( + '1.0' => array( + 'current' => '1.0.1', + ), + '1.1' => array( + 'current' => '1.1.0-a2', + ), + ), + '1.1.0-a2', + ), + ); + } + + /** + * @dataProvider get_latest_on_current_branch_data + */ + public function test_get_latest_on_current_branch($current_version, $versions, $expected) + { + $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\user(), + )) + ->getMock() + ; + + $version_helper->expects($this->any()) + ->method('get_versions_matching_stability') + ->will($this->returnValue($versions)); + + $this->assertSame($expected, $version_helper->get_latest_on_current_branch()); + } +}