Browse Source

Adding tests for loading classes from the libs folder

Jose Lorenzo Rodriguez 15 years ago
parent
commit
ecc6a22b3b
2 changed files with 22 additions and 2 deletions
  1. 2 2
      lib/Cake/Core/App.php
  2. 20 0
      lib/Cake/tests/cases/libs/app.test.php

+ 2 - 2
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) {

+ 20 - 0
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'));
+	}
 }