Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adding test cases for various permutations of execute()

Allowing admin methods to be baked separately of regular methods.
  • Loading branch information...
commit bb566c3841ce8b0011e754562a289c114a231453 1 parent 8040cc3
@markstory markstory authored
View
40 cake/console/libs/tasks/view.php
@@ -130,7 +130,6 @@ function execute() {
} else {
$vars = $this->__loadController();
if ($vars) {
-
$methods = array_diff(
array_map('strtolower', get_class_methods($this->controllerName . 'Controller')),
array_map('strtolower', get_class_methods('appcontroller'))
@@ -142,7 +141,7 @@ function execute() {
$adminRoute = Configure::read('Routing.admin');
if (!empty($adminRoute)) {
- $adminDelete = $adminRoute.'_delete';
+ $adminDelete = $adminRoute . '_delete';
}
foreach ($methods as $method) {
if ($method{0} != '_' && !in_array($method, array('delete', $adminDelete))) {
@@ -191,10 +190,6 @@ function __interactive() {
$this->connection = $this->DbConfig->getConfig();
}
- $wannaDoAdmin = 'n';
- $wannaDoScaffold = 'y';
- $admin = false;
-
$this->Controller->connection = $this->connection;
$this->controllerName = $this->Controller->getName();
@@ -208,27 +203,25 @@ function __interactive() {
}
$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'), 'y');
- }
-
- if (strtolower($wannaDoAdmin) == 'y') {
- $admin = $this->getAdmin();
- }
+ $wannaDoAdmin = $this->in(__("Would you like to create the views for admin routing?", true), array('y','n'), 'n');
- if (strtolower($wannaDoScaffold) == 'y') {
- $actions = $this->scaffoldActions;
- if ($admin) {
- foreach ($actions as $action) {
- $actions[] = $admin . $action;
- }
- }
+ if (strtolower($wannaDoScaffold) == 'y' || strtolower($wannaDoAdmin) == 'y') {
$vars = $this->__loadController();
- if ($vars) {
+ if (strtolower($wannaDoScaffold) == 'y') {
+ $actions = $this->scaffoldActions;
$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->out('');
$this->out(__("View Scaffolding Complete.\n", true));
@@ -347,7 +340,7 @@ function customAction() {
*/
function bake($action, $content = '') {
if ($content === true) {
- $content = $this->getContent();
+ $content = $this->getContent($action);
}
$filename = $this->path . $this->controllerPath . DS . Inflector::underscore($action) . '.ctp';
$Folder =& new Folder($this->path . $this->controllerPath, true);
@@ -427,6 +420,7 @@ function help() {
$this->out("");
$this->_stop();
}
+
/**
* Returns associations for controllers models.
*
View
93 cake/tests/cases/console/libs/tasks/view.test.php
@@ -58,10 +58,29 @@
class ViewTaskComment extends Model {
var $name = 'ViewTaskComment';
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 {
var $name = 'ViewTaskComments';
+
+ function index() {
+
+ }
+ function add() {
+
+ }
}
@@ -139,13 +158,19 @@ function testBake() {
$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->expectAt(0, 'createFile', array(
+ TMP . 'view_task_comments' . DS . 'view.ctp',
+ new PatternExpectation('/View Task Articles/')
+ ));
$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->expectAt(2, 'createFile', array(
+ TMP . 'view_task_comments' . DS . 'index.ctp',
+ new PatternExpectation('/\$viewTaskComment\[\'Article\'\]\[\'title\'\]/')
+ ));
$this->Task->bake('index', true);
@rmdir(TMP . 'view_task_comments');
@@ -166,6 +191,7 @@ function testBakeActions() {
$this->Task->expectAt(2, 'createFile', array(TMP . 'view_task_comments' . DS . 'index.ctp', '*'));
$this->Task->bakeActions(array('view', 'edit', 'index'), array());
+
@rmdir(TMP . 'view_task_comments');
}
@@ -186,6 +212,7 @@ function testCustomAction() {
$this->Task->expectAt(0, 'createFile', array(TMP . 'view_task_comments' . DS . 'my_action.ctp', '*'));
$this->Task->customAction();
+
@rmdir(TMP . 'view_task_comments');
}
@@ -201,14 +228,76 @@ function testExecuteIntoAll() {
$this->Task->Controller->setReturnValue('listAll', array('view_task_comments'));
$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(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');
}
+/**
+ * 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');
+ }
}
?>
Please sign in to comment.
Something went wrong with that request. Please try again.