mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-08 04:18:52 +00:00
Merge remote-tracking branch 'github-bantu/ticket/10263' into develop-olympus
* github-bantu/ticket/10263: [ticket/10263] Call phpbb_version_compare() from includes/acp/acp_main.php [ticket/10263] Call phpbb_version_compare() from includes/acp/acp_update.php [ticket/10263] Adding unit tests for phpbb_version_compare(). [ticket/10263] Add wrapper for version_compare() that allows the use of A and B
This commit is contained in:
commit
82fa4eff7e
4 changed files with 161 additions and 9 deletions
|
@ -415,11 +415,8 @@ class acp_main
|
|||
{
|
||||
$latest_version_info = explode("\n", $latest_version_info);
|
||||
|
||||
$latest_version = str_replace('rc', 'RC', strtolower(trim($latest_version_info[0])));
|
||||
$current_version = str_replace('rc', 'RC', strtolower($config['version']));
|
||||
|
||||
$template->assign_vars(array(
|
||||
'S_VERSION_UP_TO_DATE' => version_compare($current_version, $latest_version, '<') ? false : true,
|
||||
'S_VERSION_UP_TO_DATE' => phpbb_version_compare(trim($latest_version_info[0]), $config['version'], '<='),
|
||||
));
|
||||
}
|
||||
|
||||
|
|
|
@ -69,12 +69,9 @@ class acp_update
|
|||
|
||||
$current_version = (!empty($version_update_from)) ? $version_update_from : $config['version'];
|
||||
|
||||
$up_to_date_automatic = (version_compare(str_replace('rc', 'RC', strtolower($current_version)), str_replace('rc', 'RC', strtolower($latest_version)), '<')) ? false : true;
|
||||
$up_to_date = (version_compare(str_replace('rc', 'RC', strtolower($config['version'])), str_replace('rc', 'RC', strtolower($latest_version)), '<')) ? false : true;
|
||||
|
||||
$template->assign_vars(array(
|
||||
'S_UP_TO_DATE' => $up_to_date,
|
||||
'S_UP_TO_DATE_AUTO' => $up_to_date_automatic,
|
||||
'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'),
|
||||
|
|
|
@ -619,6 +619,34 @@ function phpbb_email_hash($email)
|
|||
return sprintf('%u', crc32(strtolower($email))) . strlen($email);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 Integer (-1, 0, 1) if comparison operator is specified.
|
||||
* Boolean (true, false) otherwise.
|
||||
*/
|
||||
function phpbb_version_compare($version1, $version2, $operator = null)
|
||||
{
|
||||
$version1 = strtolower($version1);
|
||||
$version2 = strtolower($version2);
|
||||
|
||||
if (is_null($operator))
|
||||
{
|
||||
return version_compare($version1, $version2);
|
||||
}
|
||||
else
|
||||
{
|
||||
return version_compare($version1, $version2, $operator);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Global function for chmodding directories and files for internal use
|
||||
*
|
||||
|
|
130
tests/wrapper/version_compare_test.php
Normal file
130
tests/wrapper/version_compare_test.php
Normal file
|
@ -0,0 +1,130 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2011 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
|
||||
|
||||
class phpbb_wrapper_version_compare_test extends phpbb_test_case
|
||||
{
|
||||
public function test_two_parameters()
|
||||
{
|
||||
$this->assertEquals(-1, phpbb_version_compare('1.0.0', '1.0.1'));
|
||||
$this->assertEquals(0, phpbb_version_compare('1.0.0', '1.0.0'));
|
||||
$this->assertEquals(1, phpbb_version_compare('1.0.1', '1.0.0'));
|
||||
}
|
||||
|
||||
public function test_three_parameters()
|
||||
{
|
||||
$this->assertEquals(true, phpbb_version_compare('1.0.0', '1.0.1', '<'));
|
||||
$this->assertEquals(true, phpbb_version_compare('1.0.0', '1.0.0', '<='));
|
||||
$this->assertEquals(true, phpbb_version_compare('1.0.0', '1.0.0', '='));
|
||||
$this->assertEquals(true, phpbb_version_compare('1.0.0', '1.0.0', '>='));
|
||||
$this->assertEquals(true, phpbb_version_compare('1.0.1', '1.0.0', '>'));
|
||||
}
|
||||
|
||||
public function test_strict_order()
|
||||
{
|
||||
$releases = array(
|
||||
'2.0.0',
|
||||
'2.0.1',
|
||||
// Those are not version_compare() compatible
|
||||
//'2.0.6a',
|
||||
//'2.0.6b',
|
||||
//'2.0.6c',
|
||||
//'2.0.6d',
|
||||
'2.0.7',
|
||||
'2.0.23',
|
||||
'3.0.A1',
|
||||
'3.0.A2',
|
||||
'3.0.A3',
|
||||
'3.0.B1',
|
||||
'3.0.B2',
|
||||
'3.0.B4',
|
||||
'3.0.B5',
|
||||
'3.0.RC1',
|
||||
'3.0.RC5',
|
||||
'3.0.0',
|
||||
'3.0.1',
|
||||
'3.0.2',
|
||||
'3.0.7',
|
||||
'3.0.7-PL1',
|
||||
'3.0.8-RC1',
|
||||
'3.0.8',
|
||||
'3.0.9-dev',
|
||||
'3.0.9-RC1',
|
||||
'3.0.9-RC2',
|
||||
'3.0.9-RC4',
|
||||
'3.0.10-RC1',
|
||||
'3.1-dev',
|
||||
'3.2-A1',
|
||||
);
|
||||
|
||||
for ($i = 0, $size = sizeof($releases); $i < $size - 1; ++$i)
|
||||
{
|
||||
$version1 = $releases[$i];
|
||||
$version2 = $releases[$i + 1];
|
||||
|
||||
$this->assertEquals(
|
||||
true,
|
||||
phpbb_version_compare($version1, $version2, '<'),
|
||||
"Result of version comparison $version1 < $version2 is incorrect."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider equality_test_data
|
||||
*/
|
||||
public function test_equality($version1, $version2)
|
||||
{
|
||||
$this->assertEquals(
|
||||
0,
|
||||
phpbb_version_compare($version1, $version2),
|
||||
"Result of version comparison $version1 = $version2 is incorrect."
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
true,
|
||||
phpbb_version_compare($version1, $version2, '='),
|
||||
"Result of version comparison $version1 = $version2 is incorrect."
|
||||
);
|
||||
}
|
||||
|
||||
public function equality_test_data()
|
||||
{
|
||||
return array(
|
||||
array('1.1.0-A2', '1.1.0-a2'),
|
||||
array('1.1.0-B1', '1.1.0-b1'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider alpha_beta_test_data
|
||||
*/
|
||||
public function test_alpha_beta($expected, $version1, $version2)
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
phpbb_version_compare($version1, $version2),
|
||||
"Result of version comparison ($version1, $version2) = $expected is incorrect."
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public function alpha_beta_test_data()
|
||||
{
|
||||
return array(
|
||||
array(-1, '1.1.0-A2', '1.1.0-B1'),
|
||||
array(-1, '1.1.0-a2', '1.1.0-b1'),
|
||||
|
||||
array(-1, '1.1.0-a2', '1.1.0-B1'),
|
||||
array(-1, '1.1.0-A2', '1.1.0-b1'),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue