From 7c08c966b0793903891c56d3613e059fb259ff45 Mon Sep 17 00:00:00 2001 From: mark_story Date: Fri, 9 Sep 2011 20:32:01 -0400 Subject: [PATCH] Adding App::uses() call to model baking. Models should always include their parent classes to be safe. Bake should reflect the best practice. Refs #1971 --- lib/Cake/Console/Command/Task/ModelTask.php | 5 ++++- lib/Cake/Console/Templates/default/classes/model.ctp | 4 +++- lib/Cake/Test/Case/Console/Command/Task/ModelTaskTest.php | 3 ++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/Cake/Console/Command/Task/ModelTask.php b/lib/Cake/Console/Command/Task/ModelTask.php index 297532d911f..42325d03f9b 100644 --- a/lib/Cake/Console/Command/Task/ModelTask.php +++ b/lib/Cake/Console/Command/Task/ModelTask.php @@ -743,7 +743,10 @@ public function bake($name, $data = array()) { $data = array_merge($defaults, $data); $this->Template->set($data); - $this->Template->set('plugin', $this->plugin); + $this->Template->set(array( + 'plugin' => $this->plugin, + 'pluginPath' => empty($this->plugin) ? '' : $this->plugin . '.' + )); $out = $this->Template->generate('classes', 'model'); $path = $this->getPath(); diff --git a/lib/Cake/Console/Templates/default/classes/model.ctp b/lib/Cake/Console/Templates/default/classes/model.ctp index 242fa95f405..8b1c51996e2 100644 --- a/lib/Cake/Console/Templates/default/classes/model.ctp +++ b/lib/Cake/Console/Templates/default/classes/model.ctp @@ -19,7 +19,9 @@ * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ -echo " +echo " /** * Model * diff --git a/lib/Cake/Test/Case/Console/Command/Task/ModelTaskTest.php b/lib/Cake/Test/Case/Console/Command/Task/ModelTaskTest.php index 888a33e2fd0..0d2db444a36 100644 --- a/lib/Cake/Test/Case/Console/Command/Task/ModelTaskTest.php +++ b/lib/Cake/Test/Case/Console/Command/Task/ModelTaskTest.php @@ -754,7 +754,8 @@ public function testBakeWithPlugin() { $this->Task->expects($this->once())->method('createFile') ->with($path, new PHPUnit_Framework_Constraint_PCREMatch('/BakeArticle extends ControllerTestAppModel/')); - $this->Task->bake('BakeArticle', array(), array()); + $result = $this->Task->bake('BakeArticle', array(), array()); + $this->assertContains("App::uses('ControllerTestAppModel', 'ControllerTest.Model');", $result); $this->assertEqual(count(ClassRegistry::keys()), 0); $this->assertEqual(count(ClassRegistry::mapKeys()), 0);