From 022702506e7639002d0a5928f60e44c71adfed05 Mon Sep 17 00:00:00 2001 From: Jose Lorenzo Rodriguez Date: Wed, 9 Mar 2011 22:11:13 -0430 Subject: [PATCH] Properly testing the App::build() method and bugfixing some issues --- lib/Cake/Core/App.php | 15 +++- lib/Cake/bootstrap.php | 2 +- lib/Cake/tests/cases/libs/app.test.php | 104 +++++++++++++++++++++++-- 3 files changed, 110 insertions(+), 11 deletions(-) diff --git a/lib/Cake/Core/App.php b/lib/Cake/Core/App.php index 583143e8a..709fc8965 100644 --- a/lib/Cake/Core/App.php +++ b/lib/Cake/Core/App.php @@ -226,10 +226,10 @@ class App { 'behaviors' => 'Model/Behavior', 'datasources' => 'Model/Datasource', 'controllers' => 'Controller', - 'components' => 'Model/Datasource', + 'components' => 'Controller/Component', 'views' => 'View', 'helpers' => 'View/Helper', - 'shells' => 'Console' + 'shells' => 'Console/Command' ); /** @@ -329,6 +329,16 @@ class App { return $paths; } + //Provides Backwards compatibility for old-style package names + $legacyPaths = array(); + foreach ($paths as $type => $path) { + if (!empty(self::$legacy[$type])) { + $type = self::$legacy[$type]; + } + $legacyPaths[$type] = $path; + } + + $paths = $legacyPaths; $defaults = array(); foreach (self::$__packageFormat as $package => $format) { foreach ($format as $f) { @@ -340,7 +350,6 @@ class App { $appLibs = empty($paths['libs']) ? $defaults['libs'] : $paths['libs']; foreach ($defaults as $type => $default) { - if (empty(self::$__packages[$type]) || empty($paths)) { self::$__packages[$type] = $default; } diff --git a/lib/Cake/bootstrap.php b/lib/Cake/bootstrap.php index 2ec1d4e0d..459d60196 100644 --- a/lib/Cake/bootstrap.php +++ b/lib/Cake/bootstrap.php @@ -192,7 +192,7 @@ if (!defined('TMP')) { * Path to the vendors directory. */ if (!defined('VENDORS')) { - define('VENDORS', CAKE_CORE_INCLUDE_PATH.DS.'vendors'.DS); + define('VENDORS', ROOT . DS . 'vendors' . DS); } /** diff --git a/lib/Cake/tests/cases/libs/app.test.php b/lib/Cake/tests/cases/libs/app.test.php index d9ba83066..4323f8db1 100644 --- a/lib/Cake/tests/cases/libs/app.test.php +++ b/lib/Cake/tests/cases/libs/app.test.php @@ -14,11 +14,37 @@ class AppImportTest extends CakeTestCase { * @return void */ function testBuild() { + $old = App::path('Model'); + $expected = array( + APP . 'models' . DS + ); + $this->assertEqual($expected, $old); + + App::build(array('Model' => array('/path/to/models/'))); + + $new = App::path('Model'); + + $expected = array( + '/path/to/models/', + APP . 'models' . DS + ); + $this->assertEqual($expected, $new); + + App::build(); //reset defaults + $defaults = App::path('Model'); + $this->assertEqual($old, $defaults); + } + +/** + * tests that it is possible to set up paths using the cake 1.3 notation for them (models, behaviors, controllers...) + * + * @access public + * @return void + */ + function testCompatibleBuild() { $old = App::path('models'); $expected = array( - APP . 'models' . DS, - APP, - LIBS . 'model' . DS + APP . 'models' . DS ); $this->assertEqual($expected, $old); @@ -28,14 +54,78 @@ class AppImportTest extends CakeTestCase { $expected = array( '/path/to/models/', - APP . 'models' . DS, - APP, - LIBS . 'model' . DS + APP . 'models' . DS ); $this->assertEqual($expected, $new); + $this->assertEqual($expected, App::path('Model')); + + App::build(array('datasources' => array('/path/to/datasources/'))); + $expected = array( + '/path/to/datasources/', + APP . 'models' . DS . 'datasources' . DS + ); + $result = App::path('datasources'); + $this->assertEqual($expected, $result); + $this->assertEqual($expected, App::path('Model/Datasource')); + + App::build(array('behaviors' => array('/path/to/behaviors/'))); + $expected = array( + '/path/to/behaviors/', + APP . 'models' . DS . 'behaviors' . DS + ); + $result = App::path('behaviors'); + $this->assertEqual($expected, $result); + $this->assertEqual($expected, App::path('Model/Behavior')); + + App::build(array('controllers' => array('/path/to/controllers/'))); + $expected = array( + '/path/to/controllers/', + APP . 'controllers' . DS + ); + $result = App::path('controllers'); + $this->assertEqual($expected, $result); + $this->assertEqual($expected, App::path('Controller')); + + App::build(array('components' => array('/path/to/components/'))); + $expected = array( + '/path/to/components/', + APP . 'controllers' . DS . 'components' . DS + ); + $result = App::path('components'); + $this->assertEqual($expected, $result); + $this->assertEqual($expected, App::path('Controller/Component')); + + App::build(array('views' => array('/path/to/views/'))); + $expected = array( + '/path/to/views/', + APP . 'views' . DS + ); + $result = App::path('views'); + $this->assertEqual($expected, $result); + $this->assertEqual($expected, App::path('View')); + + App::build(array('helpers' => array('/path/to/helpers/'))); + $expected = array( + '/path/to/helpers/', + APP . 'views' . DS . 'helpers' . DS + ); + $result = App::path('helpers'); + $this->assertEqual($expected, $result); + $this->assertEqual($expected, App::path('View/Helper')); + + App::build(array('shells' => array('/path/to/shells/'))); + $expected = array( + '/path/to/shells/', + APP . 'console' . DS . 'shells' . DS, + APP . 'vendors' . DS . 'shells' . DS, + ROOT . DS . 'vendors' . DS . 'shells' . DS + ); + $result = App::path('shells'); + $this->assertEqual($expected, $result); + $this->assertEqual($expected, App::path('Console/Command')); App::build(); //reset defaults - $defaults = App::path('models'); + $defaults = App::path('Model'); $this->assertEqual($old, $defaults); }