mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
FIX: Ensure VirtualPage forwards request/response data to virtual controllers (fixes #1329)
This commit is contained in:
parent
a40c8e034a
commit
2983d823d1
@ -563,12 +563,17 @@ class VirtualPage_Controller extends Page_Controller {
|
||||
} catch (Exception $e) {
|
||||
// Hack... detect exception type. We really should use exception subclasses.
|
||||
// if the exception isn't a 'no method' error, rethrow it
|
||||
if ($e->getCode() !== 2175) throw $e;
|
||||
if ($e->getCode() !== 2175) {
|
||||
throw $e;
|
||||
}
|
||||
|
||||
$original = $this->copyContentFrom();
|
||||
$originalClass = get_class($original);
|
||||
if ($originalClass == 'SiteTree') $name = 'ContentController';
|
||||
else $name = $originalClass."_Controller";
|
||||
$controller = new $name($this->dataRecord->copyContentFrom());
|
||||
$controller = ModelAsController::controller_for($original);
|
||||
|
||||
// Ensure request/response data is available on virtual controller
|
||||
$controller->setRequest($this->getRequest());
|
||||
$controller->response = $this->response; // @todo - replace with getter/setter in 3.3
|
||||
|
||||
return call_user_func_array(array($controller, $method), $args);
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
<?php
|
||||
|
||||
class VirtualPageTest extends SapphireTest {
|
||||
class VirtualPageTest extends FunctionalTest {
|
||||
protected static $fixture_file = 'VirtualPageTest.yml';
|
||||
protected static $use_draft_site = false;
|
||||
protected $autoFollowRedirection = false;
|
||||
|
||||
protected $extraDataObjects = array(
|
||||
'VirtualPageTest_ClassA',
|
||||
@ -21,6 +23,9 @@ class VirtualPageTest extends SapphireTest {
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Ensure we always have permission to save/publish
|
||||
$this->logInWithPermission("ADMIN");
|
||||
|
||||
$this->origInitiallyCopiedFields = VirtualPage::config()->initially_copied_fields;
|
||||
Config::inst()->remove('VirtualPage', 'initially_copied_fields');
|
||||
VirtualPage::config()->initially_copied_fields = array_merge(
|
||||
@ -644,6 +649,24 @@ class VirtualPageTest extends SapphireTest {
|
||||
|
||||
if(!$isDetected) $this->fail("Shouldn't be allowed to write a VirtualPage that links to a disallowed child");
|
||||
}
|
||||
|
||||
public function testVirtualPagePointingToRedirectorPage() {
|
||||
if (!class_exists('RedirectorPage')) {
|
||||
$this->markTestSkipped('RedirectorPage required');
|
||||
}
|
||||
|
||||
$rp = new RedirectorPage(array('ExternalURL' => 'http://google.com', 'RedirectionType' => 'External'));
|
||||
$rp->write();
|
||||
$rp->doPublish();
|
||||
|
||||
$vp = new VirtualPage(array('URLSegment' => 'vptest', 'CopyContentFromID' => $rp->ID));
|
||||
$vp->write();
|
||||
$vp->doPublish();
|
||||
|
||||
$response = $this->get($vp->Link());
|
||||
$this->assertEquals(301, $response->getStatusCode());
|
||||
$this->assertEquals('http://google.com', $response->getHeader('Location'));
|
||||
}
|
||||
}
|
||||
|
||||
class VirtualPageTest_ClassA extends Page implements TestOnly {
|
||||
|
Loading…
Reference in New Issue
Block a user