Skip to content
Permalink
Browse files

Adding -plugin support to Controller Task

Test cases added.
  • Loading branch information...
markstory committed Jun 7, 2009
1 parent 375e175 commit 4d89086146e8635535f4a690dcefbae0b5f716b0
Showing with 42 additions and 4 deletions.
  1. +5 −1 cake/console/libs/tasks/controller.php
  2. +37 −3 cake/tests/cases/console/libs/tasks/controller.test.php
@@ -310,7 +310,11 @@ function bake($controllerName, $actions = '', $helpers = null, $components = nul
$this->Template->set(compact('controllerName', 'actions', 'helpers', 'components', 'isScaffold'));
$contents = $this->Template->generate('objects', 'controller');
$filename = $this->path . $this->_controllerPath($controllerName) . '_controller.php';
$path = $this->path;
if (isset($this->plugin)) {
$path = $this->_pluginPath($this->plugin) . 'controllers' . DS;
}
$filename = $path . $this->_controllerPath($controllerName) . '_controller.php';
if ($this->createFile($filename, $contents)) {
return $contents;
}
@@ -34,6 +34,7 @@
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'controller.php';
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'model.php';
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'template.php';
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'test.php';
Mock::generatePartial(
@@ -51,6 +52,8 @@
array('in', 'out', 'err', 'createFile', '_stop', '_checkUnitTest')
);
Mock::generate('TestTask', 'ControllerMockTestTask');
$imported = App::import('Model', 'Article');
$imported = $imported || App::import('Model', 'Comment');
$imported = $imported || App::import('Model', 'Tag');
@@ -223,22 +226,36 @@ function testConfirmController() {
function testBake() {
$helpers = array('Ajax', 'Time');
$components = array('Acl', 'Auth');
$uses = array('Comment', 'User');
$this->Task->setReturnValue('createFile', true);
$result = $this->Task->bake('Articles', '--actions--', $helpers, $components, $uses);
$result = $this->Task->bake('Articles', '--actions--', $helpers, $components);
$this->assertPattern('/class ArticlesController extends AppController/', $result);
$this->assertPattern('/\$components \= array\(\'Acl\', \'Auth\'\)/', $result);
$this->assertPattern('/\$helpers \= array\(\'Html\', \'Form\', \'Ajax\', \'Time\'\)/', $result);
$this->assertPattern('/\-\-actions\-\-/', $result);
$result = $this->Task->bake('Articles', 'scaffold', $helpers, $components, $uses);
$result = $this->Task->bake('Articles', 'scaffold', $helpers, $components);
$this->assertPattern('/class ArticlesController extends AppController/', $result);
$this->assertPattern('/var \$scaffold/', $result);
$this->assertNoPattern('/helpers/', $result);
$this->assertNoPattern('/components/', $result);
}
/**
* test bake() with a -plugin param
*
* @return void
**/
function testBakeWithPlugin() {
$this->Task->plugin = 'ControllerTest';
$helpers = array('Ajax', 'Time');
$components = array('Acl', 'Auth');
$uses = array('Comment', 'User');
$path = APP . 'plugins' . DS . 'controller_test' . DS . 'controllers' . DS . 'articles_controller.php';
$this->Task->expectAt(0, 'createFile', array($path, '*'));
$this->Task->bake('Articles', '--actions--', array(), array(), array());
}
/**
* test that bakeActions is creating the correct controller Code. (Using sessions)
*
@@ -317,6 +334,23 @@ function testBakeActionsWithNoSessions() {
$this->assertTrue(strpos($result, "\$this->flash(__('Article deleted', true), array('action'=>'index'))") !== false);
}
/**
* test baking a test
*
* @return void
**/
function testBakeTest() {
$this->Task->plugin = 'ControllerTest';
$this->Task->connection = 'test_suite';
$this->Task->Test =& new ControllerMockTestTask();
$this->Task->Test->expectOnce('bake', array('Controller', 'Articles'));
$this->Task->bakeTest('Articles');
$this->assertEqual($this->Task->plugin, $this->Task->Test->plugin);
$this->assertEqual($this->Task->connection, $this->Task->Test->connection);
}
/**
* test Interactive mode.
*

0 comments on commit 4d89086

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