Skip to content

Commit

Permalink
Adding property to signal which actions to skip finding templates for.
Browse files Browse the repository at this point in the history
…Fixes #330
  • Loading branch information
markstory committed Feb 13, 2010
1 parent 2e8e233 commit 5f5aae7
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
19 changes: 15 additions & 4 deletions cake/console/libs/tasks/view.php
Expand Up @@ -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
*
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down
25 changes: 23 additions & 2 deletions cake/tests/cases/console/libs/tasks/view.test.php
Expand Up @@ -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
Expand Down Expand Up @@ -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');
}

/**
Expand All @@ -271,6 +273,7 @@ function startTest() {
*/
function endTest() {
ClassRegistry::flush();
Configure::write('Routing', $this->_routing);
}

/**
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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');
}
}
?>

0 comments on commit 5f5aae7

Please sign in to comment.