Merge pull request #7246 from open-sausages/pulls/4.0/fix-iis

BUG Fix install issue with IIS
This commit is contained in:
Chris Joe 2017-08-07 10:44:17 +12:00 committed by GitHub
commit 4dbc2a99e5
2 changed files with 64 additions and 9 deletions

View File

@ -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/(?<version>[.\\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()
{

View File

@ -0,0 +1,54 @@
<?php
namespace SilverStripe\Dev\Tests\Install;
use SilverStripe\Dev\Install\InstallRequirements;
use SilverStripe\Dev\SapphireTest;
class InstallRequirementsTest extends SapphireTest
{
public function testIIS()
{
$requirements = new InstallRequirements();
$_SERVER['SERVER_SIGNATURE'] = 'Microsoft-IIS/10.0';
// Test server
$this->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());
}
}