From 9d888d5ddeaf8d0acfa42d91d2b4f10d5c5ddf9e Mon Sep 17 00:00:00 2001 From: Stephen McMahon Date: Fri, 3 Oct 2014 14:08:47 +1000 Subject: [PATCH] BUG: Fixed SearchForm not calling getTemplate() in forTemplate() --- code/search/SearchForm.php | 18 +++++++++++++++--- tests/search/SearchFormTest.php | 13 +++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/code/search/SearchForm.php b/code/search/SearchForm.php index 8ee7b105..bbfff944 100644 --- a/code/search/SearchForm.php +++ b/code/search/SearchForm.php @@ -59,11 +59,23 @@ class SearchForm extends Form { $this->disableSecurityToken(); } + + /** + * Return a rendered version of this form. + * + * This is returned when you access a form as $FormObject rather + * than <% with FormObject %> + */ public function forTemplate() { - return $this->renderWith(array( - 'SearchForm', - 'Form' + $return = $this->renderWith(array_merge( + (array)$this->getTemplate(), + array('SearchForm', 'Form') )); + + // Now that we're rendered, clear message + $this->clearMessage(); + + return $return; } /** diff --git a/tests/search/SearchFormTest.php b/tests/search/SearchFormTest.php index 9a3a42b6..685c4997 100644 --- a/tests/search/SearchFormTest.php +++ b/tests/search/SearchFormTest.php @@ -56,6 +56,19 @@ class ZZZSearchFormTest extends FunctionalTest { return $supports; } + public function testSearchFormTemplateCanBeChanged() { + if(!$this->checkFulltextSupport()) return; + + $sf = new SearchForm($this->mockController, 'SearchForm'); + + $sf->setTemplate('BlankPage'); + + $this->assertContains( + '', + $sf->forTemplate() + ); + } + public function testPublishedPagesMatchedByTitle() { if(!$this->checkFulltextSupport()) return;