From 5f5aae71e77e9c147a995afb90439f1c723eeb24 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Sat, 13 Feb 2010 17:51:49 -0500 Subject: [PATCH] Adding property to signal which actions to skip finding templates for. Fixes #330 --- cake/console/libs/tasks/view.php | 19 +++++++++++--- .../cases/console/libs/tasks/view.test.php | 25 +++++++++++++++++-- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/cake/console/libs/tasks/view.php b/cake/console/libs/tasks/view.php index 75ac9652c09..baf159d4ebe 100644 --- a/cake/console/libs/tasks/view.php +++ b/cake/console/libs/tasks/view.php @@ -83,6 +83,15 @@ class ViewTask extends Shell { */ var $scaffoldActions = array('index', 'view', 'add', 'edit'); +/** + * An array of action names that don't require templates. These + * actions will not emit errors when doing bakeActions() + * + * @var array + * @access public + */ + var $noTemplateActions = array('delete'); + /** * Override initialize * @@ -381,10 +390,9 @@ function getContent($action, $vars = null) { $this->Template->set('action', $action); $this->Template->set('plugin', $this->plugin); $this->Template->set($vars); - $output = $this->Template->generate('views', $this->getTemplate($action)); - - if (!empty($output)) { - return $output; + $template = $this->getTemplate($action); + if ($template) { + return $this->Template->generate('views', $template); } return false; } @@ -397,6 +405,9 @@ function getContent($action, $vars = null) { * @access public */ function getTemplate($action) { + if ($action != $this->template && in_array($action, $this->noTemplateActions)) { + return false; + } if (!empty($this->template) && $action != $this->template) { return $this->template; } diff --git a/cake/tests/cases/console/libs/tasks/view.test.php b/cake/tests/cases/console/libs/tasks/view.test.php index 70715288f87..fb49c4efa8e 100644 --- a/cake/tests/cases/console/libs/tasks/view.test.php +++ b/cake/tests/cases/console/libs/tasks/view.test.php @@ -113,7 +113,7 @@ class ViewTaskArticle extends Model { } /** - * Test View Task Comments Controller + * Test View Task Comments Controller * * @package cake * @subpackage cake.tests.cases.console.libs.tasks @@ -261,6 +261,8 @@ function startTest() { $this->Task->Project =& new ViewTaskMockProjectTask(); $this->Task->path = TMP; $this->Task->Template->params['theme'] = 'default'; + + $this->_routing = Configure::read('Routing'); } /** @@ -271,6 +273,7 @@ function startTest() { */ function endTest() { ClassRegistry::flush(); + Configure::write('Routing', $this->_routing); } /** @@ -554,7 +557,7 @@ function testExecuteWithAlternateTemplates() { $this->Task->connection = 'test_suite'; $this->Task->args = array('ViewTaskComments', 'index', 'list'); $this->Task->params = array(); - + $this->Task->expectCallCount('createFile', 1); $this->Task->expectAt(0, 'createFile', array( TMP . 'view_task_comments' . DS . 'list.ctp', @@ -600,5 +603,23 @@ function testExecuteInteractiveWithAdmin() { $this->Task->execute(); } + +/** + * test getting templates, make sure noTemplateActions works + * + * @return void + */ + function testGetTemplate() { + $result = $this->Task->getTemplate('delete'); + $this->assertFalse($result); + + $result = $this->Task->getTemplate('add'); + $this->assertEqual($result, 'form'); + + Configure::write('Routing.prefixes', array('admin')); + + $result = $this->Task->getTemplate('admin_add'); + $this->assertEqual($result, 'form'); + } } ?> \ No newline at end of file