2010-11-14 18:06:25 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
2011-05-24 07:05:23 +00:00
|
|
|
* AppTest class
|
2010-11-14 18:06:25 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Core
|
2010-11-14 18:06:25 +00:00
|
|
|
*/
|
2011-05-24 07:05:23 +00:00
|
|
|
class AppTest extends CakeTestCase {
|
2010-11-14 18:06:25 +00:00
|
|
|
|
2011-05-10 05:16:24 +00:00
|
|
|
/**
|
|
|
|
* tearDown method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function tearDown() {
|
|
|
|
CakePlugin::unload();
|
|
|
|
}
|
|
|
|
|
2010-11-14 18:06:25 +00:00
|
|
|
/**
|
|
|
|
* testBuild method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testBuild() {
|
2011-03-10 02:41:13 +00:00
|
|
|
$old = App::path('Model');
|
|
|
|
$expected = array(
|
2011-03-22 05:16:51 +00:00
|
|
|
APP . 'Model' . DS,
|
2011-03-10 02:41:13 +00:00
|
|
|
APP . 'models' . DS
|
|
|
|
);
|
|
|
|
$this->assertEqual($expected, $old);
|
|
|
|
|
|
|
|
App::build(array('Model' => array('/path/to/models/')));
|
|
|
|
$new = App::path('Model');
|
|
|
|
$expected = array(
|
|
|
|
'/path/to/models/',
|
2011-03-22 05:16:51 +00:00
|
|
|
APP . 'Model' . DS,
|
2011-03-10 02:41:13 +00:00
|
|
|
APP . 'models' . DS
|
|
|
|
);
|
|
|
|
$this->assertEqual($expected, $new);
|
|
|
|
|
2011-05-01 15:24:09 +00:00
|
|
|
App::build();
|
2011-05-02 19:28:57 +00:00
|
|
|
App::build(array('Model' => array('/path/to/models/')), App::PREPEND);
|
|
|
|
$new = App::path('Model');
|
|
|
|
$expected = array(
|
|
|
|
'/path/to/models/',
|
|
|
|
APP . 'Model' . DS,
|
|
|
|
APP . 'models' . DS
|
|
|
|
);
|
|
|
|
$this->assertEqual($expected, $new);
|
|
|
|
|
|
|
|
App::build();
|
|
|
|
App::build(array('Model' => array('/path/to/models/')), App::APPEND);
|
2011-05-01 15:24:09 +00:00
|
|
|
$new = App::path('Model');
|
|
|
|
$expected = array(
|
|
|
|
APP . 'Model' . DS,
|
|
|
|
APP . 'models' . DS,
|
|
|
|
'/path/to/models/'
|
|
|
|
);
|
|
|
|
$this->assertEqual($expected, $new);
|
|
|
|
|
|
|
|
App::build();
|
|
|
|
App::build(array(
|
|
|
|
'Model' => array('/path/to/models/'),
|
|
|
|
'Controller' => array('/path/to/controllers/'),
|
2011-05-02 19:28:57 +00:00
|
|
|
), App::APPEND);
|
2011-05-01 15:24:09 +00:00
|
|
|
$new = App::path('Model');
|
|
|
|
$expected = array(
|
|
|
|
APP . 'Model' . DS,
|
|
|
|
APP . 'models' . DS,
|
|
|
|
'/path/to/models/'
|
|
|
|
);
|
|
|
|
$this->assertEqual($expected, $new);
|
|
|
|
$new = App::path('Controller');
|
|
|
|
$expected = array(
|
|
|
|
APP . 'Controller' . DS,
|
|
|
|
APP . 'controllers' . DS,
|
|
|
|
'/path/to/controllers/'
|
|
|
|
);
|
|
|
|
$this->assertEqual($expected, $new);
|
|
|
|
|
2011-03-10 02:41:13 +00:00
|
|
|
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...)
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testCompatibleBuild() {
|
2010-11-14 18:06:25 +00:00
|
|
|
$old = App::path('models');
|
|
|
|
$expected = array(
|
2011-03-22 05:16:51 +00:00
|
|
|
APP . 'Model' . DS,
|
2011-03-10 02:41:13 +00:00
|
|
|
APP . 'models' . DS
|
2010-11-14 18:06:25 +00:00
|
|
|
);
|
|
|
|
$this->assertEqual($expected, $old);
|
|
|
|
|
|
|
|
App::build(array('models' => array('/path/to/models/')));
|
|
|
|
|
|
|
|
$new = App::path('models');
|
|
|
|
|
|
|
|
$expected = array(
|
|
|
|
'/path/to/models/',
|
2011-03-22 05:16:51 +00:00
|
|
|
APP . 'Model' . DS,
|
2011-03-10 02:41:13 +00:00
|
|
|
APP . 'models' . DS
|
2010-11-14 18:06:25 +00:00
|
|
|
);
|
|
|
|
$this->assertEqual($expected, $new);
|
2011-03-10 02:41:13 +00:00
|
|
|
$this->assertEqual($expected, App::path('Model'));
|
|
|
|
|
|
|
|
App::build(array('datasources' => array('/path/to/datasources/')));
|
|
|
|
$expected = array(
|
|
|
|
'/path/to/datasources/',
|
2011-03-22 05:16:51 +00:00
|
|
|
APP . 'Model' . DS . 'Datasource' . DS,
|
2011-03-10 02:41:13 +00:00
|
|
|
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/',
|
2011-03-22 05:16:51 +00:00
|
|
|
APP . 'Model' . DS . 'Behavior' . DS,
|
2011-03-10 02:41:13 +00:00
|
|
|
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/',
|
2011-03-22 05:16:51 +00:00
|
|
|
APP . 'Controller' . DS,
|
2011-03-10 02:41:13 +00:00
|
|
|
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/',
|
2011-03-22 05:16:51 +00:00
|
|
|
APP . 'Controller' . DS . 'Component' . DS,
|
2011-03-10 02:41:13 +00:00
|
|
|
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/',
|
2011-03-22 05:16:51 +00:00
|
|
|
APP . 'View' . DS,
|
2011-03-10 02:41:13 +00:00
|
|
|
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/',
|
2011-03-22 05:16:51 +00:00
|
|
|
APP . 'View' . DS . 'Helper' .DS,
|
2011-03-10 02:41:13 +00:00
|
|
|
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/',
|
2011-03-22 05:16:51 +00:00
|
|
|
APP . 'Console' . DS . 'Command' . DS,
|
2011-03-10 02:41:13 +00:00
|
|
|
APP . 'console' . DS . 'shells' . DS,
|
|
|
|
);
|
|
|
|
$result = App::path('shells');
|
|
|
|
$this->assertEqual($expected, $result);
|
|
|
|
$this->assertEqual($expected, App::path('Console/Command'));
|
2010-11-14 18:06:25 +00:00
|
|
|
|
|
|
|
App::build(); //reset defaults
|
2011-03-10 02:41:13 +00:00
|
|
|
$defaults = App::path('Model');
|
2010-11-14 18:06:25 +00:00
|
|
|
$this->assertEqual($old, $defaults);
|
|
|
|
}
|
|
|
|
|
2011-09-13 03:20:29 +00:00
|
|
|
/**
|
|
|
|
* test path() with a plugin.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testPathWithPlugins() {
|
|
|
|
$basepath = CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS;
|
|
|
|
App::build(array(
|
|
|
|
'Plugin' => array($basepath),
|
|
|
|
));
|
|
|
|
CakePlugin::load('TestPlugin');
|
|
|
|
|
|
|
|
$result = App::path('Vendor', 'TestPlugin');
|
|
|
|
$this->assertEquals($basepath . 'TestPlugin' . DS . 'Vendor' . DS, $result[0]);
|
|
|
|
}
|
|
|
|
|
2010-11-14 18:06:25 +00:00
|
|
|
/**
|
|
|
|
* testBuildWithReset method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testBuildWithReset() {
|
2011-03-10 02:45:20 +00:00
|
|
|
$old = App::path('Model');
|
2010-11-14 18:06:25 +00:00
|
|
|
$expected = array(
|
2011-03-22 05:16:51 +00:00
|
|
|
APP . 'Model' . DS,
|
2011-03-10 02:45:20 +00:00
|
|
|
APP . 'models' . DS
|
2010-11-14 18:06:25 +00:00
|
|
|
);
|
|
|
|
$this->assertEqual($expected, $old);
|
|
|
|
|
2011-05-01 15:24:09 +00:00
|
|
|
App::build(array('Model' => array('/path/to/models/')), App::RESET);
|
2010-11-14 18:06:25 +00:00
|
|
|
|
2011-03-10 02:45:20 +00:00
|
|
|
$new = App::path('Model');
|
2010-11-14 18:06:25 +00:00
|
|
|
|
|
|
|
$expected = array(
|
|
|
|
'/path/to/models/'
|
|
|
|
);
|
|
|
|
$this->assertEqual($expected, $new);
|
|
|
|
|
|
|
|
App::build(); //reset defaults
|
2011-03-10 02:45:20 +00:00
|
|
|
$defaults = App::path('Model');
|
2010-11-14 18:06:25 +00:00
|
|
|
$this->assertEqual($old, $defaults);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testCore method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testCore() {
|
2011-03-10 02:45:20 +00:00
|
|
|
$model = App::core('Model');
|
2011-04-17 10:35:21 +00:00
|
|
|
$this->assertEqual(array(CAKE . 'Model' . DS), $model);
|
2011-03-10 02:45:20 +00:00
|
|
|
|
|
|
|
$view = App::core('View');
|
2011-04-17 10:35:21 +00:00
|
|
|
$this->assertEqual(array(CAKE . 'View' . DS), $view);
|
2011-03-10 02:45:20 +00:00
|
|
|
|
|
|
|
$controller = App::core('Controller');
|
2011-04-17 10:35:21 +00:00
|
|
|
$this->assertEqual(array(CAKE . 'Controller' . DS), $controller);
|
2010-11-14 18:06:25 +00:00
|
|
|
|
2011-03-10 02:45:20 +00:00
|
|
|
$component = App::core('Controller/Component');
|
2011-04-17 10:35:21 +00:00
|
|
|
$this->assertEqual(array(CAKE . 'Controller' . DS . 'Component' . DS), str_replace('/', DS, $component));
|
2010-11-14 18:06:25 +00:00
|
|
|
|
2011-03-10 02:45:20 +00:00
|
|
|
$auth = App::core('Controller/Component/Auth');
|
2011-04-17 10:35:21 +00:00
|
|
|
$this->assertEqual(array(CAKE . 'Controller' . DS . 'Component' . DS . 'Auth' . DS), str_replace('/', DS, $auth));
|
2010-11-14 18:06:25 +00:00
|
|
|
|
2011-03-10 02:45:20 +00:00
|
|
|
$datasource = App::core('Model/Datasource');
|
2011-04-17 10:35:21 +00:00
|
|
|
$this->assertEqual(array(CAKE . 'Model' . DS . 'Datasource' . DS), str_replace('/', DS, $datasource));
|
2010-11-14 18:06:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testListObjects method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testListObjects() {
|
2011-04-17 10:35:21 +00:00
|
|
|
$result = App::objects('class', CAKE . 'Routing', false);
|
2011-03-10 02:59:52 +00:00
|
|
|
$this->assertTrue(in_array('Dispatcher', $result));
|
|
|
|
$this->assertTrue(in_array('Router', $result));
|
2010-11-14 18:06:25 +00:00
|
|
|
|
2011-03-10 02:59:52 +00:00
|
|
|
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'),
|
2011-05-01 15:24:09 +00:00
|
|
|
), App::RESET);
|
2010-11-14 18:06:25 +00:00
|
|
|
$result = App::objects('behavior', null, false);
|
2011-03-10 02:59:52 +00:00
|
|
|
$this->assertTrue(in_array('TreeBehavior', $result));
|
|
|
|
$result = App::objects('Model/Behavior', null, false);
|
|
|
|
$this->assertTrue(in_array('TreeBehavior', $result));
|
2010-11-14 18:06:25 +00:00
|
|
|
|
|
|
|
$result = App::objects('controller', null, false);
|
2011-03-10 02:59:52 +00:00
|
|
|
$this->assertTrue(in_array('PagesController', $result));
|
|
|
|
$result = App::objects('Controller', null, false);
|
|
|
|
$this->assertTrue(in_array('PagesController', $result));
|
2010-11-14 18:06:25 +00:00
|
|
|
|
|
|
|
$result = App::objects('component', null, false);
|
2011-03-10 02:59:52 +00:00
|
|
|
$this->assertTrue(in_array('AuthComponent', $result));
|
|
|
|
$result = App::objects('Controller/Component', null, false);
|
|
|
|
$this->assertTrue(in_array('AuthComponent', $result));
|
2010-11-14 18:06:25 +00:00
|
|
|
|
|
|
|
$result = App::objects('view', null, false);
|
2011-03-10 02:59:52 +00:00
|
|
|
$this->assertTrue(in_array('MediaView', $result));
|
|
|
|
$result = App::objects('View', null, false);
|
|
|
|
$this->assertTrue(in_array('MediaView', $result));
|
2010-11-14 18:06:25 +00:00
|
|
|
|
|
|
|
$result = App::objects('helper', null, false);
|
2011-03-10 02:59:52 +00:00
|
|
|
$this->assertTrue(in_array('HtmlHelper', $result));
|
|
|
|
$result = App::objects('View/Helper', null, false);
|
|
|
|
$this->assertTrue(in_array('HtmlHelper', $result));
|
2010-11-14 18:06:25 +00:00
|
|
|
|
|
|
|
$result = App::objects('model', null, false);
|
2011-03-10 02:59:52 +00:00
|
|
|
$this->assertTrue(in_array('AcoAction', $result));
|
|
|
|
$result = App::objects('Model', null, false);
|
|
|
|
$this->assertTrue(in_array('AcoAction', $result));
|
2010-11-14 18:06:25 +00:00
|
|
|
|
|
|
|
$result = App::objects('file');
|
|
|
|
$this->assertFalse($result);
|
|
|
|
|
|
|
|
$result = App::objects('file', 'non_existing_configure');
|
|
|
|
$expected = array();
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2010-11-14 18:06:25 +00:00
|
|
|
|
|
|
|
$result = App::objects('NonExistingType');
|
2011-03-10 02:59:52 +00:00
|
|
|
$this->assertEqual($result, array());
|
2010-11-14 18:06:25 +00:00
|
|
|
|
|
|
|
App::build(array(
|
|
|
|
'plugins' => array(
|
2011-04-17 10:35:21 +00:00
|
|
|
CAKE . 'Test' . DS . 'test_app' . DS . 'Lib' . DS
|
2010-11-14 18:06:25 +00:00
|
|
|
)
|
|
|
|
));
|
|
|
|
$result = App::objects('plugin', null, false);
|
|
|
|
$this->assertTrue(in_array('Cache', $result));
|
|
|
|
$this->assertTrue(in_array('Log', $result));
|
|
|
|
|
|
|
|
App::build();
|
|
|
|
}
|
|
|
|
|
2011-08-28 19:36:19 +00:00
|
|
|
/**
|
|
|
|
* Make sure that .svn and friends are excluded from App::objects('plugin')
|
|
|
|
*/
|
|
|
|
public function testListObjectsIgnoreDotDirectories() {
|
|
|
|
$path = CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS;
|
|
|
|
App::build(array(
|
|
|
|
'plugins' => array($path)
|
|
|
|
), true);
|
|
|
|
mkdir($path . '.svn');
|
|
|
|
$result = App::objects('plugin', null, false);
|
|
|
|
rmdir($path . '.svn');
|
|
|
|
|
|
|
|
$this->assertNotContains('.svn', $result);
|
|
|
|
}
|
|
|
|
|
2011-01-04 03:27:21 +00:00
|
|
|
/**
|
|
|
|
* Tests listing objects within a plugin
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testListObjectsInPlugin() {
|
2011-01-04 03:27:21 +00:00
|
|
|
App::build(array(
|
2011-04-17 10:35:21 +00:00
|
|
|
'Model' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Model' . DS),
|
|
|
|
'plugins' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
|
2011-05-26 17:33:36 +00:00
|
|
|
), true);
|
2011-05-10 05:16:24 +00:00
|
|
|
CakePlugin::loadAll();
|
2011-01-04 03:27:21 +00:00
|
|
|
|
|
|
|
$result = App::objects('TestPlugin.model');
|
|
|
|
$this->assertTrue(in_array('TestPluginPost', $result));
|
2011-03-10 04:03:03 +00:00
|
|
|
$result = App::objects('TestPlugin.Model');
|
|
|
|
$this->assertTrue(in_array('TestPluginPost', $result));
|
2011-01-04 03:27:21 +00:00
|
|
|
|
|
|
|
$result = App::objects('TestPlugin.behavior');
|
|
|
|
$this->assertTrue(in_array('TestPluginPersisterOne', $result));
|
2011-03-10 04:03:03 +00:00
|
|
|
$result = App::objects('TestPlugin.Model/Behavior');
|
|
|
|
$this->assertTrue(in_array('TestPluginPersisterOne', $result));
|
2011-01-04 03:27:21 +00:00
|
|
|
|
|
|
|
$result = App::objects('TestPlugin.helper');
|
2011-05-15 05:26:33 +00:00
|
|
|
$expected = array('OtherHelperHelper', 'PluggedHelperHelper', 'TestPluginAppHelper');
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2011-03-10 04:03:03 +00:00
|
|
|
$result = App::objects('TestPlugin.View/Helper');
|
2011-05-15 05:26:33 +00:00
|
|
|
$expected = array('OtherHelperHelper', 'PluggedHelperHelper', 'TestPluginAppHelper');
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2011-01-04 03:27:21 +00:00
|
|
|
|
|
|
|
$result = App::objects('TestPlugin.component');
|
|
|
|
$this->assertTrue(in_array('OtherComponent', $result));
|
2011-03-10 04:03:03 +00:00
|
|
|
$result = App::objects('TestPlugin.Controller/Component');
|
|
|
|
$this->assertTrue(in_array('OtherComponent', $result));
|
2011-01-04 03:27:21 +00:00
|
|
|
|
|
|
|
$result = App::objects('TestPluginTwo.behavior');
|
|
|
|
$this->assertEquals($result, array());
|
2011-03-10 04:03:03 +00:00
|
|
|
$result = App::objects('TestPluginTwo.Model/Behavior');
|
|
|
|
$this->assertEquals($result, array());
|
2011-01-04 03:27:21 +00:00
|
|
|
|
|
|
|
$result = App::objects('model', null, false);
|
|
|
|
$this->assertTrue(in_array('Comment', $result));
|
|
|
|
$this->assertTrue(in_array('Post', $result));
|
|
|
|
|
2011-03-10 04:03:03 +00:00
|
|
|
$result = App::objects('Model', null, false);
|
|
|
|
$this->assertTrue(in_array('Comment', $result));
|
|
|
|
$this->assertTrue(in_array('Post', $result));
|
|
|
|
|
2011-01-04 03:27:21 +00:00
|
|
|
App::build();
|
|
|
|
}
|
|
|
|
|
2010-11-14 18:06:25 +00:00
|
|
|
/**
|
|
|
|
* test that pluginPath can find paths for plugins.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testPluginPath() {
|
2010-11-14 18:06:25 +00:00
|
|
|
App::build(array(
|
2011-04-17 10:35:21 +00:00
|
|
|
'plugins' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
|
2010-11-14 18:06:25 +00:00
|
|
|
));
|
2011-05-10 05:16:24 +00:00
|
|
|
CakePlugin::loadAll();
|
2010-11-14 18:06:25 +00:00
|
|
|
|
|
|
|
$path = App::pluginPath('TestPlugin');
|
2011-04-17 10:35:21 +00:00
|
|
|
$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS . 'TestPlugin' . DS;
|
2010-11-14 18:06:25 +00:00
|
|
|
$this->assertEqual($path, $expected);
|
|
|
|
|
|
|
|
$path = App::pluginPath('TestPluginTwo');
|
2011-04-17 10:35:21 +00:00
|
|
|
$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS . 'TestPluginTwo' . DS;
|
2010-11-14 18:06:25 +00:00
|
|
|
$this->assertEqual($path, $expected);
|
|
|
|
App::build();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test that pluginPath can find paths for plugins.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testThemePath() {
|
2010-11-14 18:06:25 +00:00
|
|
|
App::build(array(
|
2011-04-17 10:35:21 +00:00
|
|
|
'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS)
|
2010-11-14 18:06:25 +00:00
|
|
|
));
|
|
|
|
$path = App::themePath('test_theme');
|
2011-04-17 10:35:21 +00:00
|
|
|
$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Themed' . DS . 'TestTheme' . DS;
|
2010-11-14 18:06:25 +00:00
|
|
|
$this->assertEqual($path, $expected);
|
|
|
|
|
|
|
|
$path = App::themePath('TestTheme');
|
2011-04-17 10:35:21 +00:00
|
|
|
$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Themed' . DS . 'TestTheme' . DS;
|
2010-11-14 18:06:25 +00:00
|
|
|
$this->assertEqual($path, $expected);
|
|
|
|
|
|
|
|
App::build();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testClassLoading method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testClassLoading() {
|
2010-11-14 18:06:25 +00:00
|
|
|
$file = App::import('Model', 'Model', false);
|
|
|
|
$this->assertTrue($file);
|
|
|
|
$this->assertTrue(class_exists('Model'));
|
|
|
|
|
|
|
|
$file = App::import('Controller', 'Controller', false);
|
|
|
|
$this->assertTrue($file);
|
|
|
|
$this->assertTrue(class_exists('Controller'));
|
|
|
|
|
2011-03-11 05:20:14 +00:00
|
|
|
$file = App::import('Component', 'Auth', false);
|
2010-11-14 18:06:25 +00:00
|
|
|
$this->assertTrue($file);
|
2011-03-11 05:20:14 +00:00
|
|
|
$this->assertTrue(class_exists('AuthComponent'));
|
2010-11-14 18:06:25 +00:00
|
|
|
|
|
|
|
$file = App::import('Shell', 'Shell', false);
|
|
|
|
$this->assertTrue($file);
|
|
|
|
$this->assertTrue(class_exists('Shell'));
|
|
|
|
|
2011-03-11 05:20:14 +00:00
|
|
|
$file = App::import('Configure', 'PhpReader');
|
2010-11-30 00:37:08 +00:00
|
|
|
$this->assertTrue($file);
|
2010-12-04 22:53:57 +00:00
|
|
|
$this->assertTrue(class_exists('PhpReader'));
|
2010-11-30 00:37:08 +00:00
|
|
|
|
2010-11-14 18:06:25 +00:00
|
|
|
$file = App::import('Model', 'SomeRandomModelThatDoesNotExist', false);
|
|
|
|
$this->assertFalse($file);
|
|
|
|
|
|
|
|
$file = App::import('Model', 'AppModel', false);
|
|
|
|
$this->assertTrue($file);
|
|
|
|
$this->assertTrue(class_exists('AppModel'));
|
|
|
|
|
|
|
|
$file = App::import('WrongType', null, true, array(), '');
|
|
|
|
$this->assertFalse($file);
|
|
|
|
|
2011-03-11 05:20:14 +00:00
|
|
|
$file = App::import('Model', 'NonExistingPlugin.NonExistingModel', false);
|
2010-11-14 18:06:25 +00:00
|
|
|
$this->assertFalse($file);
|
|
|
|
|
|
|
|
$file = App::import('Model', array('NonExistingPlugin.NonExistingModel'), false);
|
|
|
|
$this->assertFalse($file);
|
|
|
|
|
2011-05-10 05:16:24 +00:00
|
|
|
if (!class_exists('AppController', false)) {
|
2010-11-14 18:06:25 +00:00
|
|
|
$classes = array_flip(get_declared_classes());
|
|
|
|
|
|
|
|
$this->assertFalse(isset($classes['PagesController']));
|
|
|
|
$this->assertFalse(isset($classes['AppController']));
|
|
|
|
|
|
|
|
$file = App::import('Controller', 'Pages');
|
|
|
|
$this->assertTrue($file);
|
|
|
|
$this->assertTrue(class_exists('PagesController'));
|
|
|
|
|
|
|
|
$classes = array_flip(get_declared_classes());
|
|
|
|
|
|
|
|
$this->assertTrue(isset($classes['PagesController']));
|
|
|
|
$this->assertTrue(isset($classes['AppController']));
|
|
|
|
|
|
|
|
$file = App::import('Behavior', 'Containable');
|
|
|
|
$this->assertTrue($file);
|
|
|
|
$this->assertTrue(class_exists('ContainableBehavior'));
|
|
|
|
|
|
|
|
$file = App::import('Component', 'RequestHandler');
|
|
|
|
$this->assertTrue($file);
|
|
|
|
$this->assertTrue(class_exists('RequestHandlerComponent'));
|
|
|
|
|
|
|
|
$file = App::import('Helper', 'Form');
|
|
|
|
$this->assertTrue($file);
|
|
|
|
$this->assertTrue(class_exists('FormHelper'));
|
|
|
|
|
|
|
|
$file = App::import('Model', 'NonExistingModel');
|
|
|
|
$this->assertFalse($file);
|
|
|
|
|
|
|
|
$file = App::import('Datasource', 'DboSource');
|
|
|
|
$this->assertTrue($file);
|
|
|
|
$this->assertTrue(class_exists('DboSource'));
|
|
|
|
}
|
|
|
|
App::build();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test import() with plugins
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testPluginImporting() {
|
2010-11-14 18:06:25 +00:00
|
|
|
App::build(array(
|
2011-04-17 10:35:21 +00:00
|
|
|
'libs' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Lib' . DS),
|
|
|
|
'plugins' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
|
2010-11-14 18:06:25 +00:00
|
|
|
));
|
2011-05-10 05:16:24 +00:00
|
|
|
CakePlugin::loadAll();
|
2010-11-14 18:06:25 +00:00
|
|
|
|
|
|
|
$result = App::import('Controller', 'TestPlugin.Tests');
|
|
|
|
$this->assertTrue($result);
|
|
|
|
$this->assertTrue(class_exists('TestPluginAppController'));
|
|
|
|
$this->assertTrue(class_exists('TestsController'));
|
|
|
|
|
|
|
|
$result = App::import('Lib', 'TestPlugin.TestPluginLibrary');
|
|
|
|
$this->assertTrue($result);
|
|
|
|
$this->assertTrue(class_exists('TestPluginLibrary'));
|
|
|
|
|
|
|
|
$result = App::import('Lib', 'Library');
|
|
|
|
$this->assertTrue($result);
|
|
|
|
$this->assertTrue(class_exists('Library'));
|
|
|
|
|
|
|
|
$result = App::import('Helper', 'TestPlugin.OtherHelper');
|
|
|
|
$this->assertTrue($result);
|
|
|
|
$this->assertTrue(class_exists('OtherHelperHelper'));
|
2011-04-30 21:49:44 +00:00
|
|
|
|
2010-11-14 18:06:25 +00:00
|
|
|
$result = App::import('Helper', 'TestPlugin.TestPluginApp');
|
|
|
|
$this->assertTrue($result);
|
|
|
|
$this->assertTrue(class_exists('TestPluginAppHelper'));
|
|
|
|
|
|
|
|
$result = App::import('Datasource', 'TestPlugin.TestSource');
|
|
|
|
$this->assertTrue($result);
|
|
|
|
$this->assertTrue(class_exists('TestSource'));
|
2011-04-30 21:49:44 +00:00
|
|
|
|
2010-11-14 18:06:25 +00:00
|
|
|
App::build();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test that building helper paths actually works.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
* @link http://cakephp.lighthouseapp.com/projects/42648/tickets/410
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testImportingHelpersFromAlternatePaths() {
|
2011-03-11 22:48:58 +00:00
|
|
|
|
|
|
|
$this->assertFalse(class_exists('BananaHelper', false), 'BananaHelper exists, cannot test importing it.');
|
2010-11-14 18:06:25 +00:00
|
|
|
App::build(array(
|
2011-03-11 22:48:58 +00:00
|
|
|
'View/Helper' => array(
|
2011-04-17 10:35:21 +00:00
|
|
|
CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Helper' . DS
|
2010-12-04 20:00:48 +00:00
|
|
|
)
|
2010-11-14 18:06:25 +00:00
|
|
|
));
|
2011-03-11 22:48:58 +00:00
|
|
|
$this->assertFalse(class_exists('BananaHelper', false), 'BananaHelper exists, cannot test importing it.');
|
2010-11-14 18:06:25 +00:00
|
|
|
App::import('Helper', 'Banana');
|
2011-03-11 22:48:58 +00:00
|
|
|
$this->assertTrue(class_exists('BananaHelper', false), 'BananaHelper was not loaded.');
|
2010-11-14 18:06:25 +00:00
|
|
|
|
|
|
|
App::build();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testFileLoading method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testFileLoading () {
|
2011-04-17 10:35:21 +00:00
|
|
|
$file = App::import('File', 'RealFile', false, array(), CAKE . 'Config' . DS . 'config.php');
|
2010-11-14 18:06:25 +00:00
|
|
|
$this->assertTrue($file);
|
|
|
|
|
2011-04-17 10:35:21 +00:00
|
|
|
$file = App::import('File', 'NoFile', false, array(), CAKE . 'Config' . DS . 'cake' . DS . 'config.php');
|
2010-11-14 18:06:25 +00:00
|
|
|
$this->assertFalse($file);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testFileLoadingWithArray method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testFileLoadingWithArray() {
|
2010-11-14 18:06:25 +00:00
|
|
|
$type = array('type' => 'File', 'name' => 'SomeName', 'parent' => false,
|
2011-04-17 10:35:21 +00:00
|
|
|
'file' => CAKE . DS . 'Config' . DS . 'config.php');
|
2010-11-14 18:06:25 +00:00
|
|
|
$file = App::import($type);
|
|
|
|
$this->assertTrue($file);
|
|
|
|
|
|
|
|
$type = array('type' => 'File', 'name' => 'NoFile', 'parent' => false,
|
2011-04-17 10:35:21 +00:00
|
|
|
'file' => CAKE . 'Config' . DS . 'cake' . DS . 'config.php');
|
2010-11-14 18:06:25 +00:00
|
|
|
$file = App::import($type);
|
|
|
|
$this->assertFalse($file);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testFileLoadingReturnValue method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testFileLoadingReturnValue () {
|
2011-04-17 10:35:21 +00:00
|
|
|
$file = App::import('File', 'Name', false, array(), CAKE . 'Config' . DS . 'config.php', true);
|
2010-11-14 18:06:25 +00:00
|
|
|
$this->assertTrue(!empty($file));
|
|
|
|
|
|
|
|
$this->assertTrue(isset($file['Cake.version']));
|
|
|
|
|
|
|
|
$type = array('type' => 'File', 'name' => 'OtherName', 'parent' => false,
|
2011-04-17 10:35:21 +00:00
|
|
|
'file' => CAKE . 'Config' . DS . 'config.php', 'return' => true);
|
2010-11-14 18:06:25 +00:00
|
|
|
$file = App::import($type);
|
|
|
|
$this->assertTrue(!empty($file));
|
|
|
|
|
|
|
|
$this->assertTrue(isset($file['Cake.version']));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testLoadingWithSearch method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testLoadingWithSearch () {
|
2011-04-17 10:35:21 +00:00
|
|
|
$file = App::import('File', 'NewName', false, array(CAKE . 'Config' . DS), 'config.php');
|
2010-11-14 18:06:25 +00:00
|
|
|
$this->assertTrue($file);
|
|
|
|
|
2011-04-17 10:35:21 +00:00
|
|
|
$file = App::import('File', 'AnotherNewName', false, array(CAKE), 'config.php');
|
2010-11-14 18:06:25 +00:00
|
|
|
$this->assertFalse($file);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testLoadingWithSearchArray method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testLoadingWithSearchArray() {
|
2011-03-11 23:26:32 +00:00
|
|
|
$type = array(
|
|
|
|
'type' => 'File',
|
|
|
|
'name' => 'RandomName',
|
|
|
|
'parent' => false,
|
|
|
|
'file' => 'config.php',
|
2011-04-17 10:35:21 +00:00
|
|
|
'search' => array(CAKE . 'Config' . DS)
|
2011-03-11 23:26:32 +00:00
|
|
|
);
|
2010-11-14 18:06:25 +00:00
|
|
|
$file = App::import($type);
|
|
|
|
$this->assertTrue($file);
|
|
|
|
|
2011-03-11 23:26:32 +00:00
|
|
|
$type = array(
|
|
|
|
'type' => 'File',
|
|
|
|
'name' => 'AnotherRandomName',
|
|
|
|
'parent' => false,
|
|
|
|
'file' => 'config.php',
|
2011-04-17 10:35:21 +00:00
|
|
|
'search' => array(CAKE)
|
2011-03-11 23:26:32 +00:00
|
|
|
);
|
2010-11-14 18:06:25 +00:00
|
|
|
$file = App::import($type);
|
|
|
|
$this->assertFalse($file);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testMultipleLoading method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testMultipleLoading() {
|
2011-03-11 23:26:32 +00:00
|
|
|
if (class_exists('PersisterOne', false) || class_exists('PersisterTwo', false)) {
|
2010-11-14 18:06:25 +00:00
|
|
|
$this->markTestSkipped('Cannot test loading of classes that exist.');
|
|
|
|
}
|
2011-03-11 23:26:32 +00:00
|
|
|
App::build(array(
|
2011-04-17 10:35:21 +00:00
|
|
|
'Model' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Model' . DS)
|
2011-03-11 23:26:32 +00:00
|
|
|
));
|
|
|
|
$toLoad = array('PersisterOne', 'PersisterTwo');
|
|
|
|
$load = App::import('Model', $toLoad);
|
2010-11-14 18:06:25 +00:00
|
|
|
$this->assertTrue($load);
|
|
|
|
|
|
|
|
$classes = array_flip(get_declared_classes());
|
|
|
|
|
|
|
|
|
2011-03-11 23:26:32 +00:00
|
|
|
$this->assertTrue(isset($classes['PersisterOne']));
|
|
|
|
$this->assertTrue(isset($classes['PersisterTwo']));
|
2010-11-14 18:06:25 +00:00
|
|
|
|
2011-03-11 23:26:32 +00:00
|
|
|
$load = App::import('Model', array('PersisterOne', 'SomeNotFoundClass', 'PersisterTwo'));
|
2010-11-14 18:06:25 +00:00
|
|
|
$this->assertFalse($load);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testLoadingVendor() {
|
2010-11-14 18:06:25 +00:00
|
|
|
App::build(array(
|
2011-04-17 10:35:21 +00:00
|
|
|
'plugins' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS),
|
|
|
|
'vendors' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Vendor'. DS),
|
2011-05-01 15:24:09 +00:00
|
|
|
), App::RESET);
|
2011-05-10 05:16:24 +00:00
|
|
|
CakePlugin::loadAll();
|
2010-11-14 18:06:25 +00:00
|
|
|
|
|
|
|
ob_start();
|
2011-03-12 03:51:34 +00:00
|
|
|
$result = App::import('Vendor', 'css/TestAsset', array('ext' => 'css'));
|
2010-11-14 18:06:25 +00:00
|
|
|
$text = ob_get_clean();
|
|
|
|
$this->assertTrue($result);
|
|
|
|
$this->assertEqual($text, 'this is the test asset css file');
|
|
|
|
|
2011-03-12 03:51:34 +00:00
|
|
|
$result = App::import('Vendor', 'TestPlugin.sample/SamplePlugin');
|
2010-11-14 18:06:25 +00:00
|
|
|
$this->assertTrue($result);
|
|
|
|
$this->assertTrue(class_exists('SamplePluginClassTestName'));
|
|
|
|
|
2011-03-12 03:51:34 +00:00
|
|
|
$result = App::import('Vendor', 'sample/ConfigureTestVendorSample');
|
2010-11-14 18:06:25 +00:00
|
|
|
$this->assertTrue($result);
|
|
|
|
$this->assertTrue(class_exists('ConfigureTestVendorSample'));
|
|
|
|
|
|
|
|
ob_start();
|
2011-03-12 03:51:34 +00:00
|
|
|
$result = App::import('Vendor', 'SomeNameInSubfolder', array('file' => 'somename/some.name.php'));
|
2010-11-14 18:06:25 +00:00
|
|
|
$text = ob_get_clean();
|
|
|
|
$this->assertTrue($result);
|
|
|
|
$this->assertEqual($text, 'This is a file with dot in file name');
|
|
|
|
|
|
|
|
ob_start();
|
|
|
|
$result = App::import('Vendor', 'TestHello', array('file' => 'Test'.DS.'hello.php'));
|
|
|
|
$text = ob_get_clean();
|
|
|
|
$this->assertTrue($result);
|
|
|
|
$this->assertEqual($text, 'This is the hello.php file in Test directory');
|
|
|
|
|
|
|
|
ob_start();
|
|
|
|
$result = App::import('Vendor', 'MyTest', array('file' => 'Test'.DS.'MyTest.php'));
|
|
|
|
$text = ob_get_clean();
|
|
|
|
$this->assertTrue($result);
|
|
|
|
$this->assertEqual($text, 'This is the MyTest.php file');
|
|
|
|
|
|
|
|
ob_start();
|
|
|
|
$result = App::import('Vendor', 'Welcome');
|
|
|
|
$text = ob_get_clean();
|
|
|
|
$this->assertTrue($result);
|
|
|
|
$this->assertEqual($text, 'This is the welcome.php file in vendors directory');
|
|
|
|
|
|
|
|
ob_start();
|
|
|
|
$result = App::import('Vendor', 'TestPlugin.Welcome');
|
|
|
|
$text = ob_get_clean();
|
|
|
|
$this->assertTrue($result);
|
|
|
|
$this->assertEqual($text, 'This is the welcome.php file in test_plugin/vendors directory');
|
|
|
|
}
|
2011-03-12 06:26:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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(
|
2011-04-17 10:35:21 +00:00
|
|
|
'libs' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Lib' . DS),
|
|
|
|
'plugins' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
|
2011-05-01 15:24:09 +00:00
|
|
|
), App::RESET);
|
2011-05-10 05:16:24 +00:00
|
|
|
CakePlugin::loadAll();
|
2011-03-12 06:26:34 +00:00
|
|
|
|
|
|
|
$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'));
|
|
|
|
}
|
2011-07-12 05:08:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests that App::location() returns the defined path for a class
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testClassLocation() {
|
|
|
|
App::uses('MyCustomClass', 'MyPackage/Name');
|
|
|
|
$this->assertEquals('MyPackage/Name', App::location('MyCustomClass'));
|
|
|
|
}
|
2011-08-30 02:07:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that paths() works.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testPaths() {
|
|
|
|
$result = App::paths();
|
2011-09-13 03:20:29 +00:00
|
|
|
$this->assertArrayHasKey('Plugin', $result);
|
2011-08-30 02:07:23 +00:00
|
|
|
$this->assertArrayHasKey('Controller', $result);
|
|
|
|
$this->assertArrayHasKey('Controller/Component', $result);
|
|
|
|
}
|
2010-11-14 18:06:25 +00:00
|
|
|
}
|