Added backup and restore of the HTTP_HOST and REQUEST_URI $_SERVER values when testing

This commit is contained in:
UndefinedOffset 2020-10-05 13:39:46 -03:00
parent 5fffeca9de
commit 446469614d
No known key found for this signature in database
GPG Key ID: 59C4EE2B6468B796
2 changed files with 33 additions and 3 deletions

View File

@ -2,8 +2,6 @@
namespace SilverStripe\Control\Middleware;
use SilverStripe\Control\Director;
use SilverStripe\Control\Controller;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Control\Middleware\HTTPMiddleware;
use SilverStripe\Core\Convert;

View File

@ -2,15 +2,47 @@
namespace SilverStripe\Control\Tests\Middleware;
use SilverStripe\Control\Middleware\RewriteHashLinksMiddleware;
use SilverStripe\Control\Director;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Control\HTTPResponse;
use SilverStripe\Control\Middleware\RewriteHashLinksMiddleware;
use SilverStripe\Core\Convert;
use SilverStripe\Dev\SapphireTest;
class RewriteHashLinksMiddlewareTest extends SapphireTest
{
protected $currentHost;
protected $currentURI;
/**
* Setup the test
*/
protected function setUp()
{
parent::setUp();
$this->currentHost = (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : false);
$this->currentURI = (isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : false);
}
/**
* Clean up the test
*/
protected function tearDown()
{
if ($this->currentHost === false) {
unset($_SERVER['HTTP_HOST']);
} else {
$_SERVER['HTTP_HOST'] = $this->currentHost;
}
if ($this->currentURI === false) {
unset($_SERVER['REQUEST_URI']);
} else {
$_SERVER['REQUEST_URI'] = $this->currentURI;
}
}
/**
* Tests rewriting of HTML content types to ensure that it's properly rewriting anchors when the base tag is present
*/