FIX: ContentController::getViewer() not returning all found templates (fixes #1244)

This commit is contained in:
Loz Calver 2015-07-23 18:24:13 +01:00
parent f55b22bd75
commit 10b2fdc318
2 changed files with 17 additions and 9 deletions

View File

@ -402,15 +402,15 @@ HTML;
if($action == "index") $action = "";
else $action = '_' . $action;
// Find templates by dataRecord
$templates = SSViewer::get_templates_by_class(get_class($this->dataRecord), $action, "SiteTree");
// Next, we need to add templates for all controllers
$templates += SSViewer::get_templates_by_class(get_class($this), $action, "Controller");
// Fail-over to the same for the "index" action
$templates += SSViewer::get_templates_by_class(get_class($this->dataRecord), "", "SiteTree");
$templates += SSViewer::get_templates_by_class(get_class($this), "", "Controller");
$templates = array_merge(
// Find templates by dataRecord
SSViewer::get_templates_by_class(get_class($this->dataRecord), $action, "SiteTree"),
// Next, we need to add templates for all controllers
SSViewer::get_templates_by_class(get_class($this), $action, "Controller"),
// Fail-over to the same for the "index" action
SSViewer::get_templates_by_class(get_class($this->dataRecord), "", "SiteTree"),
SSViewer::get_templates_by_class(get_class($this), "", "Controller")
);
return new SSViewer($templates);
}

View File

@ -168,6 +168,14 @@ class ContentControllerTest extends FunctionalTest {
// to say the default Page.ss template
$response = $self->get($page->RelativeLink("testwithouttemplate"));
$self->assertEquals("Page", $response->getBody());
// Test that an action with a template will render the both action template *and* the
// correct parent template
$controller = new ContentController($page);
$viewer = $controller->getViewer('test');
$templateList = array('ContentControllerTestPage_test', 'Page');
$expected = SS_TemplateLoader::instance()->findTemplates($templateList, 'controllertest');
$self->assertEquals($expected, $viewer->templates());
});
}