From d0a4fc206542242362a753414bd28366c9c1a84e Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Fri, 14 Feb 2014 17:44:53 +1300 Subject: [PATCH] FIX: Fix failover to index template in ContentController::getViewer() Historically, if you visit a foo action on Page, and Page_foo.ss doesn't exist, then it fails over to Page.ss. The introduction of ContentController::getViewer() broke this, but this patch adds a test for this case and fixes it. It was identified by build failures on silverstripe/userforms when tested against the master branch. --- code/controllers/ContentController.php | 4 ++++ tests/controller/ContentControllerTest.php | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/code/controllers/ContentController.php b/code/controllers/ContentController.php index 46fa0f69..700fd149 100755 --- a/code/controllers/ContentController.php +++ b/code/controllers/ContentController.php @@ -404,6 +404,10 @@ HTML; // 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"); + return new SSViewer($templates); } diff --git a/tests/controller/ContentControllerTest.php b/tests/controller/ContentControllerTest.php index b323eb09..e87a2c09 100755 --- a/tests/controller/ContentControllerTest.php +++ b/tests/controller/ContentControllerTest.php @@ -161,6 +161,11 @@ class ContentControllerTest extends FunctionalTest { $response = $this->get($page->RelativeLink("test")); $this->assertEquals("ContentControllerTestPage_test", $response->getBody()); + + // Test that an action without a template will default to the index template, which is + // to say the default Page.ss template + $response = $this->get($page->RelativeLink("testwithouttemplate")); + $this->assertEquals("Foo", $response->getBody()); } } @@ -190,5 +195,10 @@ class ContentControllerTestPage extends Page { } class ContentControllerTestPage_Controller extends Page_Controller { private static $allowed_actions = array( "test", + "testwithouttemplate" ); + + function testwithouttemplate() { + return array(); + } }