Skip to content

Commit

Permalink
Adding -plugin support to Controller Task
Browse files Browse the repository at this point in the history
Test cases added.
  • Loading branch information
markstory committed Jun 7, 2009
1 parent 375e175 commit 4d89086
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
6 changes: 5 additions & 1 deletion cake/console/libs/tasks/controller.php
Expand Up @@ -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;
}
Expand Down
40 changes: 37 additions & 3 deletions cake/tests/cases/console/libs/tasks/controller.test.php
Expand Up @@ -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(
Expand All @@ -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');
Expand Down Expand Up @@ -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)
*
Expand Down Expand Up @@ -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.
*
Expand Down

0 comments on commit 4d89086

Please sign in to comment.