Adding test cases for various permutations of execute()

Allowing admin methods to be baked separately of regular methods.
This commit is contained in:
mark_story 2009-06-04 23:35:36 -04:00
parent 8040cc31e5
commit bb566c3841
2 changed files with 108 additions and 25 deletions

View file

@ -130,7 +130,6 @@ class ViewTask extends Shell {
} else { } else {
$vars = $this->__loadController(); $vars = $this->__loadController();
if ($vars) { if ($vars) {
$methods = array_diff( $methods = array_diff(
array_map('strtolower', get_class_methods($this->controllerName . 'Controller')), array_map('strtolower', get_class_methods($this->controllerName . 'Controller')),
array_map('strtolower', get_class_methods('appcontroller')) array_map('strtolower', get_class_methods('appcontroller'))
@ -142,7 +141,7 @@ class ViewTask extends Shell {
$adminRoute = Configure::read('Routing.admin'); $adminRoute = Configure::read('Routing.admin');
if (!empty($adminRoute)) { if (!empty($adminRoute)) {
$adminDelete = $adminRoute.'_delete'; $adminDelete = $adminRoute . '_delete';
} }
foreach ($methods as $method) { foreach ($methods as $method) {
if ($method{0} != '_' && !in_array($method, array('delete', $adminDelete))) { if ($method{0} != '_' && !in_array($method, array('delete', $adminDelete))) {
@ -191,10 +190,6 @@ class ViewTask extends Shell {
$this->connection = $this->DbConfig->getConfig(); $this->connection = $this->DbConfig->getConfig();
} }
$wannaDoAdmin = 'n';
$wannaDoScaffold = 'y';
$admin = false;
$this->Controller->connection = $this->connection; $this->Controller->connection = $this->connection;
$this->controllerName = $this->Controller->getName(); $this->controllerName = $this->Controller->getName();
@ -208,27 +203,25 @@ class ViewTask extends Shell {
} }
$prompt = __("Would you like to create some CRUD views\n(index, add, view, edit) for this controller?\nNOTE: Before doing so, you'll need to create your controller\nand model classes (including associated models).", true); $prompt = __("Would you like to create some CRUD views\n(index, add, view, edit) for this controller?\nNOTE: Before doing so, you'll need to create your controller\nand model classes (including associated models).", true);
$wannaDoScaffold = $this->in($prompt, array('y','n'), 'n'); $wannaDoScaffold = $this->in($prompt, array('y','n'), 'y');
if (strtolower($wannaDoScaffold) == 'y') { $wannaDoAdmin = $this->in(__("Would you like to create the views for admin routing?", true), array('y','n'), 'n');
$wannaDoAdmin = $this->in(__("Would you like to create the views for admin routing?", true), array('y','n'), 'y');
}
if (strtolower($wannaDoAdmin) == 'y') { if (strtolower($wannaDoScaffold) == 'y' || strtolower($wannaDoAdmin) == 'y') {
$admin = $this->getAdmin();
}
if (strtolower($wannaDoScaffold) == 'y') {
$actions = $this->scaffoldActions;
if ($admin) {
foreach ($actions as $action) {
$actions[] = $admin . $action;
}
}
$vars = $this->__loadController(); $vars = $this->__loadController();
if ($vars) { if (strtolower($wannaDoScaffold) == 'y') {
$actions = $this->scaffoldActions;
$this->bakeActions($actions, $vars); $this->bakeActions($actions, $vars);
} }
if (strtolower($wannaDoAdmin) == 'y') {
$admin = $this->getAdmin();
$regularActions = $this->scaffoldActions;
$adminActions = array();
foreach ($regularActions as $action) {
$adminActions[] = $admin . $action;
}
$this->bakeActions($adminActions, $vars);
}
$this->hr(); $this->hr();
$this->out(''); $this->out('');
$this->out(__("View Scaffolding Complete.\n", true)); $this->out(__("View Scaffolding Complete.\n", true));
@ -347,7 +340,7 @@ class ViewTask extends Shell {
*/ */
function bake($action, $content = '') { function bake($action, $content = '') {
if ($content === true) { if ($content === true) {
$content = $this->getContent(); $content = $this->getContent($action);
} }
$filename = $this->path . $this->controllerPath . DS . Inflector::underscore($action) . '.ctp'; $filename = $this->path . $this->controllerPath . DS . Inflector::underscore($action) . '.ctp';
$Folder =& new Folder($this->path . $this->controllerPath, true); $Folder =& new Folder($this->path . $this->controllerPath, true);
@ -427,6 +420,7 @@ class ViewTask extends Shell {
$this->out(""); $this->out("");
$this->_stop(); $this->_stop();
} }
/** /**
* Returns associations for controllers models. * Returns associations for controllers models.
* *

View file

@ -58,10 +58,29 @@ Mock::generate('ControllerTask', 'ViewTaskMockControllerTask');
class ViewTaskComment extends Model { class ViewTaskComment extends Model {
var $name = 'ViewTaskComment'; var $name = 'ViewTaskComment';
var $useTable = 'comments'; var $useTable = 'comments';
var $belongsTo = array(
'Article' => array(
'className' => 'ViewTaskArticle',
'foreignKey' => 'article_id'
)
);
}
class ViewTaskArticle extends Model {
var $name = 'ViewTaskArticle';
var $useTable = 'articles';
} }
class ViewTaskCommentsController extends Controller { class ViewTaskCommentsController extends Controller {
var $name = 'ViewTaskComments'; var $name = 'ViewTaskComments';
function index() {
}
function add() {
}
} }
@ -139,13 +158,19 @@ class ViewTaskTest extends CakeTestCase {
$this->Task->controllerName = 'ViewTaskComments'; $this->Task->controllerName = 'ViewTaskComments';
$this->Task->controllerPath = 'view_task_comments'; $this->Task->controllerPath = 'view_task_comments';
$this->Task->expectAt(0, 'createFile', array(TMP . 'view_task_comments' . DS . 'view.ctp', '*')); $this->Task->expectAt(0, 'createFile', array(
TMP . 'view_task_comments' . DS . 'view.ctp',
new PatternExpectation('/View Task Articles/')
));
$this->Task->bake('view', true); $this->Task->bake('view', true);
$this->Task->expectAt(1, 'createFile', array(TMP . 'view_task_comments' . DS . 'edit.ctp', '*')); $this->Task->expectAt(1, 'createFile', array(TMP . 'view_task_comments' . DS . 'edit.ctp', '*'));
$this->Task->bake('edit', true); $this->Task->bake('edit', true);
$this->Task->expectAt(2, 'createFile', array(TMP . 'view_task_comments' . DS . 'index.ctp', '*')); $this->Task->expectAt(2, 'createFile', array(
TMP . 'view_task_comments' . DS . 'index.ctp',
new PatternExpectation('/\$viewTaskComment\[\'Article\'\]\[\'title\'\]/')
));
$this->Task->bake('index', true); $this->Task->bake('index', true);
@rmdir(TMP . 'view_task_comments'); @rmdir(TMP . 'view_task_comments');
@ -166,6 +191,7 @@ class ViewTaskTest extends CakeTestCase {
$this->Task->expectAt(2, 'createFile', array(TMP . 'view_task_comments' . DS . 'index.ctp', '*')); $this->Task->expectAt(2, 'createFile', array(TMP . 'view_task_comments' . DS . 'index.ctp', '*'));
$this->Task->bakeActions(array('view', 'edit', 'index'), array()); $this->Task->bakeActions(array('view', 'edit', 'index'), array());
@rmdir(TMP . 'view_task_comments'); @rmdir(TMP . 'view_task_comments');
} }
@ -186,6 +212,7 @@ class ViewTaskTest extends CakeTestCase {
$this->Task->expectAt(0, 'createFile', array(TMP . 'view_task_comments' . DS . 'my_action.ctp', '*')); $this->Task->expectAt(0, 'createFile', array(TMP . 'view_task_comments' . DS . 'my_action.ctp', '*'));
$this->Task->customAction(); $this->Task->customAction();
@rmdir(TMP . 'view_task_comments'); @rmdir(TMP . 'view_task_comments');
} }
@ -201,14 +228,76 @@ class ViewTaskTest extends CakeTestCase {
$this->Task->Controller->setReturnValue('listAll', array('view_task_comments')); $this->Task->Controller->setReturnValue('listAll', array('view_task_comments'));
$this->Task->Controller->expectOnce('listAll'); $this->Task->Controller->expectOnce('listAll');
$this->Task->expectCallCount('createFile', 4);
$this->Task->expectAt(0, 'createFile', array(TMP . 'view_task_comments' . DS . 'index.ctp', '*')); $this->Task->expectAt(0, 'createFile', array(TMP . 'view_task_comments' . DS . 'index.ctp', '*'));
$this->Task->expectAt(1, 'createFile', array(TMP . 'view_task_comments' . DS . 'view.ctp', '*')); $this->Task->expectAt(1, 'createFile', array(TMP . 'view_task_comments' . DS . 'view.ctp', '*'));
$this->Task->expectAt(2, 'createFile', array(TMP . 'view_task_comments' . DS . 'add.ctp', '*')); $this->Task->expectAt(2, 'createFile', array(TMP . 'view_task_comments' . DS . 'add.ctp', '*'));
$this->Task->expectAt(3, 'createFile', array(TMP . 'view_task_comments' . DS . 'edit.ctp', '*')); $this->Task->expectAt(3, 'createFile', array(TMP . 'view_task_comments' . DS . 'edit.ctp', '*'));
$this->Task->execute(); $this->Task->execute();
@rmdir(TMP . 'view_task_comments'); @rmdir(TMP . 'view_task_comments');
} }
/**
* test `cake bake view $controller view`
*
* @return void
**/
function testExecuteWithActionParam() {
$this->Task->path = TMP;
$this->Task->args[0] = 'ViewTaskComments';
$this->Task->args[1] = 'view';
$this->Task->expectCallCount('createFile', 1);
$this->Task->expectAt(0, 'createFile', array(TMP . 'view_task_comments' . DS . 'view.ctp', '*'));
$this->Task->execute();
@rmdir(TMP . 'view_task_comments');
}
/**
* test `cake bake view $controller`
*
* @return void
**/
function testExecuteWithController() {
$this->Task->path = TMP;
$this->Task->args[0] = 'ViewTaskComments';
$this->Task->expectCallCount('createFile', 2);
$this->Task->expectAt(0, 'createFile', array(TMP . 'view_task_comments' . DS . 'index.ctp', '*'));
$this->Task->expectAt(1, 'createFile', array(TMP . 'view_task_comments' . DS . 'add.ctp', '*'));
$this->Task->execute();
@rmdir(TMP . 'view_task_comments');
}
/**
* test execute into interactive.
*
* @return void
**/
function testExecuteInteractive() {
$this->Task->path = TMP;
$this->Task->connection = 'test_suite';
$this->Task->args = array();
$this->Task->Controller->setReturnValue('getName', 'ViewTaskComments');
$this->Task->setReturnValue('in', 'y');
$this->Task->setReturnValueAt(0, 'in', 'y');
$this->Task->setReturnValueAt(1, 'in', 'y');
$this->Task->setReturnValueAt(2, 'in', 'n');
$this->Task->expectCallCount('createFile', 4);
$this->Task->expectAt(0, 'createFile', array(TMP . 'view_task_comments' . DS . 'index.ctp', '*'));
$this->Task->expectAt(1, 'createFile', array(TMP . 'view_task_comments' . DS . 'view.ctp', '*'));
$this->Task->expectAt(2, 'createFile', array(TMP . 'view_task_comments' . DS . 'add.ctp', '*'));
$this->Task->expectAt(3, 'createFile', array(TMP . 'view_task_comments' . DS . 'edit.ctp', '*'));
$this->Task->execute();
@rmdir(TMP . 'view_task_comments');
}
} }
?> ?>