diff --git a/dev/SapphireTest.php b/dev/SapphireTest.php index e4eede1a4..afdf9bf9a 100755 --- a/dev/SapphireTest.php +++ b/dev/SapphireTest.php @@ -34,6 +34,7 @@ class SapphireTest extends PHPUnit_Framework_TestCase { protected $originalRequirements; protected $originalIsRunningTest; protected $originalTheme; + protected $originalNestedURLsState; protected $mailer; @@ -109,6 +110,9 @@ class SapphireTest extends PHPUnit_Framework_TestCase { Controller::curr()->setSession(new Session(array())); $this->originalTheme = SSViewer::current_theme(); + + // Save nested_urls state, so we can restore it later + $this->originalNestedURLsState = SiteTree::nested_urls(); $className = get_class($this); $fixtureFile = eval("return {$className}::\$fixture_file;"); @@ -346,6 +350,21 @@ class SapphireTest extends PHPUnit_Framework_TestCase { // Reset mocked datetime SS_Datetime::clear_mock_now(); + + // Restore nested_urls state + if ( $this->originalNestedURLsState ) + SiteTree::enable_nested_urls(); + else + SiteTree::disable_nested_urls(); + + // Stop the redirection that might have been requested in the test. + // Note: Ideally a clean Controller should be created for each test. + // Now all tests executed in a batch share the same controller. + $controller = Controller::curr(); + if ( $controller && $controller->response && $controller->response->getHeader('Location') ) { + $controller->response->setStatusCode(200); + $controller->response->removeHeader('Location'); + } } /** * Clear the log of emails sent