Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MINOR Fixed DirectorTest to restore it's REQUEST_URI state to the ori…

…ginal one after each test method is run (from r108665)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@112764 467b73ca-7a2a-4603-9d3b-597d59a354a9
  • Loading branch information...
commit 83e31e1f8a1b557ff2becd13fc3bacee5f706b9d 1 parent d295d68
@sminnee sminnee authored
Showing with 11 additions and 17 deletions.
  1. +11 −17 tests/control/DirectorTest.php
View
28 tests/control/DirectorTest.php
@@ -7,8 +7,15 @@
*/
class DirectorTest extends SapphireTest {
+ protected static $originalRequestURI;
+
function 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(
'DirectorTestRule/$Action/$ID/$OtherID' => 'DirectorTestRequest_Controller'
@@ -18,6 +25,9 @@ function setUp() {
function tearDown() {
// 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();
}
@@ -184,49 +194,35 @@ function testURLParams() {
}
function testForceSSLProtectsEntireSite() {
- $originalURI = $_SERVER['REQUEST_URI'];
$_SERVER['REQUEST_URI'] = Director::baseURL() . 'admin';
$output = Director::forceSSL();
$this->assertEquals($output, 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
- $_SERVER['REQUEST_URI'] = $originalURI;
$_SERVER['REQUEST_URI'] = Director::baseURL() . 'some-url';
$output = Director::forceSSL();
$this->assertEquals($output, 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
-
- $_SERVER['REQUEST_URI'] = $originalURI;
}
function testForceSSLOnTopLevelPagePattern() {
- $originalURI = $_SERVER['REQUEST_URI'];
$_SERVER['REQUEST_URI'] = Director::baseURL() . 'admin';
$output = Director::forceSSL(array('/^admin/'));
$this->assertEquals($output, 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
-
- $_SERVER['REQUEST_URI'] = $originalURI;
}
function testForceSSLOnSubPagesPattern() {
- $originalURI = $_SERVER['REQUEST_URI'];
$_SERVER['REQUEST_URI'] = Director::baseURL() . 'Security/login';
$output = Director::forceSSL(array('/^Security/'));
$this->assertEquals($output, 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
-
- $_SERVER['REQUEST_URI'] = $originalURI;
}
function testForceSSLWithPatternDoesNotMatchOtherPages() {
- $originalURI = $_SERVER['REQUEST_URI'];
$_SERVER['REQUEST_URI'] = Director::baseURL() . 'normal-page';
$output = Director::forceSSL(array('/^admin/'));
$this->assertFalse($output);
- $_SERVER['REQUEST_URI'] = $originalURI;
$_SERVER['REQUEST_URI'] = Director::baseURL() . 'just-another-page/sub-url';
$output = Director::forceSSL(array('/^admin/', '/^Security/'));
$this->assertFalse($output);
-
- $_SERVER['REQUEST_URI'] = $originalURI;
}
}
@@ -241,6 +237,4 @@ public function returnRequestValue($request) { return $_REQUEST['somekey']; }
public function returnCookieValue($request) { return $_COOKIE['somekey']; }
-}
-
-?>
+}
Please sign in to comment.
Something went wrong with that request. Please try again.