Skip to content

Commit

Permalink
Fixing plugin related tests in Core package
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed May 10, 2011
1 parent a8122a5 commit 54eb934
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 27 deletions.
14 changes: 11 additions & 3 deletions lib/Cake/Core/App.php
Expand Up @@ -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),
Expand Down Expand Up @@ -643,6 +643,9 @@ public static function import($type = null, $name = null, $parent = true, $searc
list($plugin, $name) = pluginSplit($name);
if (!empty($plugin)) {
$plugin = Inflector::camelize($plugin);
if (!CakePlugin::loaded($plugin)) {
return false;
}
}

if (!$specialPackage) {
Expand Down Expand Up @@ -679,10 +682,15 @@ private function _loadClass($name, $plugin, $type, $originalType, $parent) {
$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);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/View/View.php
Expand Up @@ -802,8 +802,8 @@ protected function _paths($plugin = null, $cached = true) {
$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]])) {
Expand Down
23 changes: 17 additions & 6 deletions lib/Cake/tests/Case/Core/AppTest.php
Expand Up @@ -7,6 +7,15 @@
*/
class AppImportTest extends CakeTestCase {

/**
* tearDown method
*
* @return void
*/
public function tearDown() {
CakePlugin::unload();
}

/**
* testBuild method
*
Expand Down Expand Up @@ -311,6 +320,7 @@ function testListObjectsInPlugin() {
'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));
Expand Down Expand Up @@ -361,16 +371,14 @@ function testPluginPath() {
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();
}
Expand Down Expand Up @@ -438,7 +446,7 @@ function testClassLoading() {
$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']));
Expand Down Expand Up @@ -485,6 +493,7 @@ function testPluginImporting() {
'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);
Expand Down Expand Up @@ -662,6 +671,7 @@ function testLoadingVendor() {
'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'));
Expand Down Expand Up @@ -718,6 +728,7 @@ public function testLoadClassInLibs() {
'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');
Expand Down
7 changes: 4 additions & 3 deletions lib/Cake/tests/Case/Core/ConfigureTest.php
Expand Up @@ -243,18 +243,19 @@ function testLoadNoMerge() {
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();
}

/**
Expand Down
23 changes: 9 additions & 14 deletions lib/Cake/tests/Case/Core/ObjectTest.php
Expand Up @@ -18,6 +18,7 @@
*/

App::uses('Object', 'Core');
App::uses('Router', 'Routing');
App::uses('Controller', 'Controller');
App::uses('Model', 'Model');

Expand Down Expand Up @@ -355,17 +356,9 @@ function setUp() {
* @return void
*/
function tearDown() {
unset($this->object);
}

/**
* endTest
*
* @access public
* @return void
*/
function endTest() {
App::build();
CakePlugin::unload();
unset($this->object);
}

/**
Expand Down Expand Up @@ -725,7 +718,7 @@ function testRequestActionPlugins() {
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'));
Expand Down Expand Up @@ -753,7 +746,7 @@ function testRequestActionPlugins() {
$this->assertEqual($result, $expected);

App::build();
App::objects('plugin', null, false);
CakePlugin::unload();
}

/**
Expand All @@ -765,9 +758,11 @@ function testRequestActionArray() {
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')
);
Expand Down

0 comments on commit 54eb934

Please sign in to comment.