From f7bebdd8f8ef17a5d3caca717f442cf4206a10cd Mon Sep 17 00:00:00 2001 From: Damian Mooyman Date: Mon, 7 Aug 2017 10:15:16 +1200 Subject: [PATCH] BUG Fix install issue with IIS Fixes #7218 --- src/Dev/Install/InstallRequirements.php | 19 +++---- .../Dev/Install/InstallRequirementsTest.php | 54 +++++++++++++++++++ 2 files changed, 64 insertions(+), 9 deletions(-) create mode 100644 tests/php/Dev/Install/InstallRequirementsTest.php diff --git a/src/Dev/Install/InstallRequirements.php b/src/Dev/Install/InstallRequirements.php index 889506338..1cdc46ee7 100644 --- a/src/Dev/Install/InstallRequirements.php +++ b/src/Dev/Install/InstallRequirements.php @@ -142,24 +142,25 @@ class InstallRequirements */ public function isIIS($fromVersion = 7) { - if (strpos($this->findWebserver(), 'IIS/') === false) { - return false; + $webserver = $this->findWebserver(); + if (preg_match('#.*IIS/(?[.\\d]+)$#', $webserver, $matches)) { + return version_compare($matches['version'], $fromVersion, '>='); } - return substr(strstr($this->findWebserver(), '/'), -3, 1) >= $fromVersion; + return false; } + /** + * @return bool + */ public function isApache() { - if (strpos($this->findWebserver(), 'Apache') !== false) { - return true; - } else { - return false; - } + return strpos($this->findWebserver(), 'Apache') !== false; } /** * Find the webserver software running on the PHP host. - * @return string|boolean Server software or boolean FALSE + * + * @return string|false Server software or boolean FALSE */ public function findWebserver() { diff --git a/tests/php/Dev/Install/InstallRequirementsTest.php b/tests/php/Dev/Install/InstallRequirementsTest.php new file mode 100644 index 000000000..57c66db02 --- /dev/null +++ b/tests/php/Dev/Install/InstallRequirementsTest.php @@ -0,0 +1,54 @@ +assertEquals('Microsoft-IIS/10.0', $requirements->findWebserver()); + + // True conditions + $this->assertTrue($requirements->isIIS()); + $this->assertTrue($requirements->isIIS(10)); + $this->assertTrue($requirements->isIIS('10.0')); + $this->assertTrue($requirements->isIIS(9)); + + // Negative - Based on number + $this->assertFalse($requirements->isIIS(11)); + $_SERVER['SERVER_SIGNATURE'] = 'Microsoft-IIS/6.0'; + $this->assertFalse($requirements->isIIS()); + $_SERVER['SERVER_SIGNATURE'] = 'Microsoft-IIS/6.5'; + $this->assertFalse($requirements->isIIS()); + + // Negative - Based on string + $_SERVER['SERVER_SOFTWARE'] = 'lighttpd/1.4.33'; + $this->assertFalse($requirements->isIIS()); + $_SERVER['SERVER_SOFTWARE'] = 'Apache/2.4.25 (Unix) PHP/5.6.30 LibreSSL/2.2.7'; + $this->assertFalse($requirements->isIIS()); + } + + public function testApache() + { + $requirements = new InstallRequirements(); + $_SERVER['SERVER_SIGNATURE'] = ''; + $_SERVER['SERVER_SOFTWARE'] = 'Apache/2.4.25 (Unix) PHP/5.6.30 LibreSSL/2.2.7'; + + // Test server + $this->assertEquals('Apache/2.4.25 (Unix) PHP/5.6.30 LibreSSL/2.2.7', $requirements->findWebserver()); + + // True conditions + $this->assertTrue($requirements->isApache()); + + // False conditions + $_SERVER['SERVER_SOFTWARE'] = 'lighttpd/1.4.33'; + $this->assertFalse($requirements->isApache()); + } +}