Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Adding tests for loading classes from the libs folder
  • Loading branch information
lorenzo committed Mar 12, 2011
1 parent fd84b14 commit ecc6a22
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/Cake/Core/App.php
Expand Up @@ -513,8 +513,8 @@ public static function load($className) {

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) {
Expand Down
20 changes: 20 additions & 0 deletions lib/Cake/tests/cases/libs/app.test.php
Expand Up @@ -657,4 +657,24 @@ function testLoadingVendor() {
$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'));
}
}

0 comments on commit ecc6a22

Please sign in to comment.