mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
MINOR Fixed DirectorTest to restore it's REQUEST_URI state to the original one after each test method is run
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@108665 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
7725426327
commit
11e9e2a348
@ -7,9 +7,16 @@
|
|||||||
*/
|
*/
|
||||||
class DirectorTest extends SapphireTest {
|
class DirectorTest extends SapphireTest {
|
||||||
|
|
||||||
|
protected static $originalRequestURI;
|
||||||
|
|
||||||
function setUp() {
|
function setUp() {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
|
// Hold the original request URI once so it doesn't get overwritten
|
||||||
|
if(!self::$originalRequestURI) {
|
||||||
|
self::$originalRequestURI = $_SERVER['REQUEST_URI'];
|
||||||
|
}
|
||||||
|
|
||||||
Director::addRules(99, array(
|
Director::addRules(99, array(
|
||||||
'DirectorTestRule/$Action/$ID/$OtherID' => 'DirectorTestRequest_Controller'
|
'DirectorTestRule/$Action/$ID/$OtherID' => 'DirectorTestRequest_Controller'
|
||||||
));
|
));
|
||||||
@ -18,6 +25,9 @@ class DirectorTest extends SapphireTest {
|
|||||||
function tearDown() {
|
function tearDown() {
|
||||||
// TODO Remove director rule, currently API doesnt allow this
|
// TODO Remove director rule, currently API doesnt allow this
|
||||||
|
|
||||||
|
// Reinstate the original REQUEST_URI after it was modified by some tests
|
||||||
|
$_SERVER['REQUEST_URI'] = self::$originalRequestURI;
|
||||||
|
|
||||||
parent::tearDown();
|
parent::tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -191,49 +201,35 @@ class DirectorTest extends SapphireTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function testForceSSLProtectsEntireSite() {
|
function testForceSSLProtectsEntireSite() {
|
||||||
$originalURI = $_SERVER['REQUEST_URI'];
|
|
||||||
$_SERVER['REQUEST_URI'] = Director::baseURL() . 'admin';
|
$_SERVER['REQUEST_URI'] = Director::baseURL() . 'admin';
|
||||||
$output = Director::forceSSL();
|
$output = Director::forceSSL();
|
||||||
$this->assertEquals($output, 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
|
$this->assertEquals($output, 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
|
||||||
|
|
||||||
$_SERVER['REQUEST_URI'] = $originalURI;
|
|
||||||
$_SERVER['REQUEST_URI'] = Director::baseURL() . 'some-url';
|
$_SERVER['REQUEST_URI'] = Director::baseURL() . 'some-url';
|
||||||
$output = Director::forceSSL();
|
$output = Director::forceSSL();
|
||||||
$this->assertEquals($output, 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
|
$this->assertEquals($output, 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
|
||||||
|
|
||||||
$_SERVER['REQUEST_URI'] = $originalURI;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function testForceSSLOnTopLevelPagePattern() {
|
function testForceSSLOnTopLevelPagePattern() {
|
||||||
$originalURI = $_SERVER['REQUEST_URI'];
|
|
||||||
$_SERVER['REQUEST_URI'] = Director::baseURL() . 'admin';
|
$_SERVER['REQUEST_URI'] = Director::baseURL() . 'admin';
|
||||||
$output = Director::forceSSL(array('/^admin/'));
|
$output = Director::forceSSL(array('/^admin/'));
|
||||||
$this->assertEquals($output, 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
|
$this->assertEquals($output, 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
|
||||||
|
|
||||||
$_SERVER['REQUEST_URI'] = $originalURI;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function testForceSSLOnSubPagesPattern() {
|
function testForceSSLOnSubPagesPattern() {
|
||||||
$originalURI = $_SERVER['REQUEST_URI'];
|
|
||||||
$_SERVER['REQUEST_URI'] = Director::baseURL() . 'Security/login';
|
$_SERVER['REQUEST_URI'] = Director::baseURL() . 'Security/login';
|
||||||
$output = Director::forceSSL(array('/^Security/'));
|
$output = Director::forceSSL(array('/^Security/'));
|
||||||
$this->assertEquals($output, 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
|
$this->assertEquals($output, 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
|
||||||
|
|
||||||
$_SERVER['REQUEST_URI'] = $originalURI;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function testForceSSLWithPatternDoesNotMatchOtherPages() {
|
function testForceSSLWithPatternDoesNotMatchOtherPages() {
|
||||||
$originalURI = $_SERVER['REQUEST_URI'];
|
|
||||||
$_SERVER['REQUEST_URI'] = Director::baseURL() . 'normal-page';
|
$_SERVER['REQUEST_URI'] = Director::baseURL() . 'normal-page';
|
||||||
$output = Director::forceSSL(array('/^admin/'));
|
$output = Director::forceSSL(array('/^admin/'));
|
||||||
$this->assertFalse($output);
|
$this->assertFalse($output);
|
||||||
|
|
||||||
$_SERVER['REQUEST_URI'] = $originalURI;
|
|
||||||
$_SERVER['REQUEST_URI'] = Director::baseURL() . 'just-another-page/sub-url';
|
$_SERVER['REQUEST_URI'] = Director::baseURL() . 'just-another-page/sub-url';
|
||||||
$output = Director::forceSSL(array('/^admin/', '/^Security/'));
|
$output = Director::forceSSL(array('/^admin/', '/^Security/'));
|
||||||
$this->assertFalse($output);
|
$this->assertFalse($output);
|
||||||
|
|
||||||
$_SERVER['REQUEST_URI'] = $originalURI;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -249,5 +245,3 @@ class DirectorTestRequest_Controller extends Controller implements TestOnly {
|
|||||||
public function returnCookieValue($request) { return $_COOKIE['somekey']; }
|
public function returnCookieValue($request) { return $_COOKIE['somekey']; }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
||||||
|
Loading…
Reference in New Issue
Block a user