mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
Merge pull request #1899 from dhensby/pulls/3.5/vp-render-fix
FIX Make sure VirtualPage renders correct templates
This commit is contained in:
commit
be0c0ef5b5
@ -496,10 +496,8 @@ class VirtualPage_Controller extends Page_Controller {
|
||||
}
|
||||
|
||||
public function getViewer($action) {
|
||||
$originalClass = get_class($this->CopyContentFrom());
|
||||
if ($originalClass == 'SiteTree') $name = 'Page_Controller';
|
||||
else $name = $originalClass."_Controller";
|
||||
$controller = new $name();
|
||||
$object = $this->CopyContentFrom();
|
||||
$controller = ModelAsController::controller_for($object, $action);
|
||||
return $controller->getViewer($action);
|
||||
}
|
||||
|
||||
@ -538,11 +536,8 @@ class VirtualPage_Controller extends Page_Controller {
|
||||
*/
|
||||
public function hasMethod($method) {
|
||||
$haveIt = parent::hasMethod($method);
|
||||
if (!$haveIt) {
|
||||
$originalClass = get_class($this->CopyContentFrom());
|
||||
if ($originalClass == 'SiteTree') $name = 'ContentController';
|
||||
else $name = $originalClass."_Controller";
|
||||
$controller = new $name($this->dataRecord->copyContentFrom());
|
||||
if (!$haveIt) {
|
||||
$controller = ModelAsController::controller_for($this->CopyContentFrom());
|
||||
$haveIt = $controller->hasMethod($method);
|
||||
}
|
||||
return $haveIt;
|
||||
|
@ -9,7 +9,7 @@ class VirtualPageTest extends FunctionalTest {
|
||||
'VirtualPageTest_ClassA',
|
||||
'VirtualPageTest_ClassB',
|
||||
'VirtualPageTest_VirtualPageSub',
|
||||
'VirtualPageTest_PageWithAllowedChildren'
|
||||
'VirtualPageTest_PageWithAllowedChildren',
|
||||
);
|
||||
|
||||
protected $illegalExtensions = array(
|
||||
@ -667,6 +667,27 @@ class VirtualPageTest extends FunctionalTest {
|
||||
$this->assertEquals(301, $response->getStatusCode());
|
||||
$this->assertEquals('http://google.com', $response->getHeader('Location'));
|
||||
}
|
||||
|
||||
public function testVirtualPageRendersCorrectTemplate() {
|
||||
$self = $this;
|
||||
$this->useDraftSite(true);
|
||||
$this->useTestTheme(dirname(__FILE__), 'virtualpagetest', function() use ($self) {
|
||||
$page = new VirtualPageTest_ClassA();
|
||||
$page->Title = 'Test Page';
|
||||
$page->Content = 'NotThisContent';
|
||||
$page->MyInitiallyCopiedField = 'TestContent';
|
||||
$page->write();
|
||||
|
||||
$vp = new VirtualPage();
|
||||
$vp->CopyContentFromID = $page->ID;
|
||||
$vp->write();
|
||||
|
||||
$response = $self->get($vp->Link());
|
||||
$self->assertEquals(200, $response->getStatusCode());
|
||||
$self->assertContains('TestContent', $response->getBody());
|
||||
$self->assertNotContains('NotThisContent', $response->getBody());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
class VirtualPageTest_ClassA extends Page implements TestOnly {
|
||||
|
1
tests/model/themes/virtualpagetest/Page.ss
Normal file
1
tests/model/themes/virtualpagetest/Page.ss
Normal file
@ -0,0 +1 @@
|
||||
<div>$Content</div>
|
@ -0,0 +1 @@
|
||||
<div>$MyInitiallyCopiedField</div>
|
Loading…
Reference in New Issue
Block a user