From 5f9729264849ea54c2dec73ffaf5a6097e5cecf7 Mon Sep 17 00:00:00 2001 From: Ceeram Date: Wed, 25 May 2011 21:14:23 +0200 Subject: [PATCH] Change case of Controller::$plugin, fixing missing plugin exceptions, tests updated. Also removing no longer needed camelize() calls --- .../Console/Command/Task/ControllerTask.php | 2 +- lib/Cake/Console/Command/Task/ModelTask.php | 2 +- lib/Cake/Console/Command/Task/PluginTask.php | 15 +++++++------ lib/Cake/Controller/Controller.php | 21 +++++++++---------- lib/Cake/Core/App.php | 1 - lib/Cake/Model/CakeSchema.php | 2 +- .../Console/Command/Task/ModelTaskTest.php | 4 ++-- lib/Cake/Test/Case/Routing/DispatcherTest.php | 14 ++++++------- lib/Cake/View/Helper/FormHelper.php | 6 +++++- lib/Cake/View/View.php | 7 +++++-- 10 files changed, 39 insertions(+), 35 deletions(-) diff --git a/lib/Cake/Console/Command/Task/ControllerTask.php b/lib/Cake/Console/Command/Task/ControllerTask.php index bfc38a5c0..d1f1d5236 100644 --- a/lib/Cake/Console/Command/Task/ControllerTask.php +++ b/lib/Cake/Console/Command/Task/ControllerTask.php @@ -311,7 +311,7 @@ class ControllerTask extends BakeTask { $isScaffold = ($actions === 'scaffold') ? true : false; - $this->Template->set('plugin', Inflector::camelize($this->plugin)); + $this->Template->set('plugin', $this->plugin); $this->Template->set(compact('controllerName', 'actions', 'helpers', 'components', 'isScaffold')); $contents = $this->Template->generate('classes', 'controller'); diff --git a/lib/Cake/Console/Command/Task/ModelTask.php b/lib/Cake/Console/Command/Task/ModelTask.php index 06bb17d3a..2380b57eb 100644 --- a/lib/Cake/Console/Command/Task/ModelTask.php +++ b/lib/Cake/Console/Command/Task/ModelTask.php @@ -741,7 +741,7 @@ class ModelTask extends BakeTask { $data = array_merge($defaults, $data); $this->Template->set($data); - $this->Template->set('plugin', Inflector::camelize($this->plugin)); + $this->Template->set('plugin', $this->plugin); $out = $this->Template->generate('classes', 'model'); $path = $this->getPath(); diff --git a/lib/Cake/Console/Command/Task/PluginTask.php b/lib/Cake/Console/Command/Task/PluginTask.php index f2aa0ff56..590e95072 100644 --- a/lib/Cake/Console/Command/Task/PluginTask.php +++ b/lib/Cake/Console/Command/Task/PluginTask.php @@ -76,7 +76,7 @@ class PluginTask extends Shell { } if (!$this->bake($plugin)) { - $this->error(__d('cake_console', "An error occured trying to bake: %s in %s", $plugin, $this->path . Inflector::camelize($plugin))); + $this->error(__d('cake_console', "An error occured trying to bake: %s in %s", $plugin, $this->path . $plugin)); } } @@ -88,20 +88,19 @@ class PluginTask extends Shell { * @return bool */ public function bake($plugin) { - $pluginPath = Inflector::camelize($plugin); $pathOptions = App::path('plugins'); if (count($pathOptions) > 1) { $this->findPath($pathOptions); } $this->hr(); $this->out(__d('cake_console', "Plugin Name: %s", $plugin)); - $this->out(__d('cake_console', "Plugin Directory: %s", $this->path . $pluginPath)); + $this->out(__d('cake_console', "Plugin Directory: %s", $this->path . $plugin)); $this->hr(); $looksGood = $this->in(__d('cake_console', 'Look okay?'), array('y', 'n', 'q'), 'y'); if (strtolower($looksGood) == 'y') { - $Folder = new Folder($this->path . $pluginPath); + $Folder = new Folder($this->path . $plugin); $directories = array( 'Config' . DS . 'schema', 'Model' . DS . 'Behavior', @@ -119,7 +118,7 @@ class PluginTask extends Shell { ); foreach ($directories as $directory) { - $dirPath = $this->path . $pluginPath . DS . $directory; + $dirPath = $this->path . $plugin . DS . $directory; $Folder->create($dirPath); $File = new File($dirPath . DS . 'empty', true); } @@ -139,7 +138,7 @@ class PluginTask extends Shell { $out .= "class {$plugin}AppController extends AppController {\n\n"; $out .= "}\n\n"; $out .= "?>"; - $this->createFile($this->path . $pluginPath. DS . 'Controller' . DS . $controllerFileName, $out); + $this->createFile($this->path . $plugin. DS . 'Controller' . DS . $controllerFileName, $out); $modelFileName = $plugin . 'AppModel.php'; @@ -147,10 +146,10 @@ class PluginTask extends Shell { $out .= "class {$plugin}AppModel extends AppModel {\n\n"; $out .= "}\n\n"; $out .= "?>"; - $this->createFile($this->path . $pluginPath . DS . 'Model' . DS . $modelFileName, $out); + $this->createFile($this->path . $plugin . DS . 'Model' . DS . $modelFileName, $out); $this->hr(); - $this->out(__d('cake_console', 'Created: %s in %s', $plugin, $this->path . $pluginPath), 2); + $this->out(__d('cake_console', 'Created: %s in %s', $plugin, $this->path . $plugin), 2); } return true; diff --git a/lib/Cake/Controller/Controller.php b/lib/Cake/Controller/Controller.php index a6f635970..3cc1e8d6a 100644 --- a/lib/Cake/Controller/Controller.php +++ b/lib/Cake/Controller/Controller.php @@ -440,7 +440,7 @@ class Controller extends Object { */ public function setRequest(CakeRequest $request) { $this->request = $request; - $this->plugin = isset($request->params['plugin']) ? $request->params['plugin'] : null; + $this->plugin = isset($request->params['plugin']) ? Inflector::camelize($request->params['plugin']) : null; $this->view = isset($request->params['action']) ? $request->params['action'] : null; if (isset($request->params['pass']) && isset($request->params['named'])) { $this->passedArgs = array_merge($request->params['pass'], $request->params['named']); @@ -460,15 +460,14 @@ class Controller extends Object { * @return void */ protected function __mergeVars() { - $pluginName = $pluginController = $plugin = null; + $pluginController = $pluginDot = null; if (!empty($this->plugin)) { - $pluginName = Inflector::camelize($this->plugin); - $pluginController = $pluginName . 'AppController'; + $pluginController = $this->plugin . 'AppController'; if (!is_subclass_of($this, $pluginController)) { $pluginController = null; } - $plugin = $pluginName . '.'; + $pluginDot = $this->plugin . '.'; } if (is_subclass_of($this, $this->_mergeParent) || !empty($pluginController)) { @@ -477,13 +476,13 @@ class Controller extends Object { $merge = array('components', 'helpers'); if ($uses == $this->uses && !empty($this->uses)) { - if (!in_array($plugin . $this->modelClass, $this->uses)) { - array_unshift($this->uses, $plugin . $this->modelClass); - } elseif ($this->uses[0] !== $plugin . $this->modelClass) { + if (!in_array($pluginDot . $this->modelClass, $this->uses)) { + array_unshift($this->uses, $pluginDot . $this->modelClass); + } elseif ($this->uses[0] !== $pluginDot . $this->modelClass) { $this->uses = array_flip($this->uses); - unset($this->uses[$plugin . $this->modelClass]); + unset($this->uses[$pluginDot . $this->modelClass]); $this->uses = array_flip($this->uses); - array_unshift($this->uses, $plugin . $this->modelClass); + array_unshift($this->uses, $pluginDot . $this->modelClass); } } elseif ( ($this->uses !== null || $this->uses !== false) && @@ -494,7 +493,7 @@ class Controller extends Object { $this->_mergeVars($merge, $this->_mergeParent, true); } - if ($pluginController && $pluginName != null) { + if ($pluginController && $this->plugin != null) { $merge = array('components', 'helpers'); $appVars = get_class_vars($pluginController); if ( diff --git a/lib/Cake/Core/App.php b/lib/Cake/Core/App.php index 909d478be..e8d98b81c 100644 --- a/lib/Cake/Core/App.php +++ b/lib/Cake/Core/App.php @@ -630,7 +630,6 @@ class App { } list($plugin, $name) = pluginSplit($name); if (!empty($plugin)) { - $plugin = Inflector::camelize($plugin); if (!CakePlugin::loaded($plugin)) { return false; } diff --git a/lib/Cake/Model/CakeSchema.php b/lib/Cake/Model/CakeSchema.php index afb159d0f..b4fd682dd 100644 --- a/lib/Cake/Model/CakeSchema.php +++ b/lib/Cake/Model/CakeSchema.php @@ -206,7 +206,7 @@ class CakeSchema extends Object { $db = ConnectionManager::getDataSource($connection); if (isset($this->plugin)) { - App::uses(Inflector::camelize($this->plugin) . 'AppModel', $this->plugin . '.Model'); + App::uses($this->plugin . 'AppModel', $this->plugin . '.Model'); } $tables = array(); diff --git a/lib/Cake/Test/Case/Console/Command/Task/ModelTaskTest.php b/lib/Cake/Test/Case/Console/Command/Task/ModelTaskTest.php index 4603dfb35..a385f5724 100644 --- a/lib/Cake/Test/Case/Console/Command/Task/ModelTaskTest.php +++ b/lib/Cake/Test/Case/Console/Command/Task/ModelTaskTest.php @@ -555,7 +555,7 @@ class ModelTaskTest extends CakeTestCase { * @return void */ public function testBakeFixture() { - $this->Task->plugin = 'test_plugin'; + $this->Task->plugin = 'TestPlugin'; $this->Task->interactive = true; $this->Task->Fixture->expects($this->at(0))->method('bake')->with('BakeArticle', 'bake_articles'); $this->Task->bakeFixture('BakeArticle', 'bake_articles'); @@ -571,7 +571,7 @@ class ModelTaskTest extends CakeTestCase { * @return void */ public function testBakeTest() { - $this->Task->plugin = 'test_plugin'; + $this->Task->plugin = 'TestPlugin'; $this->Task->interactive = true; $this->Task->Test->expects($this->at(0))->method('bake')->with('Model', 'BakeArticle'); $this->Task->bakeTest('BakeArticle'); diff --git a/lib/Cake/Test/Case/Routing/DispatcherTest.php b/lib/Cake/Test/Case/Routing/DispatcherTest.php index edeee52c1..15e9f6bd4 100644 --- a/lib/Cake/Test/Case/Routing/DispatcherTest.php +++ b/lib/Cake/Test/Case/Routing/DispatcherTest.php @@ -874,7 +874,7 @@ class DispatcherTest extends CakeTestCase { $this->assertEqual($result[$key], $value, 'Value mismatch ' . $key . ' %'); } - $this->assertIdentical($controller->plugin, 'my_plugin'); + $this->assertIdentical($controller->plugin, 'MyPlugin'); $this->assertIdentical($controller->name, 'SomePages'); $this->assertIdentical($controller->params['controller'], 'some_pages'); $this->assertIdentical($controller->passedArgs, array('0' => 'home', 'param'=>'value', 'param2'=>'value2')); @@ -901,7 +901,7 @@ class DispatcherTest extends CakeTestCase { $url = new CakeRequest('my_plugin/other_pages/index/param:value/param2:value2'); $controller = $Dispatcher->dispatch($url, array('return' => 1)); - $this->assertIdentical($controller->plugin, 'my_plugin'); + $this->assertIdentical($controller->plugin, 'MyPlugin'); $this->assertIdentical($controller->name, 'OtherPages'); $this->assertIdentical($controller->action, 'index'); $this->assertIdentical($controller->passedArgs, array('param' => 'value', 'param2' => 'value2')); @@ -936,7 +936,7 @@ class DispatcherTest extends CakeTestCase { $controller = $Dispatcher->dispatch($url, array('return' => 1)); - $this->assertIdentical($controller->plugin, 'my_plugin'); + $this->assertIdentical($controller->plugin, 'MyPlugin'); $this->assertIdentical($controller->name, 'MyPlugin'); $this->assertIdentical($controller->action, 'add'); $this->assertEqual($controller->params['named'], array('param' => 'value', 'param2' => 'value2')); @@ -954,7 +954,7 @@ class DispatcherTest extends CakeTestCase { $url = new CakeRequest($pluginUrl); $controller = $Dispatcher->dispatch($url, array('return' => 1)); - $this->assertIdentical($controller->plugin, 'my_plugin'); + $this->assertIdentical($controller->plugin, 'MyPlugin'); $this->assertIdentical($controller->name, 'MyPlugin'); $this->assertIdentical($controller->action, 'index'); @@ -975,7 +975,7 @@ class DispatcherTest extends CakeTestCase { $this->assertEqual($controller->params['action'], 'admin_add'); $this->assertEqual($controller->params['pass'], array(5)); $this->assertEqual($controller->params['named'], array('param' => 'value', 'param2' => 'value2')); - $this->assertIdentical($controller->plugin, 'my_plugin'); + $this->assertIdentical($controller->plugin, 'MyPlugin'); $this->assertIdentical($controller->name, 'MyPlugin'); $this->assertIdentical($controller->action, 'admin_add'); @@ -983,13 +983,13 @@ class DispatcherTest extends CakeTestCase { $this->assertEqual($controller->passedArgs, $expected); Configure::write('Routing.prefixes', array('admin')); - CakePLugin::load('ArticlesTest', array('path' => '/fake/path')); + CakePlugin::load('ArticlesTest', array('path' => '/fake/path')); Router::reload(); $Dispatcher = new TestDispatcher(); $controller = $Dispatcher->dispatch(new CakeRequest('admin/articles_test'), array('return' => 1)); - $this->assertIdentical($controller->plugin, 'articles_test'); + $this->assertIdentical($controller->plugin, 'ArticlesTest'); $this->assertIdentical($controller->name, 'ArticlesTest'); $this->assertIdentical($controller->action, 'admin_index'); diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index 0140c3eeb..9086f2414 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -261,8 +261,12 @@ class FormHelper extends AppHelper { $options['action'] = $this->request->params['action']; } + $plugin = null; + if ($this->plugin) { + $plugin = Inflector::underscore($this->plugin); + } $actionDefaults = array( - 'plugin' => $this->plugin, + 'plugin' => $plugin, 'controller' => $this->_View->viewPath, 'action' => $options['action'], ); diff --git a/lib/Cake/View/View.php b/lib/Cake/View/View.php index 1a2f75564..59c116aa4 100644 --- a/lib/Cake/View/View.php +++ b/lib/Cake/View/View.php @@ -316,7 +316,11 @@ class View extends Object { } if (isset($options['cache'])) { - $keys = array_merge(array($plugin, $name), array_keys($options), array_keys($data)); + $underscored = null; + if ($plugin) { + $underscored = Inflector::underscore($plugin); + } + $keys = array_merge(array($underscored, $name), array_keys($options), array_keys($data)); $caching = array( 'config' => $this->elementCache, 'key' => implode('_', $keys) @@ -803,7 +807,6 @@ class View extends Object { $viewPaths = App::path('View'); $corePaths = array_flip(App::core('View')); if (!empty($plugin)) { - $plugin = Inflector::camelize($plugin); $count = count($viewPaths); for ($i = 0; $i < $count; $i++) { if (!isset($corePaths[$viewPaths[$i]])) {