2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
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
|
|
|
*
|
2010-10-03 16:31:21 +00:00
|
|
|
* PHP 5
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-05-19 01:15:13 +00:00
|
|
|
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
|
2010-01-26 19:18:20 +00:00
|
|
|
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-10-03 16:31:21 +00:00
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-01-26 19:18:20 +00:00
|
|
|
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2010-05-19 01:15:13 +00:00
|
|
|
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases.libs
|
2008-10-30 17:30:26 +00:00
|
|
|
* @since CakePHP(tm) v 1.2.0.5432
|
2010-10-03 16:27:27 +00:00
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-12-09 05:13:11 +00:00
|
|
|
App::uses('PhpReader', 'Configure');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2009-03-18 17:55:58 +00:00
|
|
|
* ConfigureTest
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases.libs
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2008-07-21 02:40:58 +00:00
|
|
|
class ConfigureTest extends CakeTestCase {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
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');
|
|
|
|
$this->_debug = Configure::read('debug');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-06-11 16:13:16 +00:00
|
|
|
Configure::write('Cache.disable', true);
|
|
|
|
App::build();
|
2010-09-22 02:16:33 +00:00
|
|
|
App::objects('plugin', null, true);
|
2009-07-24 19:18:37 +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);
|
2010-12-04 06:05:12 +00:00
|
|
|
Configure::drop('test');
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +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);
|
2010-07-06 01:50:36 +00:00
|
|
|
|
|
|
|
$result = Configure::read();
|
|
|
|
$this->assertTrue(is_array($result));
|
|
|
|
$this->assertTrue(isset($result['debug']));
|
|
|
|
$this->assertTrue(isset($result['level1']));
|
|
|
|
|
|
|
|
$result = Configure::read('something_I_just_made_up_now');
|
|
|
|
$this->assertEquals(null, $result, 'Missing key should return null.');
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
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() {
|
2010-03-03 23:20:15 +00:00
|
|
|
$writeResult = Configure::write('SomeName.someKey', 'myvalue');
|
|
|
|
$this->assertTrue($writeResult);
|
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');
|
|
|
|
|
2010-03-03 23:20:15 +00:00
|
|
|
$writeResult = Configure::write('SomeName.someKey', null);
|
|
|
|
$this->assertTrue($writeResult);
|
2008-10-15 17:30:08 +00:00
|
|
|
$result = Configure::read('SomeName.someKey');
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertEqual($result, null);
|
2009-07-26 01:27:02 +00:00
|
|
|
|
2009-07-24 20:29:46 +00:00
|
|
|
$expected = array('One' => array('Two' => array('Three' => array('Four' => array('Five' => 'cool')))));
|
2010-03-03 23:20:15 +00:00
|
|
|
$writeResult = Configure::write('Key', $expected);
|
|
|
|
$this->assertTrue($writeResult);
|
2009-07-26 01:27:02 +00:00
|
|
|
|
2009-07-24 20:29:46 +00:00
|
|
|
$result = Configure::read('Key');
|
|
|
|
$this->assertEqual($expected, $result);
|
2009-07-26 01:27:02 +00:00
|
|
|
|
2009-07-24 20:29:46 +00:00
|
|
|
$result = Configure::read('Key.One');
|
|
|
|
$this->assertEqual($expected['One'], $result);
|
2009-07-26 01:27:02 +00:00
|
|
|
|
2009-07-24 20:29:46 +00:00
|
|
|
$result = Configure::read('Key.One.Two');
|
|
|
|
$this->assertEqual($expected['One']['Two'], $result);
|
2009-07-26 01:27:02 +00:00
|
|
|
|
2009-07-24 20:29:46 +00:00
|
|
|
$result = Configure::read('Key.One.Two.Three.Four.Five');
|
|
|
|
$this->assertEqual('cool', $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-13 14:04:28 +00:00
|
|
|
/**
|
2010-11-15 01:58:20 +00:00
|
|
|
* test setting display_errors with debug.
|
2008-06-13 14:04:28 +00:00
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2010-11-15 01:58:20 +00:00
|
|
|
function testDebugSettingDisplayErrors() {
|
2008-10-15 17:30:08 +00:00
|
|
|
Configure::write('debug', 0);
|
2010-11-15 01:58:20 +00:00
|
|
|
$result = ini_get('display_errors');
|
2008-06-13 14:04:28 +00:00
|
|
|
$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('display_errors');
|
|
|
|
$this->assertEqual($result, 1);
|
2009-09-08 03:28:50 +00:00
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testLoad method
|
2008-09-19 02:37:20 +00:00
|
|
|
*
|
2010-12-04 06:05:12 +00:00
|
|
|
* @expectedException RuntimeException
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testLoadExceptionOnNonExistantFile() {
|
|
|
|
Configure::config('test', new PhpReader());
|
|
|
|
$result = Configure::load('non_existing_configuration_file', 'test');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test load
|
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testLoad() {
|
2010-12-20 04:03:37 +00:00
|
|
|
Configure::config('test', new PhpReader(LIBS . 'tests' . DS . 'test_app' . DS . 'config' . DS));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-12-04 06:05:12 +00:00
|
|
|
$result = Configure::load('var_test', 'test');
|
2010-03-03 23:20:15 +00:00
|
|
|
$this->assertTrue($result);
|
2010-12-04 06:05:12 +00:00
|
|
|
|
|
|
|
$this->assertEquals('value', Configure::read('Read'));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-11-15 21:59:19 +00:00
|
|
|
/**
|
|
|
|
* testLoad method
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testLoadPlugin() {
|
2010-12-20 04:03:37 +00:00
|
|
|
App::build(array('plugins' => array(LIBS . 'tests' . DS . 'test_app' . DS . 'plugins' . DS)), true);
|
2010-12-04 06:05:12 +00:00
|
|
|
Configure::config('test', new PhpReader());
|
|
|
|
|
|
|
|
$result = Configure::load('test_plugin.load', 'test');
|
2010-03-03 23:20:15 +00:00
|
|
|
$this->assertTrue($result);
|
2009-11-15 21:59:19 +00:00
|
|
|
$expected = '/test_app/plugins/test_plugin/config/load.php';
|
|
|
|
$config = Configure::read('plugin_load');
|
|
|
|
$this->assertEqual($config, $expected);
|
|
|
|
|
2010-12-04 06:05:12 +00:00
|
|
|
$result = Configure::load('test_plugin.more.load', 'test');
|
2010-03-03 23:20:15 +00:00
|
|
|
$this->assertTrue($result);
|
2009-11-15 21:59:19 +00:00
|
|
|
$expected = '/test_app/plugins/test_plugin/config/more.load.php';
|
|
|
|
$config = Configure::read('plugin_more_load');
|
|
|
|
$this->assertEqual($config, $expected);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
*/
|
2010-12-04 22:26:59 +00:00
|
|
|
function testStoreAndRestore() {
|
2008-10-15 17:30:08 +00:00
|
|
|
Configure::write('Cache.disable', false);
|
|
|
|
|
2010-12-04 22:26:59 +00:00
|
|
|
Configure::write('Testing', 'yummy');
|
|
|
|
$this->assertTrue(Configure::store('store_test', 'default'));
|
2008-10-15 17:30:08 +00:00
|
|
|
|
2010-12-04 22:26:59 +00:00
|
|
|
Configure::delete('Testing');
|
|
|
|
$this->assertNull(Configure::read('Testing'));
|
2008-10-15 17:30:08 +00:00
|
|
|
|
2010-12-04 22:26:59 +00:00
|
|
|
Configure::restore('store_test', 'default');
|
|
|
|
$this->assertEquals('yummy', Configure::read('Testing'));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-12-04 22:26:59 +00:00
|
|
|
Cache::delete('store_test', 'default');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test that store and restore only store/restore the provided data.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testStoreAndRestoreWithData() {
|
|
|
|
Configure::write('Cache.disable', false);
|
|
|
|
|
|
|
|
Configure::write('testing', 'value');
|
|
|
|
Configure::store('store_test', 'default', array('store_test' => 'one'));
|
|
|
|
Configure::delete('testing');
|
|
|
|
$this->assertNull(Configure::read('store_test'), 'Calling store with data shouldnt modify runtime.');
|
|
|
|
|
|
|
|
Configure::restore('store_test', 'default');
|
|
|
|
$this->assertEquals('one', Configure::read('store_test'));
|
|
|
|
$this->assertNull(Configure::read('testing'), 'Values that were not stored are not restored.');
|
|
|
|
|
|
|
|
Cache::delete('store_test', 'default');
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +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', '>='));
|
|
|
|
}
|
2010-12-04 05:09:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* test adding new readers.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testReaderSetup() {
|
|
|
|
$reader = new PhpReader();
|
2010-12-04 05:10:42 +00:00
|
|
|
Configure::config('test', $reader);
|
2010-12-04 05:09:11 +00:00
|
|
|
$configured = Configure::configured();
|
|
|
|
|
|
|
|
$this->assertTrue(in_array('test', $configured));
|
2010-12-05 03:57:33 +00:00
|
|
|
|
|
|
|
$this->assertTrue(Configure::configured('test'));
|
|
|
|
$this->assertFalse(Configure::configured('fake_garbage'));
|
|
|
|
|
2010-12-04 05:14:55 +00:00
|
|
|
$this->assertTrue(Configure::drop('test'));
|
|
|
|
$this->assertFalse(Configure::drop('test'), 'dropping things that do not exist should return false.');
|
2010-12-04 05:09:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test reader() throwing exceptions on missing interface.
|
|
|
|
*
|
|
|
|
* @expectedException Exception
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testReaderExceptionOnIncorrectClass() {
|
|
|
|
$reader = new StdClass();
|
2010-12-04 05:10:42 +00:00
|
|
|
Configure::config('test', $reader);
|
2010-12-04 05:09:11 +00:00
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|