mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
Add App::uses to baked controllers.
Controllers should load their dependencies. Bake should help with the best practice. Fixes #1971
This commit is contained in:
parent
7c08c966b0
commit
3cb3424b4f
3 changed files with 13 additions and 5 deletions
|
@ -290,7 +290,8 @@ class ControllerTask extends BakeTask {
|
|||
$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 @@ class ControllerTask extends BakeTask {
|
|||
|
||||
$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 @@ class ControllerTaskTest extends CakeTestCase {
|
|||
$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();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue