From ecc6a22b3b20149c8a370d3f2a6f86319363a956 Mon Sep 17 00:00:00 2001 From: Jose Lorenzo Rodriguez Date: Sat, 12 Mar 2011 01:56:34 -0430 Subject: [PATCH] Adding tests for loading classes from the libs folder --- lib/Cake/Core/App.php | 4 ++-- lib/Cake/tests/cases/libs/app.test.php | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Core/App.php b/lib/Cake/Core/App.php index 4d651abe2..07aea99ef 100644 --- a/lib/Cake/Core/App.php +++ b/lib/Cake/Core/App.php @@ -513,8 +513,8 @@ class App { if (empty($plugin)) { $appLibs = empty(self::$__packages['Lib']) ? APPLIBS : current(self::$__packages['Lib']); - $paths[] = $appLibs . self::$__classMap[$className] . DS; - $paths[] = LIBS . self::$__classMap[$className] . DS; + $paths[] = $appLibs . $package . DS; + $paths[] = LIBS . $package . DS; } foreach ($paths as $path) { diff --git a/lib/Cake/tests/cases/libs/app.test.php b/lib/Cake/tests/cases/libs/app.test.php index 3009b337a..e90e1b06b 100644 --- a/lib/Cake/tests/cases/libs/app.test.php +++ b/lib/Cake/tests/cases/libs/app.test.php @@ -657,4 +657,24 @@ class AppImportTest extends CakeTestCase { $this->assertTrue($result); $this->assertEqual($text, 'This is the welcome.php file in test_plugin/vendors directory'); } + +/** + * Tests that the automatic class loader will also find in "libs" folder for both + * app and plugins if it does not find the class in other configured paths + * + */ + public function testLoadClassInLibs() { + App::build(array( + 'libs' => array(LIBS . 'tests' . DS . 'test_app' . DS . 'libs' . DS), + 'plugins' => array(LIBS . 'tests' . DS . 'test_app' . DS . 'plugins' . DS) + ), true); + + $this->assertFalse(class_exists('CustomLibClass', false)); + App::uses('CustomLibClass', 'TestPlugin.Custom/Package'); + $this->assertTrue(class_exists('CustomLibClass')); + + $this->assertFalse(class_exists('TestUtilityClass', false)); + App::uses('TestUtilityClass', 'Utility'); + $this->assertTrue(class_exists('CustomLibClass')); + } }