mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Add support for --admin to bake controller all.
I missed this when originally implementing bake controller all. Fixes #3536
This commit is contained in:
parent
0ed9e3c120
commit
5a6a45d0d1
2 changed files with 47 additions and 0 deletions
|
@ -105,12 +105,22 @@ class ControllerTask extends BakeTask {
|
|||
$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 @@ class ControllerTaskTest extends CakeTestCase {
|
|||
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 @@ class ControllerTaskTest extends CakeTestCase {
|
|||
$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.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue