Skip to content
Permalink
Browse files

Add App::uses to baked controllers.

Controllers should load their dependencies.
Bake should help with the best practice.
Fixes #1971
  • Loading branch information...
markstory committed Sep 10, 2011
1 parent 7c08c96 commit 3cb3424b4f646a9e8d06c1bae2a18333cba53dad
@@ -290,7 +290,8 @@ public function bakeActions($controllerName, $admin = null, $wannaUseSession = t
$displayField = $modelObj->displayField;
$primaryKey = $modelObj->primaryKey;
$this->Template->set(compact('plugin', 'admin', 'controllerPath', 'pluralName', 'singularName',
$this->Template->set(compact(
'plugin', 'admin', 'controllerPath', 'pluralName', 'singularName',
'singularHumanName', 'pluralHumanName', 'modelObj', 'wannaUseSession', 'currentModelName',
'displayField', 'primaryKey'
));
@@ -312,7 +313,10 @@ public function bake($controllerName, $actions = '', $helpers = null, $component
$isScaffold = ($actions === 'scaffold') ? true : false;
$this->Template->set('plugin', $this->plugin);
$this->Template->set(array(
'plugin' => $this->plugin,
'pluginPath' => empty($this->plugin) ? '' : $this->plugin . '.'
));
$this->Template->set(compact('controllerName', 'actions', 'helpers', 'components', 'isScaffold'));
$contents = $this->Template->generate('classes', 'controller');
@@ -20,6 +20,7 @@
*/
echo "<?php\n";
echo "App::uses('{$plugin}AppController', '{$pluginPath}Controller');\n";
?>
/**
* <?php echo $controllerName; ?> Controller
@@ -315,15 +315,18 @@ public function testBakeWithPlugin() {
$this->Task->expects($this->at(3))->method('createFile')->with(
$path,
new PHPUnit_Framework_Constraint_PCREMatch('/ArticlesController extends ControllerTestAppController/')
);
)->will($this->returnValue(true));
$this->Task->bake('Articles', '--actions--', array(), array(), array());
$this->Task->plugin = 'ControllerTest';
$path = APP . 'Plugin' . DS . 'ControllerTest' . DS . 'Controller' . DS . 'ArticlesController.php';
$this->Task->bake('Articles', '--actions--', array(), array(), array());
$result = $this->Task->bake('Articles', '--actions--', array(), array(), array());
$this->assertContains("App::uses('ControllerTestAppController', 'ControllerTest.Controller');", $result);
$this->assertEquals('ControllerTest', $this->Task->Template->templateVars['plugin']);
$this->assertEquals('ControllerTest.', $this->Task->Template->templateVars['pluginPath']);
$this->assertEqual($this->Task->Template->templateVars['plugin'], 'ControllerTest');
CakePlugin::unload();
}

0 comments on commit 3cb3424

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