Skip to content
Permalink
Browse files

Refactoring out bakeActions

Adding tests for bake()
  • Loading branch information...
markstory committed Jun 4, 2009
1 parent 91f90b5 commit 0a3af5b7924c7c5c2507f83a2130f2581e26e9db
Showing with 53 additions and 10 deletions.
  1. +20 −9 cake/console/libs/tasks/view.php
  2. +33 −1 cake/tests/cases/console/libs/tasks/view.test.php
@@ -150,6 +150,7 @@ function execute() {
}
}
}
/**
* Bake All views for All controllers.
*
@@ -167,10 +168,7 @@ function all() {
if (App::import('Model', $model)) {
$vars = $this->__loadController();
if ($vars) {
foreach ($actions as $action) {
$content = $this->getContent($action, $vars);
$this->bake($action, $content);
}
$this->bakeActions($actions);
}
}
}
@@ -185,8 +183,10 @@ function __interactive() {
$this->hr();
$this->out(sprintf("Bake View\nPath: %s", $this->path));
$this->hr();
$wannaDoAdmin = 'n';
$wannaDoScaffold = 'y';
$admin = false;
$this->interactive = false;
$this->controllerName = $this->Controller->getName();
@@ -203,7 +203,6 @@ function __interactive() {
if (strtolower($wannaDoScaffold) == 'y') {
$wannaDoAdmin = $this->in("Would you like to create the views for admin routing?", array('y','n'), 'y');
}
$admin = false;
if (strtolower($wannaDoAdmin) == 'y') {
$admin = $this->getAdmin();
@@ -218,10 +217,7 @@ function __interactive() {
}
$vars = $this->__loadController();
if ($vars) {
foreach ($actions as $action) {
$content = $this->getContent($action, $vars);
$this->bake($action, $content);
}
$this->bakeActions($actions);
}
$this->hr();
$this->out('');
@@ -251,6 +247,7 @@ function __interactive() {
}
}
}
/**
* Loads Controller and sets variables for the template
* Available template variables
@@ -307,6 +304,20 @@ function __loadController() {
return compact('modelClass', 'schema', 'primaryKey', 'displayField', 'singularVar', 'pluralVar',
'singularHumanName', 'pluralHumanName', 'fields','associations');
}
/**
* Bake a view file for each of the supplied actions
*
* @param array $actions Array of actions to make files for.
* @return void
**/
function bakeActions($actions) {
foreach ($actions as $action) {
$content = $this->getContent($action, $vars);
$this->bake($action, $content);
}
}
/**
* Assembles and writes bakes the view file.
*
@@ -52,6 +52,16 @@
array('in', '_stop', 'err', 'out', 'createFile')
);
class ViewTaskComment extends Model {
var $name = 'ViewTaskComment';
var $useTable = 'comments';
}
class ViewTaskCommentsController extends Controller {
var $name = 'ViewTaskComments';
}
/**
* ViewTaskTest class
*
@@ -111,8 +121,30 @@ function testGetContent() {
$this->assertPattern('/New Test View Model/', $result);
$this->assertPattern('/testViewModel\[\'TestViewModel\'\]\[\'id\'\]/', $result);
$this->assertPattern('/testViewModel\[\'TestViewModel\'\]\[\'name\'\]/', $result);
$this->assertPattern('/testViewModel\[\'TestViewModel\'\]\[\'name\'\]/', $result);
$this->assertPattern('/testViewModel\[\'TestViewModel\'\]\[\'body\'\]/', $result);
}
/**
* test Bake method
*
* @return void
**/
function testBake() {
$this->Task->path = TMP;
$this->Task->controllerName = 'ViewTaskComments';
$this->Task->controllerPath = 'view_task_comments';
$this->Task->expectAt(0, 'createFile', array(TMP . 'view_task_comments' . DS . 'view.ctp', '*'));
$this->Task->bake('view', true);
$this->Task->expectAt(1, 'createFile', array(TMP . 'view_task_comments' . DS . 'edit.ctp', '*'));
$this->Task->bake('edit', true);
$this->Task->expectAt(2, 'createFile', array(TMP . 'view_task_comments' . DS . 'index.ctp', '*'));
$this->Task->bake('index', true);
@rmdir(TMP . 'view_task_comments');
}
}
?>

0 comments on commit 0a3af5b

Please sign in to comment.
You can’t perform that action at this time.