Skip to content

Commit

Permalink
Update App tests.
Browse files Browse the repository at this point in the history
Don't use App::build() to map the core directories. Instead use files in
TestApp to test objects(). Update documentation a bit and other tests.
  • Loading branch information
markstory committed Sep 9, 2013
1 parent 33913e2 commit 4701a5a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 53 deletions.
25 changes: 9 additions & 16 deletions lib/Cake/Core/App.php
Expand Up @@ -21,25 +21,16 @@
use Cake\Utility\Inflector;

/**
* App is responsible for path management, class location and class loading.
* App is responsible for resource location, and path management.
*
* ### Adding paths
*
* You can add paths to the search indexes App uses to find classes using `App::build()`. Adding
* additional controller paths for example would alter where CakePHP looks for controllers.
* This allows you to split your application up across the filesystem.
*
* ### Packages
*
* CakePHP is organized around the idea of packages, each class belongs to a package or folder where other
* classes reside. You can configure each package location in your application using `App::build('APackage/SubPackage', $paths)`
* to inform the framework where should each class be loaded. Almost every class in the CakePHP framework can be swapped
* by your own compatible implementation. If you wish to use you own class instead of the classes the framework provides,
* just add the class to your libs folder mocking the directory location of where CakePHP expects to find it.
* ### Adding paths
*
* For instance if you'd like to use your own HttpSocket class, put it under
* You can add paths to the search indexes App uses to find resources using `App::build()`. Adding
* additional view paths for example would alter where CakePHP looks for view files.
*
* App/Network/Http/HttpSocket.php
* You can only add paths for Views and Locale files. All class based resources should be mapped
* using your application's autoloader.
*
* ### Inspecting loaded paths
*
Expand Down Expand Up @@ -365,6 +356,8 @@ public static function objects($type, $path = null, $cache = true) {
if (empty($path)) {
$path = static::path($type, $plugin);
}
// TODO write tests and fix objects(Plugin) with plugins
// on unique paths. Perhaps use Plugin::loaded()?
foreach ((array)$path as $dir) {
if ($dir != APP && is_dir($dir)) {
Expand Down Expand Up @@ -421,7 +414,7 @@ protected static function _packageFormat() {
if (empty(static::$_packageFormat)) {
static::$_packageFormat = array(
'View' => array(
'%s' . 'View' . DS
'%s' . 'View' . DS,
),
'Locale' => array(
'%s' . 'Locale' . DS
Expand Down
52 changes: 15 additions & 37 deletions lib/Cake/Test/TestCase/Core/AppTest.php
Expand Up @@ -58,9 +58,6 @@ public function testClassname() {
$this->assertFalse(App::classname('Unknown', 'Controller', 'Controller'));

// Test plugin
App::build(array(
'Plugin' => array(CAKE . 'Test' . DS . 'TestApp' . DS . 'Plugin' . DS)
), App::RESET);
Plugin::load('TestPlugin');
$this->assertEquals('TestPlugin\Utility\TestPluginEngine', App::classname('TestPlugin.TestPlugin', 'Utility', 'Engine'));
$this->assertFalse(App::classname('TestPlugin.Unknown', 'Utility'));
Expand All @@ -87,7 +84,7 @@ public function testClassnameUnknownPlugin() {
public function testBuild() {
$old = App::path('View');
$expected = array(
APP . 'View' . DS
APP . 'View' . DS,
);
$this->assertEquals($expected, $old);

Expand All @@ -96,7 +93,7 @@ public function testBuild() {
$new = App::path('View');
$expected = array(
'/path/to/views/',
APP . 'View' . DS
APP . 'View' . DS,
);
$this->assertEquals($expected, $new);

Expand Down Expand Up @@ -139,9 +136,6 @@ public function testBuild() {
*/
public function testPathWithPlugins() {
$basepath = CAKE . 'Test' . DS . 'TestApp' . DS . 'Plugin' . DS;
App::build(array(
'Plugin' => array($basepath),
));
Plugin::load('TestPlugin');

$result = App::path('Controller', 'TestPlugin');
Expand All @@ -154,23 +148,23 @@ public function testPathWithPlugins() {
* @return void
*/
public function testBuildWithReset() {
$old = App::path('Model');
$old = App::path('View');
$expected = array(
APP . 'Model' . DS
APP . 'View' . DS,
);
$this->assertEquals($expected, $old);

App::build(array('Model' => array('/path/to/models/')), App::RESET);
App::build(array('View' => array('/path/to/views/')), App::RESET);

$new = App::path('Model');
$new = App::path('View');

$expected = array(
'/path/to/models/'
'/path/to/views/'
);
$this->assertEquals($expected, $new);

App::build(); //reset defaults
$defaults = App::path('Model');
$defaults = App::path('View');
$this->assertEquals($old, $defaults);
}

Expand Down Expand Up @@ -209,28 +203,20 @@ public function testListObjects() {
$this->assertTrue(in_array('Dispatcher', $result));
$this->assertTrue(in_array('Router', $result));

App::build(array(
'Model/Behavior' => App::core('Model/Behavior'),
'Controller' => App::core('Controller'),
'Controller/Component' => App::core('Controller/Component'),
'View' => App::core('View'),
'Model' => App::core('Model'),
'View/Helper' => App::core('View/Helper'),
), App::RESET);
$result = App::objects('Model/Behavior', null, false);
$this->assertTrue(in_array('TreeBehavior', $result));
$this->assertContains('PersisterOneBehaviorBehavior', $result);

$result = App::objects('Controller/Component', null, false);
$this->assertTrue(in_array('AuthComponent', $result));
$this->assertContains('AppleComponent', $result);

$result = App::objects('View', null, false);
$this->assertTrue(in_array('JsonView', $result));
$this->assertContains('CustomJsonView', $result);

$result = App::objects('View/Helper', null, false);
$this->assertTrue(in_array('HtmlHelper', $result));
$this->assertContains('BananaHelper', $result);

$result = App::objects('Model', null, false);
$this->assertTrue(in_array('AcoAction', $result));
$this->assertContains('Article', $result);

$result = App::objects('file');
$this->assertFalse($result);
Expand All @@ -241,14 +227,7 @@ public function testListObjects() {

$result = App::objects('NonExistingType');
$this->assertSame(array(), $result);
}

function testMe() {
App::build(array(
'Plugin' => array(
CAKE . 'Test/TestApp/Plugin/'
)
));
$result = App::objects('Plugin', null, false);
$this->assertContains('TestPlugin', $result);
$this->assertContains('TestPluginTwo', $result);
Expand Down Expand Up @@ -355,9 +334,8 @@ public function testThemePath() {
*/
public function testPaths() {
$result = App::paths();
$this->assertArrayHasKey('Plugin', $result);
$this->assertArrayHasKey('Controller', $result);
$this->assertArrayHasKey('Controller/Component', $result);
$this->assertArrayHasKey('View', $result);
$this->assertArrayHasKey('Locale', $result);
}

}

0 comments on commit 4701a5a

Please sign in to comment.