diff options
-rw-r--r-- | core/Config.php | 38 | ||||
-rw-r--r-- | tests/core/Config.test.php | 42 | ||||
-rwxr-xr-x | tests/core/blank.test.php | 2 | ||||
-rw-r--r-- | tests/resources/Config/config.ini.php | 6 | ||||
-rw-r--r-- | tests/resources/Config/global.ini.php | 6 | ||||
-rw-r--r-- | tests/resources/referer-xss.txt (renamed from tests/datasets/referer-xss.txt) | 0 |
6 files changed, 81 insertions, 13 deletions
diff --git a/core/Config.php b/core/Config.php index 40aecb36d1..2bbb63f541 100644 --- a/core/Config.php +++ b/core/Config.php @@ -55,20 +55,24 @@ class Piwik_Config */ static public function getDefaultUserConfigPath() { - return 'config/config.ini.php'; + return Piwik_Common::getPathToPiwikRoot() . '/config/config.ini.php'; } + static public function getDefaultDefaultConfigPath() + { + return Piwik_Common::getPathToPiwikRoot() . '/config/global.ini.php'; + } + /** * Builds the Config object, given the optional path for the user INI file * If not specified, it will use the default path * * @param string $pathIniFileUserConfig */ - function __construct($pathIniFileUserConfig = null) + function __construct($pathIniFileUserConfig = null, $pathIniFileDefaultConfig = null) { Zend_Registry::set('config', $this); - $this->pathIniFileDefaultConfig = Piwik_Common::getPathToPiwikRoot().'/config/global.ini.php'; if(is_null($pathIniFileUserConfig)) { $this->pathIniFileUserConfig = self::getDefaultUserConfigPath(); @@ -78,6 +82,15 @@ class Piwik_Config $this->pathIniFileUserConfig = $pathIniFileUserConfig; } + if(is_null($pathIniFileDefaultConfig)) + { + $this->pathIniFileDefaultConfig = self::getDefaultDefaultConfigPath(); + } + else + { + $this->pathIniFileDefaultConfig = $pathIniFileDefaultConfig; + } + $this->defaultConfig = new Zend_Config_Ini($this->pathIniFileDefaultConfig, null, true); if(!Zend_Loader::isReadable($this->pathIniFileUserConfig)) @@ -206,18 +219,21 @@ class Piwik_Config */ public function __get($name) { - if( !is_null($this->userConfig) - && null !== ($valueInUserConfig = $this->userConfig->$name)) + $value = array(); + if(null !== ($valueInDefaultConfig = $this->defaultConfig->$name)) { - return $valueInUserConfig; + $value = array_merge($value, $valueInDefaultConfig->toArray()); } - if(null !== ($valueInDefaultConfig = $this->defaultConfig->$name)) + if( !is_null($this->userConfig) + && null !== ($valueInUserConfig = $this->userConfig->$name)) { - return $valueInDefaultConfig; + $value = array_merge($value, $valueInUserConfig->toArray()); } - throw new Exception("The configuration parameter $name couldn't be found in your configuration file. - <br>Try to replace your default configuration file ({$this->pathIniFileDefaultConfig}) with - the <a href='".$this->urlToPiwikHelpMissingValueInConfigurationFile."'>default piwik configuration file</a> "); + return new Zend_Config($value); + +// throw new Exception("The configuration parameter $name couldn't be found in your configuration file. +// <br>Try to replace your default configuration file ({$this->pathIniFileDefaultConfig}) with +// the <a href='".$this->urlToPiwikHelpMissingValueInConfigurationFile."'>default piwik configuration file</a> "); } } diff --git a/tests/core/Config.test.php b/tests/core/Config.test.php new file mode 100644 index 0000000000..dac5ad3e4b --- /dev/null +++ b/tests/core/Config.test.php @@ -0,0 +1,42 @@ +<?php +if(!defined("PATH_TEST_TO_ROOT")) { + define('PATH_TEST_TO_ROOT', getcwd().'/../..'); +} +if(!defined('CONFIG_TEST_INCLUDED')) +{ + require_once PATH_TEST_TO_ROOT . "/tests/config_test.php"; +} + +class Test_Piwik_Blank extends UnitTestCase +{ + function __construct( $title = '') + { + parent::__construct( $title ); + } + + public function setUp() + { + } + + public function tearDown() + { + } + + + /** + * -> exception + */ + public function testUserConfigOverwritesSectionGlobalConfigValue() + { + $userFile = 'tests/resources/Config/config.ini.php'; + $globalFile = 'tests/resources/Config/global.ini.php'; + + $config = new Piwik_Config($userFile, $globalFile); + + $this->assertEqual($config->Category->key1, "value_overwritten"); + $this->assertEqual($config->Category->key2, "value2"); + $this->assertEqual($config->General->login, "test"); + $this->assertEqual($config->CategoryOnlyInGlobalFile->key3, "value3"); + } +} + diff --git a/tests/core/blank.test.php b/tests/core/blank.test.php index b6c852d9d5..a873cc98bf 100755 --- a/tests/core/blank.test.php +++ b/tests/core/blank.test.php @@ -7,8 +7,6 @@ if(!defined('CONFIG_TEST_INCLUDED')) require_once PATH_TEST_TO_ROOT . "/tests/config_test.php"; } -//Zend_Loader::loadClass('Piwik_'); - class Test_Piwik_Blank extends UnitTestCase { function __construct( $title = '') diff --git a/tests/resources/Config/config.ini.php b/tests/resources/Config/config.ini.php new file mode 100644 index 0000000000..8b99401fb9 --- /dev/null +++ b/tests/resources/Config/config.ini.php @@ -0,0 +1,6 @@ +[General] +login=test +password=test + +[Category] +key1 = value_overwritten
\ No newline at end of file diff --git a/tests/resources/Config/global.ini.php b/tests/resources/Config/global.ini.php new file mode 100644 index 0000000000..05bd172203 --- /dev/null +++ b/tests/resources/Config/global.ini.php @@ -0,0 +1,6 @@ +[Category] +key1 = value1 +key2 = value2 + +[CategoryOnlyInGlobalFile] +key3 = value3
\ No newline at end of file diff --git a/tests/datasets/referer-xss.txt b/tests/resources/referer-xss.txt index b396c04813..b396c04813 100644 --- a/tests/datasets/referer-xss.txt +++ b/tests/resources/referer-xss.txt |