Skip to content

Commit

Permalink
refactoring Configure::load() to load config files from plugins, test…
Browse files Browse the repository at this point in the history
…s and config files added

Signed-off-by: Mark Story <mark@mark-story.com>
  • Loading branch information
ceeram authored and markstory committed Nov 15, 2009
1 parent e1d6036 commit 7a4793a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
10 changes: 9 additions & 1 deletion cake/libs/configure.php
Expand Up @@ -201,8 +201,16 @@ function delete($var = null) {
*/
function load($fileName) {
$found = false;
$pluginPath = false;
if(strpos($fileName, '.') !== false) {
$plugin = explode('.', $fileName, 2);
$pluginPath = App::pluginPath($plugin[0]);
}

if (file_exists(CONFIGS . $fileName . '.php')) {
if ($pluginPath && file_exists($pluginPath . 'config' . DS . $plugin[1] . '.php')) {
include($pluginPath . 'config' . DS . $plugin[1] . '.php');
$found = true;
} elseif (file_exists(CONFIGS . $fileName . '.php')) {
include(CONFIGS . $fileName . '.php');
$found = true;
} elseif (file_exists(CACHE . 'persistent' . DS . $fileName . '.php')) {
Expand Down
21 changes: 21 additions & 0 deletions cake/tests/cases/libs/configure.test.php
Expand Up @@ -224,6 +224,27 @@ function testLoad() {
$this->assertTrue($result === null);
}

/**
* testLoad method
*
* @access public
* @return void
*/
function testLoadPlugin() {
App::build(array('plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS)), true);
$result = Configure::load('test_plugin.load');
$this->assertTrue($result === null);
$expected = '/test_app/plugins/test_plugin/config/load.php';
$config = Configure::read('plugin_load');
$this->assertEqual($config, $expected);

$result = Configure::load('test_plugin.more.load');
$this->assertTrue($result === null);
$expected = '/test_app/plugins/test_plugin/config/more.load.php';
$config = Configure::read('plugin_more_load');
$this->assertEqual($config, $expected);
}

/**
* testStore method
*
Expand Down
3 changes: 3 additions & 0 deletions cake/tests/test_app/plugins/test_plugin/config/load.php
@@ -0,0 +1,3 @@
<?php
$config['plugin_load'] = '/test_app/plugins/test_plugin/config/load.php';
?>
3 changes: 3 additions & 0 deletions cake/tests/test_app/plugins/test_plugin/config/more.load.php
@@ -0,0 +1,3 @@
<?php
$config['plugin_more_load'] = '/test_app/plugins/test_plugin/config/more.load.php';
?>

0 comments on commit 7a4793a

Please sign in to comment.