Merge pull request #2901 from dhensby/director-test

Making Director::test() ignore URL Anchors
This commit is contained in:
Simon Welsh 2014-03-15 00:09:06 +13:00
commit d1befdd37c
2 changed files with 21 additions and 0 deletions

View File

@ -244,6 +244,10 @@ class Director implements TemplateGlobalProvider {
Config::inst()->update('Cookie', 'report_errors', false);
Requirements::set_backend(new Requirements_Backend());
if (strpos($url, '#') !== false) {
$url = substr($url, 0, strpos($url, '#'));
}
// Handle absolute URLs
if (parse_url($url, PHP_URL_HOST)) {
$bits = parse_url($url);

View File

@ -344,6 +344,23 @@ class DirectorTest extends SapphireTest {
$_SERVER = $origServer;
}
public function testTestIgnoresHashes() {
//test that hashes are ignored
$url = "DirectorTestRequest_Controller/returnGetValue?somekey=key";
$hash = "#test";
$response = Director::test($url . $hash, null, null, null, null, null, null, $request);
$this->assertFalse($response->isError());
$this->assertEquals('key', $response->getBody());
$this->assertEquals($request->getURL(true), $url);
//test encoded hashes are accepted
$url = "DirectorTestRequest_Controller/returnGetValue?somekey=test%23key";
$response = Director::test($url, null, null, null, null, null, null, $request);
$this->assertFalse($response->isError());
$this->assertEquals('test#key', $response->getBody());
$this->assertEquals($request->getURL(true), $url);
}
public function testRequestFilterInDirectorTest() {
$filter = new TestRequestFilter;