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
|
|
|
*
|
2012-04-27 02:49:18 +00:00
|
|
|
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
|
2013-02-08 11:59:49 +00:00
|
|
|
* Copyright (c) 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
|
2013-02-08 12:22:51 +00:00
|
|
|
* For full copyright and license information, please see the LICENSE.txt
|
2010-10-03 16:31:21 +00:00
|
|
|
* Redistributions of files must retain the above copyright notice
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2013-02-08 11:59:49 +00:00
|
|
|
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2012-04-27 02:49:18 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Core
|
2008-10-30 17:30:26 +00:00
|
|
|
* @since CakePHP(tm) v 1.2.0.5432
|
2013-05-30 22:11:14 +00:00
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2013-05-30 22:11:14 +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
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Core
|
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
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function setUp() {
|
2012-04-16 02:20:34 +00:00
|
|
|
parent::setUp();
|
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
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function tearDown() {
|
2012-04-16 02:20:34 +00:00
|
|
|
parent::tearDown();
|
2008-05-30 11:40:08 +00:00
|
|
|
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');
|
|
|
|
}
|
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
|
|
|
|
2013-07-31 08:24:51 +00:00
|
|
|
/**
|
|
|
|
* Test to ensure bootrapping doesn't overwrite prior configs set under 'App' key
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testBootstrap() {
|
|
|
|
$expected = array(
|
|
|
|
'foo' => 'bar'
|
|
|
|
);
|
|
|
|
Configure::write('App', $expected);
|
|
|
|
|
|
|
|
Configure::bootstrap(true);
|
|
|
|
$result = Configure::read('App');
|
|
|
|
|
|
|
|
$this->assertEquals($expected['foo'], $result['foo']);
|
|
|
|
$this->assertFalse($result['base']);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testRead() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$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');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-10-15 17:30:08 +00:00
|
|
|
$result = Configure::read('level1.level2.level3_2');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('something_else', $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-10-15 17:30:08 +00:00
|
|
|
$result = Configure::read('debug');
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertTrue($result >= 0);
|
2011-04-17 10:35:21 +00:00
|
|
|
|
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
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public 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');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('myvalue', $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
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');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(null, $result);
|
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');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-07-26 01:27:02 +00:00
|
|
|
|
2009-07-24 20:29:46 +00:00
|
|
|
$result = Configure::read('Key.One');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($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');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($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');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals('cool', $result);
|
2011-05-21 19:49:28 +00:00
|
|
|
|
|
|
|
Configure::write('one.two.three.four', '4');
|
|
|
|
$result = Configure::read('one.two.three.four');
|
2011-05-22 00:21:15 +00:00
|
|
|
$this->assertEquals('4', $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
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public 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');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(0, $result);
|
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');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(1, $result);
|
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
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testDelete() {
|
2008-10-15 17:30:08 +00:00
|
|
|
Configure::write('SomeName.someKey', 'myvalue');
|
|
|
|
$result = Configure::read('SomeName.someKey');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('myvalue', $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
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');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('myvalue', $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-10-15 17:30:08 +00:00
|
|
|
$result = Configure::read('SomeName.otherKey');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('otherValue', $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
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
|
|
|
|
2012-09-03 23:04:48 +00:00
|
|
|
/**
|
|
|
|
* testCheck method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testCheck() {
|
|
|
|
Configure::write('ConfigureTestCase', 'value');
|
|
|
|
$this->assertTrue(Configure::check('ConfigureTestCase'));
|
|
|
|
|
|
|
|
$this->assertFalse(Configure::check('NotExistingConfigureTestCase'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testCheckingSavedEmpty method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testCheckingSavedEmpty() {
|
|
|
|
$this->assertTrue(Configure::write('ConfigureTestCase', 0));
|
|
|
|
$this->assertTrue(Configure::check('ConfigureTestCase'));
|
|
|
|
|
|
|
|
$this->assertTrue(Configure::write('ConfigureTestCase', '0'));
|
|
|
|
$this->assertTrue(Configure::check('ConfigureTestCase'));
|
|
|
|
|
|
|
|
$this->assertTrue(Configure::write('ConfigureTestCase', false));
|
|
|
|
$this->assertTrue(Configure::check('ConfigureTestCase'));
|
|
|
|
|
|
|
|
$this->assertTrue(Configure::write('ConfigureTestCase', null));
|
|
|
|
$this->assertFalse(Configure::check('ConfigureTestCase'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testCheckKeyWithSpaces method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testCheckKeyWithSpaces() {
|
|
|
|
$this->assertTrue(Configure::write('Configure Test', "test"));
|
|
|
|
$this->assertTrue(Configure::check('Configure Test'));
|
|
|
|
Configure::delete('Configure Test');
|
|
|
|
|
|
|
|
$this->assertTrue(Configure::write('Configure Test.Test Case', "test"));
|
|
|
|
$this->assertTrue(Configure::check('Configure Test.Test Case'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testCheckEmpty
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testCheckEmpty() {
|
|
|
|
$this->assertFalse(Configure::check());
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testLoadExceptionOnNonExistantFile() {
|
2010-12-04 06:05:12 +00:00
|
|
|
Configure::config('test', new PhpReader());
|
2013-01-23 12:45:50 +00:00
|
|
|
Configure::load('non_existing_configuration_file', 'test');
|
2010-12-04 06:05:12 +00:00
|
|
|
}
|
|
|
|
|
2011-09-17 18:30:39 +00:00
|
|
|
/**
|
|
|
|
* test load method for default config creation
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testLoadDefaultConfig() {
|
|
|
|
try {
|
|
|
|
Configure::load('non_existing_configuration_file');
|
|
|
|
} catch (Exception $e) {
|
|
|
|
$result = Configure::configured('default');
|
|
|
|
$this->assertTrue($result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-04 06:05:12 +00:00
|
|
|
/**
|
2011-04-02 14:00:59 +00:00
|
|
|
* test load with merging
|
2010-12-04 06:05:12 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testLoadWithMerge() {
|
2011-04-17 10:35:21 +00:00
|
|
|
Configure::config('test', new PhpReader(CAKE . 'Test' . 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);
|
2011-04-02 14:00:59 +00:00
|
|
|
|
2010-12-04 06:05:12 +00:00
|
|
|
$this->assertEquals('value', Configure::read('Read'));
|
2011-04-02 14:00:59 +00:00
|
|
|
|
2011-03-29 02:39:35 +00:00
|
|
|
$result = Configure::load('var_test2', 'test', true);
|
|
|
|
$this->assertTrue($result);
|
2011-04-02 14:00:59 +00:00
|
|
|
|
2011-03-29 02:39:35 +00:00
|
|
|
$this->assertEquals('value2', Configure::read('Read'));
|
|
|
|
$this->assertEquals('buried2', Configure::read('Deep.Second.SecondDeepest'));
|
|
|
|
$this->assertEquals('buried', Configure::read('Deep.Deeper.Deepest'));
|
2012-01-07 15:45:35 +00:00
|
|
|
$this->assertEquals('Overwrite', Configure::read('TestAcl.classname'));
|
|
|
|
$this->assertEquals('one', Configure::read('TestAcl.custom'));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2011-04-02 14:00:59 +00:00
|
|
|
/**
|
|
|
|
* test loading with overwrite
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testLoadNoMerge() {
|
2011-04-17 10:35:21 +00:00
|
|
|
Configure::config('test', new PhpReader(CAKE . 'Test' . DS . 'test_app' . DS . 'Config' . DS));
|
2011-04-02 14:00:59 +00:00
|
|
|
|
|
|
|
$result = Configure::load('var_test', 'test');
|
|
|
|
$this->assertTrue($result);
|
|
|
|
|
|
|
|
$this->assertEquals('value', Configure::read('Read'));
|
|
|
|
|
|
|
|
$result = Configure::load('var_test2', 'test', false);
|
|
|
|
$this->assertTrue($result);
|
|
|
|
|
|
|
|
$this->assertEquals('value2', Configure::read('Read'));
|
|
|
|
$this->assertEquals('buried2', Configure::read('Deep.Second.SecondDeepest'));
|
|
|
|
$this->assertNull(Configure::read('Deep.Deeper.Deepest'));
|
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
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testLoadPlugin() {
|
2012-02-18 12:04:54 +00:00
|
|
|
App::build(array(
|
|
|
|
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
|
|
|
|
), App::RESET);
|
2010-12-04 06:05:12 +00:00
|
|
|
Configure::config('test', new PhpReader());
|
2011-05-10 05:16:24 +00:00
|
|
|
CakePlugin::load('TestPlugin');
|
|
|
|
$result = Configure::load('TestPlugin.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');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals($expected, $config);
|
2009-11-15 21:59:19 +00:00
|
|
|
|
2011-05-10 05:16:24 +00:00
|
|
|
$result = Configure::load('TestPlugin.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');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals($expected, $config);
|
2011-05-10 05:16:24 +00:00
|
|
|
CakePlugin::unload();
|
2009-11-15 21:59:19 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public 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
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testStoreAndRestoreWithData() {
|
2010-12-04 22:26:59 +00:00
|
|
|
Configure::write('Cache.disable', false);
|
|
|
|
|
|
|
|
Configure::write('testing', 'value');
|
|
|
|
Configure::store('store_test', 'default', array('store_test' => 'one'));
|
|
|
|
Configure::delete('testing');
|
2012-02-23 23:29:53 +00:00
|
|
|
$this->assertNull(Configure::read('store_test'), 'Calling store with data shouldn\'t modify runtime.');
|
2010-12-04 22:26:59 +00:00
|
|
|
|
|
|
|
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
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public 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
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testReaderSetup() {
|
2010-12-04 05:09:11 +00:00
|
|
|
$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.
|
|
|
|
*
|
2011-11-03 03:25:09 +00:00
|
|
|
* @expectedException PHPUnit_Framework_Error
|
2010-12-04 05:09:11 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testReaderExceptionOnIncorrectClass() {
|
2010-12-04 05:09:11 +00:00
|
|
|
$reader = new StdClass();
|
2010-12-04 05:10:42 +00:00
|
|
|
Configure::config('test', $reader);
|
2010-12-04 05:09:11 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2012-04-15 03:31:26 +00:00
|
|
|
/**
|
|
|
|
* Test that clear wipes all values.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testClear() {
|
|
|
|
Configure::write('test', 'value');
|
|
|
|
$this->assertTrue(Configure::clear());
|
|
|
|
$this->assertNull(Configure::read('debug'));
|
|
|
|
$this->assertNull(Configure::read('test'));
|
|
|
|
}
|
2012-04-20 02:45:01 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException ConfigureException
|
|
|
|
*/
|
|
|
|
public function testDumpNoAdapter() {
|
|
|
|
Configure::dump(TMP . 'test.php', 'does_not_exist');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test dump integrated with the PhpReader.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testDump() {
|
|
|
|
Configure::config('test_reader', new PhpReader(TMP));
|
|
|
|
|
2012-04-22 00:26:35 +00:00
|
|
|
$result = Configure::dump('config_test.php', 'test_reader');
|
2012-04-20 02:45:01 +00:00
|
|
|
$this->assertTrue($result > 0);
|
|
|
|
$result = file_get_contents(TMP . 'config_test.php');
|
|
|
|
$this->assertContains('<?php', $result);
|
|
|
|
$this->assertContains('$config = ', $result);
|
2012-11-14 09:00:15 +00:00
|
|
|
if (file_exists(TMP . 'config_test.php')) {
|
|
|
|
unlink(TMP . 'config_test.php');
|
|
|
|
}
|
2012-04-20 02:45:01 +00:00
|
|
|
}
|
|
|
|
|
2012-05-01 01:07:32 +00:00
|
|
|
/**
|
|
|
|
* Test dumping only some of the data.
|
|
|
|
*
|
2013-07-05 15:19:22 +00:00
|
|
|
* @return void
|
2012-05-01 01:07:32 +00:00
|
|
|
*/
|
|
|
|
public function testDumpPartial() {
|
|
|
|
Configure::config('test_reader', new PhpReader(TMP));
|
|
|
|
|
|
|
|
$result = Configure::dump('config_test.php', 'test_reader', array('Error'));
|
|
|
|
$this->assertTrue($result > 0);
|
|
|
|
$result = file_get_contents(TMP . 'config_test.php');
|
|
|
|
$this->assertContains('<?php', $result);
|
|
|
|
$this->assertContains('$config = ', $result);
|
|
|
|
$this->assertContains('Error', $result);
|
|
|
|
$this->assertNotContains('debug', $result);
|
|
|
|
|
2012-11-14 09:00:15 +00:00
|
|
|
if (file_exists(TMP . 'config_test.php')) {
|
|
|
|
unlink(TMP . 'config_test.php');
|
|
|
|
}
|
2012-05-01 01:07:32 +00:00
|
|
|
}
|
|
|
|
|
2012-03-15 15:06:54 +00:00
|
|
|
}
|