Skip to content

Commit

Permalink
Add support for --admin to bake controller all.
Browse files Browse the repository at this point in the history
I missed this when originally implementing bake controller all.

Fixes #3536
  • Loading branch information
markstory committed Jan 16, 2013
1 parent 0ed9e3c commit 5a6a45d
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/Cake/Console/Command/Task/ControllerTask.php
Expand Up @@ -105,12 +105,22 @@ public function all() {
$this->listAll($this->connection, false);
ClassRegistry::config('Model', array('ds' => $this->connection));
$unitTestExists = $this->_checkUnitTest();

$admin = false;
if (!empty($this->params['admin'])) {
$admin = $this->Project->getPrefix();
}

foreach ($this->__tables as $table) {
$model = $this->_modelName($table);
$controller = $this->_controllerName($model);
App::uses($model, 'Model');
if (class_exists($model)) {
$actions = $this->bakeActions($controller);
if ($admin) {
$this->out(__d('cake_console', 'Adding %s methods', $admin));
$actions .= "\n" . $this->bakeActions($controller, $admin);
}
if ($this->bake($controller, $actions) && $unitTestExists) {
$this->bakeTest($controller);
}
Expand Down
37 changes: 37 additions & 0 deletions lib/Cake/Test/Case/Console/Command/Task/ControllerTaskTest.php
Expand Up @@ -514,6 +514,7 @@ public function testExecuteIntoAll() {
if (!defined('ARTICLE_MODEL_CREATED')) {
$this->markTestSkipped('Execute into all could not be run as an Article, Tag or Comment model was already loaded.');
}

$this->Task->connection = 'test';
$this->Task->path = '/my/path/';
$this->Task->args = array('all');
Expand All @@ -530,6 +531,42 @@ public function testExecuteIntoAll() {
$this->Task->execute();
}

/**
* Test execute() with all and --admin
*
* @return void
*/
public function testExecuteIntoAllAdmin() {
$count = count($this->Task->listAll('test'));
if ($count != count($this->fixtures)) {
$this->markTestSkipped('Additional tables detected.');
}
if (!defined('ARTICLE_MODEL_CREATED')) {
$this->markTestSkipped('Execute into all could not be run as an Article, Tag or Comment model was already loaded.');
}

$this->Task->connection = 'test';
$this->Task->path = '/my/path/';
$this->Task->args = array('all');
$this->Task->params['admin'] = true;

$this->Task->Project->expects($this->any())
->method('getPrefix')
->will($this->returnValue('admin_'));
$this->Task->expects($this->any())
->method('_checkUnitTest')
->will($this->returnValue(true));
$this->Task->Test->expects($this->once())->method('bake');

$filename = '/my/path/BakeArticlesController.php';
$this->Task->expects($this->once())->method('createFile')->with(
$filename,
$this->stringContains('function admin_index')
)->will($this->returnValue(true));

$this->Task->execute();
}

/**
* test that `cake bake controller foos` works.
*
Expand Down

0 comments on commit 5a6a45d

Please sign in to comment.