Refactoring out bakeActions

Adding tests for bake()
This commit is contained in:
mark_story 2009-06-03 21:59:46 -04:00
parent 91f90b5c05
commit 0a3af5b792
2 changed files with 53 additions and 10 deletions

View file

@ -150,6 +150,7 @@ class ViewTask extends Shell {
}
}
}
/**
* Bake All views for All controllers.
*
@ -167,10 +168,7 @@ class ViewTask extends Shell {
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 @@ class ViewTask extends Shell {
$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 @@ class ViewTask extends Shell {
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 @@ class ViewTask extends Shell {
}
$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 @@ class ViewTask extends Shell {
}
}
}
/**
* Loads Controller and sets variables for the template
* Available template variables
@ -307,6 +304,20 @@ class ViewTask extends Shell {
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.
*

View file

@ -52,6 +52,16 @@ Mock::generatePartial(
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 @@ class ViewTaskTest extends CakeTestCase {
$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');
}
}
?>