From 54eb934892e810959503dcb259eab6c49f009b50 Mon Sep 17 00:00:00 2001 From: Jose Lorenzo Rodriguez Date: Tue, 10 May 2011 00:46:24 -0430 Subject: [PATCH] Fixing plugin related tests in Core package --- lib/Cake/Core/App.php | 14 ++++++++++--- lib/Cake/View/View.php | 2 +- lib/Cake/tests/Case/Core/AppTest.php | 23 ++++++++++++++++------ lib/Cake/tests/Case/Core/ConfigureTest.php | 7 ++++--- lib/Cake/tests/Case/Core/ObjectTest.php | 23 +++++++++------------- 5 files changed, 42 insertions(+), 27 deletions(-) diff --git a/lib/Cake/Core/App.php b/lib/Cake/Core/App.php index 8a6aba93e..b0104918c 100644 --- a/lib/Cake/Core/App.php +++ b/lib/Cake/Core/App.php @@ -92,7 +92,7 @@ class App { 'class' => array('extends' => null, 'core' => true), 'file' => array('extends' => null, 'core' => true), 'model' => array('extends' => 'AppModel', 'core' => false), - 'behavior' => array('extends' => 'ModelBehavior', 'core' => true), + 'behavior' => array( 'suffix' => 'Behavior', 'extends' => 'Model/ModelBehavior', 'core' => true), 'controller' => array('suffix' => 'Controller', 'extends' => 'AppController', 'core' => true), 'component' => array('suffix' => 'Component', 'extends' => null, 'core' => true), 'lib' => array('extends' => null, 'core' => true), @@ -643,6 +643,9 @@ class App { list($plugin, $name) = pluginSplit($name); if (!empty($plugin)) { $plugin = Inflector::camelize($plugin); + if (!CakePlugin::loaded($plugin)) { + return false; + } } if (!$specialPackage) { @@ -679,10 +682,15 @@ class App { $suffix = self::$types[$originalType]['suffix']; $name .= ($suffix == $name) ? '' : $suffix; } - if ($parent && isset(self::$types[$originalType]['extends'])) { $extends = self::$types[$originalType]['extends']; - App::uses($extends, $type); + $extendType = $type; + if (strpos($extends, '/') !== false) { + $parts = explode('/', $extends); + $extends = array_pop($parts); + $extendType = implode('/', $parts); + } + App::uses($extends, $extendType); if ($plugin && in_array($originalType, array('controller', 'model'))) { App::uses($plugin . $extends, $plugin . '.' .$type); } diff --git a/lib/Cake/View/View.php b/lib/Cake/View/View.php index a9831356b..91dd15696 100644 --- a/lib/Cake/View/View.php +++ b/lib/Cake/View/View.php @@ -802,8 +802,8 @@ class View extends Object { $paths = array(); $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]])) { diff --git a/lib/Cake/tests/Case/Core/AppTest.php b/lib/Cake/tests/Case/Core/AppTest.php index 3b40453d8..4f4450b5f 100644 --- a/lib/Cake/tests/Case/Core/AppTest.php +++ b/lib/Cake/tests/Case/Core/AppTest.php @@ -7,6 +7,15 @@ */ class AppImportTest extends CakeTestCase { +/** + * tearDown method + * + * @return void + */ + public function tearDown() { + CakePlugin::unload(); + } + /** * testBuild method * @@ -311,6 +320,7 @@ class AppImportTest extends CakeTestCase { 'Model' => array(LIBS . 'tests' . DS . 'test_app' . DS . 'Model' . DS), 'plugins' => array(LIBS . 'tests' . DS . 'test_app' . DS . 'plugins' . DS) )); + CakePlugin::loadAll(); $result = App::objects('TestPlugin.model'); $this->assertTrue(in_array('TestPluginPost', $result)); @@ -361,16 +371,14 @@ class AppImportTest extends CakeTestCase { App::build(array( 'plugins' => array(LIBS . 'tests' . DS . 'test_app' . DS . 'plugins' . DS) )); - $path = App::pluginPath('test_plugin'); - $expected = LIBS . 'tests' . DS . 'test_app' . DS . 'plugins' . DS . 'test_plugin' . DS; - $this->assertEqual($path, $expected); + CakePlugin::loadAll(); $path = App::pluginPath('TestPlugin'); - $expected = LIBS . 'tests' . DS . 'test_app' . DS . 'plugins' . DS . 'test_plugin' . DS; + $expected = LIBS . 'tests' . DS . 'test_app' . DS . 'plugins' . DS . 'TestPlugin' . DS; $this->assertEqual($path, $expected); $path = App::pluginPath('TestPluginTwo'); - $expected = LIBS . 'tests' . DS . 'test_app' . DS . 'plugins' . DS . 'test_plugin_two' . DS; + $expected = LIBS . 'tests' . DS . 'test_app' . DS . 'plugins' . DS . 'TestPluginTwo' . DS; $this->assertEqual($path, $expected); App::build(); } @@ -438,7 +446,7 @@ class AppImportTest extends CakeTestCase { $file = App::import('Model', array('NonExistingPlugin.NonExistingModel'), false); $this->assertFalse($file); - if (!class_exists('AppController')) { + if (!class_exists('AppController', false)) { $classes = array_flip(get_declared_classes()); $this->assertFalse(isset($classes['PagesController'])); @@ -485,6 +493,7 @@ class AppImportTest extends CakeTestCase { 'libs' => array(LIBS . 'tests' . DS . 'test_app' . DS . 'Lib' . DS), 'plugins' => array(LIBS . 'tests' . DS . 'test_app' . DS . 'plugins' . DS) )); + CakePlugin::loadAll(); $result = App::import('Controller', 'TestPlugin.Tests'); $this->assertTrue($result); @@ -662,6 +671,7 @@ class AppImportTest extends CakeTestCase { 'plugins' => array(LIBS . 'tests' . DS . 'test_app' . DS . 'plugins' . DS), 'vendors' => array(LIBS . 'tests' . DS . 'test_app' . DS . 'vendors'. DS), ), App::RESET); + CakePlugin::loadAll(); ob_start(); $result = App::import('Vendor', 'css/TestAsset', array('ext' => 'css')); @@ -718,6 +728,7 @@ class AppImportTest extends CakeTestCase { 'libs' => array(LIBS . 'tests' . DS . 'test_app' . DS . 'libs' . DS), 'plugins' => array(LIBS . 'tests' . DS . 'test_app' . DS . 'plugins' . DS) ), App::RESET); + CakePlugin::loadAll(); $this->assertFalse(class_exists('CustomLibClass', false)); App::uses('CustomLibClass', 'TestPlugin.Custom/Package'); diff --git a/lib/Cake/tests/Case/Core/ConfigureTest.php b/lib/Cake/tests/Case/Core/ConfigureTest.php index d4ed6b634..1f51633d5 100644 --- a/lib/Cake/tests/Case/Core/ConfigureTest.php +++ b/lib/Cake/tests/Case/Core/ConfigureTest.php @@ -243,18 +243,19 @@ class ConfigureTest extends CakeTestCase { function testLoadPlugin() { App::build(array('plugins' => array(LIBS . 'tests' . DS . 'test_app' . DS . 'plugins' . DS)), true); Configure::config('test', new PhpReader()); - - $result = Configure::load('test_plugin.load', 'test'); + CakePlugin::load('TestPlugin'); + $result = Configure::load('TestPlugin.load', 'test'); $this->assertTrue($result); $expected = '/test_app/plugins/test_plugin/config/load.php'; $config = Configure::read('plugin_load'); $this->assertEqual($config, $expected); - $result = Configure::load('test_plugin.more.load', 'test'); + $result = Configure::load('TestPlugin.more.load', 'test'); $this->assertTrue($result); $expected = '/test_app/plugins/test_plugin/config/more.load.php'; $config = Configure::read('plugin_more_load'); $this->assertEqual($config, $expected); + CakePlugin::unload(); } /** diff --git a/lib/Cake/tests/Case/Core/ObjectTest.php b/lib/Cake/tests/Case/Core/ObjectTest.php index 8566057df..c21b06855 100644 --- a/lib/Cake/tests/Case/Core/ObjectTest.php +++ b/lib/Cake/tests/Case/Core/ObjectTest.php @@ -18,6 +18,7 @@ */ App::uses('Object', 'Core'); +App::uses('Router', 'Routing'); App::uses('Controller', 'Controller'); App::uses('Model', 'Model'); @@ -355,17 +356,9 @@ class ObjectTest extends CakeTestCase { * @return void */ function tearDown() { - unset($this->object); - } - -/** - * endTest - * - * @access public - * @return void - */ - function endTest() { App::build(); + CakePlugin::unload(); + unset($this->object); } /** @@ -725,7 +718,7 @@ class ObjectTest extends CakeTestCase { App::build(array( 'plugins' => array(LIBS . 'tests' . DS . 'test_app' . DS . 'plugins' . DS), )); - App::objects('plugin', null, false); + CakePlugin::loadAll(); Router::reload(); $result = $this->object->requestAction('/test_plugin/tests/index', array('return')); @@ -753,7 +746,7 @@ class ObjectTest extends CakeTestCase { $this->assertEqual($result, $expected); App::build(); - App::objects('plugin', null, false); + CakePlugin::unload(); } /** @@ -765,9 +758,11 @@ class ObjectTest extends CakeTestCase { App::build(array( 'models' => array(LIBS . 'tests' . DS . 'test_app' . DS . 'Model' . DS), 'views' => array(LIBS . 'tests' . DS . 'test_app' . DS . 'View' . DS), - 'controllers' => array(LIBS . 'tests' . DS . 'test_app' . DS . 'Controller' . DS) + 'controllers' => array(LIBS . 'tests' . DS . 'test_app' . DS . 'Controller' . DS), + 'plugins' => array(LIBS . 'tests' . DS . 'test_app' . DS . 'plugins'. DS) )); - + CakePlugin::loadAll(); + $result = $this->object->requestAction( array('controller' => 'request_action', 'action' => 'test_request_action') );