Permalink
Browse files

Add support for --admin to bake controller all.

I missed this when originally implementing bake controller all.

Fixes #3536
  • Loading branch information...
markstory committed Jan 16, 2013
1 parent 0ed9e3c commit 5a6a45d0d1b9e4f844e950939c63204b4c0d2065
@@ -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);
}
@@ -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');
@@ -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.
*

0 comments on commit 5a6a45d

Please sign in to comment.