Change case of Controller::$plugin, fixing missing plugin exceptions, tests updated. Also removing no longer needed camelize() calls

This commit is contained in:
Ceeram 2011-05-25 21:14:23 +02:00
parent 3f72c92226
commit 5f97292648
10 changed files with 39 additions and 35 deletions

View file

@ -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');

View file

@ -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();

View file

@ -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', "<info>Plugin Name:</info> %s", $plugin));
$this->out(__d('cake_console', "<info>Plugin Directory:</info> %s", $this->path . $pluginPath));
$this->out(__d('cake_console', "<info>Plugin Directory:</info> %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', '<success>Created:</success> %s in %s', $plugin, $this->path . $pluginPath), 2);
$this->out(__d('cake_console', '<success>Created:</success> %s in %s', $plugin, $this->path . $plugin), 2);
}
return true;

View file

@ -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 (

View file

@ -630,7 +630,6 @@ class App {
}
list($plugin, $name) = pluginSplit($name);
if (!empty($plugin)) {
$plugin = Inflector::camelize($plugin);
if (!CakePlugin::loaded($plugin)) {
return false;
}

View file

@ -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();

View file

@ -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');

View file

@ -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');

View file

@ -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'],
);

View file

@ -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]])) {