Commit 25d48a83 by Scott

Fix Q2A/PHP version checks

Corrects 1.8.0-beta and 1.8.0 being treated as the same version.
parent 80e735df
......@@ -80,6 +80,7 @@ if (!isset($qa_autoconnect) || $qa_autoconnect !== false) {
/**
* Converts the $version string (e.g. 1.6.2.2) to a floating point that can be used for greater/lesser comparisons
* (PHP's version_compare() function is not quite suitable for our needs)
* @deprecated 1.8.2 no longer used
* @param $version
* @return float
*/
......@@ -102,30 +103,24 @@ function qa_version_to_float($version)
/**
* Returns true if the current Q2A version is lower than $version, if both are valid version strings for qa_version_to_float()
* Returns true if the current Q2A version is lower than $version
* @param $version
* @return bool
*/
function qa_qa_version_below($version)
{
$minqa = qa_version_to_float($version);
$thisqa = qa_version_to_float(QA_VERSION);
return $minqa && $thisqa && $thisqa < $minqa;
return version_compare(QA_VERSION, $version) < 0;
}
/**
* Returns true if the current PHP version is lower than $version, if both are valid version strings for qa_version_to_float()
* Returns true if the current PHP version is lower than $version
* @param $version
* @return bool
*/
function qa_php_version_below($version)
{
$minphp = qa_version_to_float($version);
$thisphp = qa_version_to_float(phpversion());
return $minphp && $thisphp && $thisphp < $minphp;
return version_compare(phpversion(), $version) < 0;
}
......
......@@ -9,6 +9,22 @@ class BaseTest extends PHPUnit_Framework_TestCase
$this->assertSame(1.008, qa_version_to_float('1.8.0-beta1'));
}
public function test__qa_qa_version_below()
{
// as we cannot change the QA_VERSION constant, we test an appended version against the set constant
$buildVersion = QA_VERSION . '.1234';
$betaVersion = QA_VERSION . '-beta1';
$this->assertSame(true, qa_qa_version_below($buildVersion));
$this->assertSame(false, qa_qa_version_below($betaVersion));
}
public function test__qa_php_version_below()
{
// as we cannot change the PHP version, we test against an unsupported PHP version and a far-future version
$this->assertSame(false, qa_php_version_below('5.1.4'));
$this->assertSame(true, qa_php_version_below('11.1.0'));
}
public function test__qa_js()
{
$this->assertSame("'test'", qa_js('test'));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment