2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/* SVN FILE: $Id$ */
|
|
|
|
/**
|
2009-03-18 17:55:58 +00:00
|
|
|
* ConfigureTest file
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2009-03-18 17:55:58 +00:00
|
|
|
* Holds several tests
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* PHP versions 4 and 5
|
|
|
|
*
|
|
|
|
* CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
|
2008-10-30 17:30:26 +00:00
|
|
|
* Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* Licensed under The Open Group Test Suite License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
|
|
|
* @filesource
|
2008-10-30 17:30:26 +00:00
|
|
|
* @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
|
|
|
|
* @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
|
2009-03-18 17:55:58 +00:00
|
|
|
* @package cake
|
2008-10-30 17:30:26 +00:00
|
|
|
* @subpackage cake.tests.cases.libs
|
|
|
|
* @since CakePHP(tm) v 1.2.0.5432
|
|
|
|
* @version $Revision$
|
|
|
|
* @modifiedby $LastChangedBy$
|
|
|
|
* @lastmodified $Date$
|
|
|
|
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
|
|
|
App::import('Core', 'Configure');
|
|
|
|
/**
|
2009-03-18 17:55:58 +00:00
|
|
|
* ConfigureTest
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2009-03-18 17:55:58 +00:00
|
|
|
* @package cake
|
2008-10-30 17:30:26 +00:00
|
|
|
* @subpackage cake.tests.cases.libs
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2008-07-21 02:40:58 +00:00
|
|
|
class ConfigureTest extends CakeTestCase {
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* setUp method
|
2008-09-19 02:37:20 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function setUp() {
|
2009-03-21 23:55:39 +00:00
|
|
|
$this->_cacheDisable = Configure::read('Cache.disable');
|
2008-10-15 17:30:08 +00:00
|
|
|
Configure::write('Cache.disable', true);
|
2009-03-21 23:55:39 +00:00
|
|
|
|
|
|
|
$this->_debug = Configure::read('debug');
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* tearDown method
|
2008-09-19 02:37:20 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function tearDown() {
|
|
|
|
if (file_exists(TMP . 'cache' . DS . 'persistent' . DS . 'cake_core_core_paths')) {
|
|
|
|
unlink(TMP . 'cache' . DS . 'persistent' . DS . 'cake_core_core_paths');
|
|
|
|
}
|
|
|
|
if (file_exists(TMP . 'cache' . DS . 'persistent' . DS . 'cake_core_dir_map')) {
|
|
|
|
unlink(TMP . 'cache' . DS . 'persistent' . DS . 'cake_core_dir_map');
|
|
|
|
}
|
|
|
|
if (file_exists(TMP . 'cache' . DS . 'persistent' . DS . 'cake_core_file_map')) {
|
|
|
|
unlink(TMP . 'cache' . DS . 'persistent' . DS . 'cake_core_file_map');
|
|
|
|
}
|
|
|
|
if (file_exists(TMP . 'cache' . DS . 'persistent' . DS . 'cake_core_object_map')) {
|
|
|
|
unlink(TMP . 'cache' . DS . 'persistent' . DS . 'cake_core_object_map');
|
|
|
|
}
|
2008-10-15 17:30:08 +00:00
|
|
|
if (file_exists(TMP . 'cache' . DS . 'persistent' . DS . 'test.config.php')) {
|
|
|
|
unlink(TMP . 'cache' . DS . 'persistent' . DS . 'test.config.php');
|
|
|
|
}
|
|
|
|
if (file_exists(TMP . 'cache' . DS . 'persistent' . DS . 'test.php')) {
|
|
|
|
unlink(TMP . 'cache' . DS . 'persistent' . DS . 'test.php');
|
|
|
|
}
|
2009-03-21 23:55:39 +00:00
|
|
|
Configure::write('debug', $this->_debug);
|
|
|
|
Configure::write('Cache.disable', $this->_cacheDisable);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testRead method
|
2008-09-19 02:37:20 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testRead() {
|
|
|
|
$expected = 'ok';
|
2008-10-15 17:30:08 +00:00
|
|
|
Configure::write('level1.level2.level3_1', $expected);
|
|
|
|
Configure::write('level1.level2.level3_2', 'something_else');
|
|
|
|
$result = Configure::read('level1.level2.level3_1');
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
|
|
|
|
2008-10-15 17:30:08 +00:00
|
|
|
$result = Configure::read('level1.level2.level3_2');
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertEqual($result, 'something_else');
|
|
|
|
|
2008-10-15 17:30:08 +00:00
|
|
|
$result = Configure::read('debug');
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertTrue($result >= 0);
|
|
|
|
}
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testWrite method
|
2008-09-19 02:37:20 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testWrite() {
|
2008-10-15 17:30:08 +00:00
|
|
|
Configure::write('SomeName.someKey', 'myvalue');
|
|
|
|
$result = Configure::read('SomeName.someKey');
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertEqual($result, 'myvalue');
|
|
|
|
|
2008-10-15 17:30:08 +00:00
|
|
|
Configure::write('SomeName.someKey', null);
|
|
|
|
$result = Configure::read('SomeName.someKey');
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertEqual($result, null);
|
|
|
|
}
|
2008-06-13 14:04:28 +00:00
|
|
|
/**
|
|
|
|
* testSetErrorReporting Level
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
**/
|
|
|
|
function testSetErrorReportingLevel() {
|
2008-10-15 17:30:08 +00:00
|
|
|
Configure::write('debug', 0);
|
2008-06-13 14:04:28 +00:00
|
|
|
$result = ini_get('error_reporting');
|
|
|
|
$this->assertEqual($result, 0);
|
2008-09-19 02:37:20 +00:00
|
|
|
|
2008-10-15 17:30:08 +00:00
|
|
|
Configure::write('debug', 2);
|
2008-06-13 14:04:28 +00:00
|
|
|
$result = ini_get('error_reporting');
|
|
|
|
$this->assertEqual($result, E_ALL);
|
2008-09-19 02:37:20 +00:00
|
|
|
|
2008-06-13 14:04:28 +00:00
|
|
|
$result = ini_get('display_errors');
|
|
|
|
$this->assertEqual($result, 1);
|
2008-09-19 02:37:20 +00:00
|
|
|
|
2008-10-15 17:30:08 +00:00
|
|
|
Configure::write('debug', 0);
|
2008-06-13 14:04:28 +00:00
|
|
|
$result = ini_get('error_reporting');
|
|
|
|
$this->assertEqual($result, 0);
|
|
|
|
}
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testDelete method
|
2008-09-19 02:37:20 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testDelete() {
|
2008-10-15 17:30:08 +00:00
|
|
|
Configure::write('SomeName.someKey', 'myvalue');
|
|
|
|
$result = Configure::read('SomeName.someKey');
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertEqual($result, 'myvalue');
|
|
|
|
|
2008-10-15 17:30:08 +00:00
|
|
|
Configure::delete('SomeName.someKey');
|
|
|
|
$result = Configure::read('SomeName.someKey');
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertTrue($result === null);
|
|
|
|
|
2008-10-15 17:30:08 +00:00
|
|
|
Configure::write('SomeName', array('someKey' => 'myvalue', 'otherKey' => 'otherValue'));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-10-15 17:30:08 +00:00
|
|
|
$result = Configure::read('SomeName.someKey');
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertEqual($result, 'myvalue');
|
|
|
|
|
2008-10-15 17:30:08 +00:00
|
|
|
$result = Configure::read('SomeName.otherKey');
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertEqual($result, 'otherValue');
|
|
|
|
|
2008-10-15 17:30:08 +00:00
|
|
|
Configure::delete('SomeName');
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-10-15 17:30:08 +00:00
|
|
|
$result = Configure::read('SomeName.someKey');
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertTrue($result === null);
|
|
|
|
|
2008-10-15 17:30:08 +00:00
|
|
|
$result = Configure::read('SomeName.otherKey');
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertTrue($result === null);
|
|
|
|
}
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testLoad method
|
2008-09-19 02:37:20 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testLoad() {
|
2008-10-15 17:30:08 +00:00
|
|
|
$result = Configure::load('non_existing_configuration_file');
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertFalse($result);
|
|
|
|
|
2008-10-15 17:30:08 +00:00
|
|
|
$result = Configure::load('config');
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertTrue($result === null);
|
|
|
|
}
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testStore method
|
2008-09-19 02:37:20 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-10-15 17:30:08 +00:00
|
|
|
function testStoreAndLoad() {
|
|
|
|
Configure::write('Cache.disable', false);
|
|
|
|
|
|
|
|
$expected = array('data' => 'value');
|
|
|
|
Configure::store('SomeExample', 'test', $expected);
|
|
|
|
|
|
|
|
Configure::load('test');
|
|
|
|
$config = Configure::read('SomeExample');
|
|
|
|
$this->assertEqual($config, $expected);
|
|
|
|
|
|
|
|
$expected = array('data' => array('first' => 'value', 'second' => 'value2'));
|
|
|
|
Configure::store('AnotherExample', 'test.config', $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-10-15 17:30:08 +00:00
|
|
|
Configure::load('test.config');
|
|
|
|
$config = Configure::read('AnotherExample');
|
|
|
|
$this->assertEqual($config, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testVersion method
|
2008-09-19 02:37:20 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testVersion() {
|
2008-10-15 17:30:08 +00:00
|
|
|
$result = Configure::version();
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertTrue(version_compare($result, '1.2', '>='));
|
|
|
|
}
|
|
|
|
}
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* AppImportTest class
|
2008-09-19 02:37:20 +00:00
|
|
|
*
|
2008-10-30 17:30:26 +00:00
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.tests.cases.libs
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
class AppImportTest extends UnitTestCase {
|
2009-06-07 22:24:10 +00:00
|
|
|
/**
|
|
|
|
* testBuildPaths method
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testBuild() {
|
|
|
|
App::build();
|
|
|
|
$models = App::path('models');
|
|
|
|
$this->assertTrue(!empty($models));
|
2009-06-10 23:13:39 +00:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* testBuildPaths method
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testCore() {
|
|
|
|
$model = App::core('model');
|
|
|
|
$this->assertTrue(!empty($models));
|
2009-06-07 22:24:10 +00:00
|
|
|
}
|
2009-06-10 23:13:39 +00:00
|
|
|
/**
|
|
|
|
* testListObjects method
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testListObjects() {
|
|
|
|
$result = App::objects('class', TEST_CAKE_CORE_INCLUDE_PATH . 'libs');
|
|
|
|
$this->assertTrue(in_array('Xml', $result));
|
|
|
|
$this->assertTrue(in_array('Cache', $result));
|
|
|
|
$this->assertTrue(in_array('HttpSocket', $result));
|
|
|
|
|
|
|
|
$result = App::objects('behavior');
|
|
|
|
$this->assertTrue(in_array('Tree', $result));
|
|
|
|
|
|
|
|
$result = App::objects('controller');
|
|
|
|
$this->assertTrue(in_array('Pages', $result));
|
|
|
|
|
|
|
|
$result = App::objects('component');
|
|
|
|
$this->assertTrue(in_array('Auth', $result));
|
|
|
|
|
|
|
|
$result = App::objects('view');
|
|
|
|
$this->assertTrue(in_array('Media', $result));
|
|
|
|
|
|
|
|
$result = App::objects('helper');
|
|
|
|
$this->assertTrue(in_array('Html', $result));
|
|
|
|
|
|
|
|
$result = App::objects('model');
|
|
|
|
$notExpected = array('AppModel', 'Behavior', 'ConnectionManager', 'DbAcl', 'Model', 'Schema');
|
|
|
|
|
|
|
|
foreach ($notExpected as $class) {
|
|
|
|
$this->assertFalse(in_array($class, $result));
|
|
|
|
}
|
|
|
|
|
|
|
|
$result = App::objects('file');
|
|
|
|
$this->assertFalse($result);
|
|
|
|
|
|
|
|
$result = App::objects('file', 'non_existing_configure');
|
|
|
|
$expected = array();
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = App::objects('NonExistingType');
|
|
|
|
$this->assertFalse($result);
|
|
|
|
}
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testClassLoading method
|
2008-09-19 02:37:20 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testClassLoading() {
|
|
|
|
$file = App::import();
|
|
|
|
$this->assertTrue($file);
|
|
|
|
|
|
|
|
$file = App::import('Core', 'Model', false);
|
|
|
|
$this->assertTrue($file);
|
|
|
|
|
|
|
|
$file = App::import('Model', 'SomeRandomModelThatDoesNotExist', false);
|
|
|
|
$this->assertFalse($file);
|
|
|
|
|
|
|
|
$file = App::import('Model', 'AppModel', false);
|
|
|
|
$this->assertTrue($file);
|
|
|
|
|
|
|
|
$file = App::import('WrongType', null, true, array(), '');
|
|
|
|
$this->assertTrue($file);
|
|
|
|
|
|
|
|
$file = App::import('Model', 'NonExistingPlugin.NonExistingModel', false);
|
|
|
|
$this->assertFalse($file);
|
|
|
|
|
|
|
|
$file = App::import('Core', 'NonExistingPlugin.NonExistingModel', false);
|
|
|
|
$this->assertFalse($file);
|
|
|
|
|
|
|
|
$file = App::import('Model', array('NonExistingPlugin.NonExistingModel'), false);
|
|
|
|
$this->assertFalse($file);
|
|
|
|
|
|
|
|
$file = App::import('Core', array('NonExistingPlugin.NonExistingModel'), false);
|
|
|
|
$this->assertFalse($file);
|
|
|
|
|
|
|
|
$file = App::import('Core', array('NonExistingPlugin.NonExistingModel.AnotherChild'), false);
|
|
|
|
$this->assertFalse($file);
|
|
|
|
|
|
|
|
if (!class_exists('AppController')) {
|
|
|
|
$classes = array_flip(get_declared_classes());
|
|
|
|
|
|
|
|
if (PHP5) {
|
|
|
|
$this->assertFalse(isset($classes['PagesController']));
|
|
|
|
$this->assertFalse(isset($classes['AppController']));
|
|
|
|
} else {
|
|
|
|
$this->assertFalse(isset($classes['pagescontroller']));
|
|
|
|
$this->assertFalse(isset($classes['appcontroller']));
|
|
|
|
}
|
|
|
|
|
|
|
|
$file = App::import('Controller', 'Pages');
|
|
|
|
$this->assertTrue($file);
|
|
|
|
|
|
|
|
$classes = array_flip(get_declared_classes());
|
|
|
|
|
|
|
|
if (PHP5) {
|
|
|
|
$this->assertTrue(isset($classes['PagesController']));
|
|
|
|
$this->assertTrue(isset($classes['AppController']));
|
|
|
|
} else {
|
|
|
|
$this->assertTrue(isset($classes['pagescontroller']));
|
|
|
|
$this->assertTrue(isset($classes['appcontroller']));
|
|
|
|
}
|
|
|
|
|
|
|
|
$file = App::import('Behavior', 'Containable');
|
|
|
|
$this->assertTrue($file);
|
|
|
|
|
|
|
|
$file = App::import('Component', 'RequestHandler');
|
|
|
|
$this->assertTrue($file);
|
|
|
|
|
|
|
|
$file = App::import('Helper', 'Form');
|
|
|
|
$this->assertTrue($file);
|
|
|
|
|
|
|
|
$file = App::import('Model', 'NonExistingModel');
|
|
|
|
$this->assertFalse($file);
|
|
|
|
}
|
2008-09-19 02:37:20 +00:00
|
|
|
|
2009-06-07 22:24:10 +00:00
|
|
|
$_back = App::path('plugins');
|
|
|
|
App::path('plugins', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS));
|
2008-07-21 02:40:58 +00:00
|
|
|
|
|
|
|
$result = App::import('Controller', 'TestPlugin.Tests');
|
|
|
|
$this->assertTrue($result);
|
|
|
|
$this->assertTrue(class_exists('TestPluginAppController'));
|
2008-07-24 02:19:05 +00:00
|
|
|
$this->assertTrue(class_exists('TestsController'));
|
2008-09-19 02:37:20 +00:00
|
|
|
|
2008-07-21 02:40:58 +00:00
|
|
|
$result = App::import('Helper', 'TestPlugin.OtherHelper');
|
|
|
|
$this->assertTrue($result);
|
2008-07-24 02:19:05 +00:00
|
|
|
$this->assertTrue(class_exists('OtherHelperHelper'));
|
2008-09-19 02:37:20 +00:00
|
|
|
|
2009-06-07 22:24:10 +00:00
|
|
|
App::path('plugins', $_back);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testFileLoading method
|
2008-09-19 02:37:20 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testFileLoading () {
|
|
|
|
$file = App::import('File', 'RealFile', false, array(), TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'config.php');
|
|
|
|
$this->assertTrue($file);
|
|
|
|
|
|
|
|
$file = App::import('File', 'NoFile', false, array(), TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'cake' . DS . 'config.php');
|
|
|
|
$this->assertFalse($file);
|
|
|
|
}
|
|
|
|
// import($type = null, $name = null, $parent = true, $file = null, $search = array(), $return = false) {
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testFileLoadingWithArray method
|
2008-09-19 02:37:20 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testFileLoadingWithArray() {
|
|
|
|
$type = array('type' => 'File', 'name' => 'SomeName', 'parent' => false,
|
|
|
|
'file' => TEST_CAKE_CORE_INCLUDE_PATH . DS . 'config' . DS . 'config.php');
|
|
|
|
$file = App::import($type);
|
|
|
|
$this->assertTrue($file);
|
|
|
|
|
|
|
|
$type = array('type' => 'File', 'name' => 'NoFile', 'parent' => false,
|
|
|
|
'file' => TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'cake' . DS . 'config.php');
|
|
|
|
$file = App::import($type);
|
|
|
|
$this->assertFalse($file);
|
|
|
|
}
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testFileLoadingReturnValue method
|
2008-09-19 02:37:20 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testFileLoadingReturnValue () {
|
|
|
|
$file = App::import('File', 'Name', false, array(), TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'config.php', true);
|
|
|
|
$this->assertTrue($file);
|
|
|
|
|
|
|
|
$this->assertTrue(isset($file['Cake.version']));
|
|
|
|
|
|
|
|
$type = array('type' => 'File', 'name' => 'OtherName', 'parent' => false,
|
|
|
|
'file' => TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'config.php', 'return' => true);
|
|
|
|
$file = App::import($type);
|
|
|
|
$this->assertTrue($file);
|
|
|
|
|
|
|
|
$this->assertTrue(isset($file['Cake.version']));
|
|
|
|
}
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testLoadingWithSearch method
|
2008-09-19 02:37:20 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testLoadingWithSearch () {
|
|
|
|
$file = App::import('File', 'NewName', false, array(TEST_CAKE_CORE_INCLUDE_PATH ), 'config.php');
|
|
|
|
$this->assertTrue($file);
|
|
|
|
|
|
|
|
$file = App::import('File', 'AnotherNewName', false, array(LIBS), 'config.php');
|
|
|
|
$this->assertFalse($file);
|
|
|
|
}
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testLoadingWithSearchArray method
|
2008-09-19 02:37:20 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testLoadingWithSearchArray () {
|
|
|
|
$type = array('type' => 'File', 'name' => 'RandomName', 'parent' => false, 'file' => 'config.php', 'search' => array(TEST_CAKE_CORE_INCLUDE_PATH ));
|
|
|
|
$file = App::import($type);
|
|
|
|
$this->assertTrue($file);
|
|
|
|
|
|
|
|
$type = array('type' => 'File', 'name' => 'AnotherRandomName', 'parent' => false, 'file' => 'config.php', 'search' => array(LIBS));
|
|
|
|
$file = App::import($type);
|
|
|
|
$this->assertFalse($file);
|
|
|
|
}
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testMultipleLoading method
|
2008-09-19 02:37:20 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testMultipleLoading() {
|
2009-03-15 20:52:27 +00:00
|
|
|
$toLoad = array('I18n', 'CakeSocket');
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$classes = array_flip(get_declared_classes());
|
|
|
|
$this->assertFalse(isset($classes['i18n']));
|
2009-03-15 20:52:27 +00:00
|
|
|
$this->assertFalse(isset($classes['CakeSocket']));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$load = App::import($toLoad);
|
|
|
|
$this->assertTrue($load);
|
|
|
|
|
|
|
|
$classes = array_flip(get_declared_classes());
|
|
|
|
|
|
|
|
if (PHP5) {
|
|
|
|
$this->assertTrue(isset($classes['I18n']));
|
|
|
|
} else {
|
|
|
|
$this->assertTrue(isset($classes['i18n']));
|
|
|
|
}
|
|
|
|
|
2009-03-15 20:52:27 +00:00
|
|
|
$load = App::import(array('I18n', 'SomeNotFoundClass', 'CakeSocket'));
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertFalse($load);
|
|
|
|
|
|
|
|
$load = App::import($toLoad);
|
|
|
|
$this->assertTrue($load);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* This test only works if you have plugins/my_plugin set up.
|
|
|
|
* plugins/my_plugin/models/my_plugin.php and other_model.php
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
function testMultipleLoadingByType() {
|
|
|
|
$classes = array_flip(get_declared_classes());
|
|
|
|
$this->assertFalse(isset($classes['OtherPlugin']));
|
|
|
|
$this->assertFalse(isset($classes['MyPlugin']));
|
|
|
|
|
|
|
|
|
|
|
|
$load = App::import('Model', array('MyPlugin.OtherPlugin', 'MyPlugin.MyPlugin'));
|
|
|
|
$this->assertTrue($load);
|
|
|
|
|
|
|
|
$classes = array_flip(get_declared_classes());
|
|
|
|
$this->assertTrue(isset($classes['OtherPlugin']));
|
|
|
|
$this->assertTrue(isset($classes['MyPlugin']));
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
function testLoadingVendor() {
|
2009-06-07 22:24:10 +00:00
|
|
|
App::path('plugins', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS));
|
|
|
|
App::path('vendors', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'vendors'. DS));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
ob_start();
|
|
|
|
$result = App::import('Vendor', 'TestPlugin.TestPluginAsset', array('ext' => 'css'));
|
|
|
|
$text = ob_get_clean();
|
|
|
|
$this->assertTrue($result);
|
|
|
|
$this->assertEqual($text, 'this is the test plugin asset css file');
|
|
|
|
|
|
|
|
ob_start();
|
|
|
|
$result = App::import('Vendor', 'TestAsset', array('ext' => 'css'));
|
|
|
|
$text = ob_get_clean();
|
|
|
|
$this->assertTrue($result);
|
|
|
|
$this->assertEqual($text, 'this is the test asset css file');
|
|
|
|
|
|
|
|
$result = App::import('Vendor', 'TestPlugin.SamplePlugin');
|
|
|
|
$this->assertTrue($result);
|
|
|
|
$this->assertTrue(class_exists('SamplePluginClassTestName'));
|
|
|
|
|
2008-12-17 04:14:34 +00:00
|
|
|
$result = App::import('Vendor', 'ConfigureTestVendorSample');
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertTrue($result);
|
2008-12-17 04:14:34 +00:00
|
|
|
$this->assertTrue(class_exists('ConfigureTestVendorSample'));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
ob_start();
|
|
|
|
$result = App::import('Vendor', 'SomeName', array('file' => 'some.name.php'));
|
|
|
|
$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);
|
2008-11-08 02:58:37 +00:00
|
|
|
$this->assertEqual($text, 'This is the hello.php file in Test directory');
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
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');
|
2008-09-19 02:37:20 +00:00
|
|
|
|
|
|
|
ob_start();
|
|
|
|
$result = App::import('Vendor', 'Welcome');
|
|
|
|
$text = ob_get_clean();
|
|
|
|
$this->assertTrue($result);
|
2008-11-08 02:58:37 +00:00
|
|
|
$this->assertEqual($text, 'This is the welcome.php file in vendors directory');
|
2008-09-19 02:37:20 +00:00
|
|
|
|
|
|
|
ob_start();
|
|
|
|
$result = App::import('Vendor', 'TestPlugin.Welcome');
|
|
|
|
$text = ob_get_clean();
|
|
|
|
$this->assertTrue($result);
|
2008-11-08 02:58:37 +00:00
|
|
|
$this->assertEqual($text, 'This is the welcome.php file in test_plugin/vendors directory');
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
}
|
2008-06-27 08:17:02 +00:00
|
|
|
?>
|