Skip to content

Commit

Permalink
Merge pull request #305 from majna/2.0-prefixed-actions
Browse files Browse the repository at this point in the history
Make View task use prefixed template before falling back to generic one
  • Loading branch information
lorenzo committed Nov 7, 2011
2 parents 6fd69b0 + 57afa18 commit bab6136
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
4 changes: 4 additions & 0 deletions lib/Cake/Console/Command/Task/ViewTask.php
Expand Up @@ -393,6 +393,10 @@ public function getTemplate($action) {
if (!empty($this->template) && $action != $this->template) {
return $this->template;
}
$themePath = $this->Template->getThemePath();
if (file_exists($themePath . 'views' . DS . $action . '.ctp')) {
return $action;
}
$template = $action;
$prefixes = Configure::read('Routing.prefixes');
foreach ((array)$prefixes as $prefix) {
Expand Down
13 changes: 11 additions & 2 deletions lib/Cake/Test/Case/Console/Command/Task/ViewTaskTest.php
Expand Up @@ -230,6 +230,7 @@ public function setUp() {

$this->Task->path = TMP;
$this->Task->Template->params['theme'] = 'default';
$this->Task->Template->templatePaths = array('default' => CAKE . 'Console' . DS . 'Templates' . DS . 'default' .DS);
}

/**
Expand Down Expand Up @@ -563,7 +564,7 @@ public function testExecuteWithControllerVariations($name) {
}

/**
* test `cake bake view $controller -admin`
* test `cake bake view $controller --admin`
* Which only bakes admin methods, not non-admin methods.
*
* @return void
Expand Down Expand Up @@ -701,7 +702,7 @@ public function testExecuteInteractiveWithAdmin() {
}

/**
* test getting templates, make sure noTemplateActions works
* test getting templates, make sure noTemplateActions works and prefixed template is used before generic one.
*
* @return void
*/
Expand All @@ -716,6 +717,14 @@ public function testGetTemplate() {

$result = $this->Task->getTemplate('admin_add');
$this->assertEqual($result, 'form');

$this->Task->Template->templatePaths = array(
'test' => CAKE . 'Test' . DS . 'test_app' . DS . 'Console' . DS . 'Templates' . DS . 'test' .DS
);
$this->Task->Template->params['theme'] = 'test';

$result = $this->Task->getTemplate('admin_edit');
$this->assertEqual($result, 'admin_edit');
}

}
@@ -0,0 +1 @@
admin_edit template

0 comments on commit bab6136

Please sign in to comment.