mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-04 23:28:41 +02:00
Merge pull request #3424 from halkyon/director_test_relative
BUG Fixing Director::test() failing on BASE_URL prefixed URLs
This commit is contained in:
commit
0d169d5c8d
@ -255,9 +255,12 @@ class Director implements TemplateGlobalProvider {
|
|||||||
} else {
|
} else {
|
||||||
$_SERVER['HTTP_HOST'] = $bits['host'];
|
$_SERVER['HTTP_HOST'] = $bits['host'];
|
||||||
}
|
}
|
||||||
$url = Director::makeRelative($url);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ensure URL is properly made relative.
|
||||||
|
// Example: url passed is "/ss31/my-page" (prefixed with BASE_URL), this should be changed to "my-page"
|
||||||
|
$url = self::makeRelative($url);
|
||||||
|
|
||||||
$urlWithQuerystring = $url;
|
$urlWithQuerystring = $url;
|
||||||
if(strpos($url, '?') !== false) {
|
if(strpos($url, '?') !== false) {
|
||||||
list($url, $getVarsEncoded) = explode('?', $url, 2);
|
list($url, $getVarsEncoded) = explode('?', $url, 2);
|
||||||
|
@ -110,6 +110,30 @@ class FunctionalTest extends SapphireTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run a test while mocking the base url with the provided value
|
||||||
|
* @param string $url The base URL to use for this test
|
||||||
|
* @param callable $callback The test to run
|
||||||
|
*/
|
||||||
|
protected function withBaseURL($url, $callback) {
|
||||||
|
$oldBase = Config::inst()->get('Director', 'alternate_base_url');
|
||||||
|
Config::inst()->update('Director', 'alternate_base_url', $url);
|
||||||
|
$callback($this);
|
||||||
|
Config::inst()->update('Director', 'alternate_base_url', $oldBase);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run a test while mocking the base folder with the provided value
|
||||||
|
* @param string $folder The base folder to use for this test
|
||||||
|
* @param callable $callback The test to run
|
||||||
|
*/
|
||||||
|
protected function withBaseFolder($folder, $callback) {
|
||||||
|
$oldFolder = Config::inst()->get('Director', 'alternate_base_folder');
|
||||||
|
Config::inst()->update('Director', 'alternate_base_folder', $folder);
|
||||||
|
$callback($this);
|
||||||
|
Config::inst()->update('Director', 'alternate_base_folder', $oldFolder);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Submit a get request
|
* Submit a get request
|
||||||
* @uses Director::test()
|
* @uses Director::test()
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
* @package framework
|
* @package framework
|
||||||
* @subpackage tests
|
* @subpackage tests
|
||||||
*/
|
*/
|
||||||
class HTTPTest extends SapphireTest {
|
class HTTPTest extends FunctionalTest {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests {@link HTTP::getLinksIn()}
|
* Tests {@link HTTP::getLinksIn()}
|
||||||
@ -227,16 +227,5 @@ class HTTPTest extends SapphireTest {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Run a test while mocking the base url with the provided value
|
|
||||||
* @param string $url The base URL to use for this test
|
|
||||||
* @param callable $callback The test to run
|
|
||||||
*/
|
|
||||||
protected function withBaseURL($url, $callback) {
|
|
||||||
$oldBase = Config::inst()->get('Director', 'alternate_base_url');
|
|
||||||
Config::inst()->update('Director', 'alternate_base_url', $url);
|
|
||||||
$callback($this);
|
|
||||||
Config::inst()->update('Director', 'alternate_base_url', $oldBase);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -60,10 +60,24 @@ class RequestHandlingTest extends FunctionalTest {
|
|||||||
$this->assertEquals("MyField requested", $response->getBody());
|
$this->assertEquals("MyField requested", $response->getBody());
|
||||||
|
|
||||||
/* We can also make a POST request on a form field, which could be used for in-place editing, for example. */
|
/* We can also make a POST request on a form field, which could be used for in-place editing, for example. */
|
||||||
$response = Director::test("testGoodBase1/TestForm/fields/MyField" ,array("MyField" => 5));
|
$response = Director::test("testGoodBase1/TestForm/fields/MyField", array("MyField" => 5));
|
||||||
$this->assertEquals("MyField posted, update to 5", $response->getBody());
|
$this->assertEquals("MyField posted, update to 5", $response->getBody());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testBaseUrlPrefixed() {
|
||||||
|
$this->withBaseFolder('/silverstripe', function($test) {
|
||||||
|
$test->assertEquals(
|
||||||
|
'MyField requested',
|
||||||
|
Director::test('/silverstripe/testGoodBase1/TestForm/fields/MyField')->getBody()
|
||||||
|
);
|
||||||
|
|
||||||
|
$test->assertEquals(
|
||||||
|
'MyField posted, update to 5',
|
||||||
|
Director::test('/silverstripe/testGoodBase1/TestForm/fields/MyField', array('MyField' => 5))->getBody()
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public function testBadBase() {
|
public function testBadBase() {
|
||||||
/* We no longer support using hacky attempting to handle URL parsing with broken rules */
|
/* We no longer support using hacky attempting to handle URL parsing with broken rules */
|
||||||
$response = Director::test("testBadBase/method/1/2");
|
$response = Director::test("testBadBase/method/1/2");
|
||||||
|
Loading…
Reference in New Issue
Block a user