From f4d8a7eff1c58af828a6f82537f8a4170a3f151d Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 2 Apr 2011 10:00:59 -0400 Subject: [PATCH] Making Configure::load merge by default. Adding a test case for overwriting. Fixes #1618 --- cake/libs/configure.php | 8 +++--- cake/tests/cases/libs/configure.test.php | 31 ++++++++++++++++++++---- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/cake/libs/configure.php b/cake/libs/configure.php index cabe174c8..97b54b3e9 100644 --- a/cake/libs/configure.php +++ b/cake/libs/configure.php @@ -272,9 +272,9 @@ class Configure { * Loads stored configuration information from a resource. You can add * config file resource readers with `Configure::config()`. * - * Loaded configuration infomration will be merged with the current + * Loaded configuration information will be merged with the current * runtime configuration. You can load configuration files from plugins - * by preceeding the filename with the plugin name. + * by preceding the filename with the plugin name. * * `Configure::load('Users.user', 'default')` * @@ -285,12 +285,12 @@ class Configure { * * @link http://book.cakephp.org/view/929/load * @param string $key name of configuration resource to load. - * @param string $config Name of the configured reader to use to read the resource identfied by $key. + * @param string $config Name of the configured reader to use to read the resource identified by $key. * @param boolean $merge if config files should be merged instead of simply overridden * @return mixed false if file not found, void if load successful. * @throws ConfigureException Will throw any exceptions the reader raises. */ - public static function load($key, $config = 'default', $merge = false) { + public static function load($key, $config = 'default', $merge = true) { if (!isset(self::$_readers[$config])) { return false; } diff --git a/cake/tests/cases/libs/configure.test.php b/cake/tests/cases/libs/configure.test.php index dad3ed227..920eb15f7 100644 --- a/cake/tests/cases/libs/configure.test.php +++ b/cake/tests/cases/libs/configure.test.php @@ -193,26 +193,47 @@ class ConfigureTest extends CakeTestCase { } /** - * test load + * test load with merging * * @return void */ - function testLoad() { + function testLoadWithMerge() { Configure::config('test', new PhpReader(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'config' . DS)); $result = Configure::load('var_test', 'test'); $this->assertTrue($result); - + $this->assertEquals('value', Configure::read('Read')); - + $result = Configure::load('var_test2', 'test', true); $this->assertTrue($result); - + $this->assertEquals('value2', Configure::read('Read')); $this->assertEquals('buried2', Configure::read('Deep.Second.SecondDeepest')); $this->assertEquals('buried', Configure::read('Deep.Deeper.Deepest')); } +/** + * test loading with overwrite + * + * @return void + */ + function testLoadNoMerge() { + Configure::config('test', new PhpReader(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'config' . DS)); + + $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')); + } + /** * testLoad method *