mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUG Fix DirectorTest failing when run with sake
This commit is contained in:
parent
85cff0ad8f
commit
e0710ae4e4
@ -25,9 +25,11 @@ class DirectorTest extends SapphireTest {
|
|||||||
if(!self::$originalRequestURI) {
|
if(!self::$originalRequestURI) {
|
||||||
self::$originalRequestURI = $_SERVER['REQUEST_URI'];
|
self::$originalRequestURI = $_SERVER['REQUEST_URI'];
|
||||||
}
|
}
|
||||||
|
$_SERVER['REQUEST_URI'] = 'http://www.mysite.com';
|
||||||
|
|
||||||
$this->originalGet = $_GET;
|
$this->originalGet = $_GET;
|
||||||
$this->originalSession = $_SESSION;
|
$this->originalSession = $_SESSION;
|
||||||
|
$_SESSION = array();
|
||||||
|
|
||||||
Config::inst()->update('Director', 'rules', array(
|
Config::inst()->update('Director', 'rules', array(
|
||||||
'DirectorTestRule/$Action/$ID/$OtherID' => 'DirectorTestRequest_Controller',
|
'DirectorTestRule/$Action/$ID/$OtherID' => 'DirectorTestRequest_Controller',
|
||||||
@ -136,26 +138,47 @@ class DirectorTest extends SapphireTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function testAlternativeBaseURL() {
|
public function testAlternativeBaseURL() {
|
||||||
|
// Get original protocol and hostname
|
||||||
|
$rootURL = Director::protocolAndHost();
|
||||||
|
|
||||||
// relative base URLs - you should end them in a /
|
// relative base URLs - you should end them in a /
|
||||||
Config::inst()->update('Director', 'alternate_base_url', '/relativebase/');
|
Config::inst()->update('Director', 'alternate_base_url', '/relativebase/');
|
||||||
|
$_SERVER['REQUEST_URI'] = "$rootURL/relativebase/sub-page/";
|
||||||
|
|
||||||
$this->assertEquals('/relativebase/', Director::baseURL());
|
$this->assertEquals('/relativebase/', Director::baseURL());
|
||||||
$this->assertEquals(Director::protocolAndHost() . '/relativebase/', Director::absoluteBaseURL());
|
$this->assertEquals($rootURL . '/relativebase/', Director::absoluteBaseURL());
|
||||||
$this->assertEquals(Director::protocolAndHost() . '/relativebase/subfolder/test',
|
$this->assertEquals(
|
||||||
Director::absoluteURL('subfolder/test'));
|
$rootURL . '/relativebase/subfolder/test',
|
||||||
|
Director::absoluteURL('subfolder/test')
|
||||||
|
);
|
||||||
|
|
||||||
// absolute base URLs - you should end them in a /
|
// absolute base URLs - you should end them in a /
|
||||||
Config::inst()->update('Director', 'alternate_base_url', 'http://www.example.org/');
|
Config::inst()->update('Director', 'alternate_base_url', 'http://www.example.org/');
|
||||||
|
$_SERVER['REQUEST_URI'] = "http://www.example.org/sub-page/";
|
||||||
$this->assertEquals('http://www.example.org/', Director::baseURL());
|
$this->assertEquals('http://www.example.org/', Director::baseURL());
|
||||||
$this->assertEquals('http://www.example.org/', Director::absoluteBaseURL());
|
$this->assertEquals('http://www.example.org/', Director::absoluteBaseURL());
|
||||||
$this->assertEquals('http://www.example.org/', Director::absoluteURL(''));
|
$this->assertEquals('http://www.example.org/sub-page/', Director::absoluteURL(''));
|
||||||
$this->assertEquals('http://www.example.org/subfolder/test', Director::absoluteURL('subfolder/test'));
|
$this->assertEquals('http://www.example.org/', Director::absoluteURL('', true));
|
||||||
|
/*
|
||||||
|
* See Legacy behaviour in testAbsoluteURL - sub-pages with '/' in the string are not correctly evaluated
|
||||||
|
$this->assertEquals(
|
||||||
|
'http://www.example.org/sub-page/subfolder/test',
|
||||||
|
Director::absoluteURL('subfolder/test')
|
||||||
|
);*/
|
||||||
|
$this->assertEquals(
|
||||||
|
'http://www.example.org/subfolder/test',
|
||||||
|
Director::absoluteURL('subfolder/test', true)
|
||||||
|
);
|
||||||
|
|
||||||
// Setting it to false restores functionality
|
// Setting it to false restores functionality
|
||||||
Config::inst()->update('Director', 'alternate_base_url', false);
|
Config::inst()->update('Director', 'alternate_base_url', false);
|
||||||
|
$_SERVER['REQUEST_URI'] = $rootURL;
|
||||||
$this->assertEquals(BASE_URL.'/', Director::baseURL());
|
$this->assertEquals(BASE_URL.'/', Director::baseURL());
|
||||||
$this->assertEquals(Director::protocolAndHost().BASE_URL.'/', Director::absoluteBaseURL(BASE_URL));
|
$this->assertEquals($rootURL.BASE_URL.'/', Director::absoluteBaseURL(BASE_URL));
|
||||||
$this->assertEquals(Director::protocolAndHost().BASE_URL . '/subfolder/test',
|
$this->assertEquals(
|
||||||
Director::absoluteURL('subfolder/test'));
|
$rootURL.BASE_URL . '/subfolder/test',
|
||||||
|
Director::absoluteURL('subfolder/test')
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user