Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/Config.php215
-rw-r--r--core/Config/Compat.php2
-rw-r--r--core/Config/Writer.php228
-rw-r--r--core/PluginsManager.php18
-rw-r--r--core/Updates/0.5.4.php8
-rw-r--r--core/Updates/0.6.3.php4
-rw-r--r--plugins/CoreAdminHome/Controller.php4
-rw-r--r--plugins/Installation/Controller.php4
-rw-r--r--plugins/Login/Controller.php2
-rw-r--r--plugins/PrivacyManager/Controller.php8
-rw-r--r--plugins/UsersManager/Controller.php2
-rw-r--r--tests/core/Config.test.php94
-rw-r--r--tests/core/Config/Writer.test.php107
13 files changed, 320 insertions, 376 deletions
diff --git a/core/Config.php b/core/Config.php
index c5ea4d5245..4f9fdeac32 100644
--- a/core/Config.php
+++ b/core/Config.php
@@ -25,7 +25,16 @@
*
* will read the value minimum_memory_limit under the [General] section of the config file.
*
- * Note: if you want to save your changes, you have to use Piwik_Config_Writer
+ * Example setting a section in the configuration:
+ *
+ * $brandingConfig = array(
+ * 'use_custom_logo' => 1,
+ * );
+ * Piwik_Config::getInstance()->setConfigSection('branding', $brandingConfig);
+ *
+ * Example setting an option within a section in the configuration:
+ *
+ * Piwik_Config::getInstance()->setConfigOption('branding', 'use_custom_logo', '1');
*
* @package Piwik
* @subpackage Piwik_Config
@@ -49,6 +58,29 @@ class Piwik_Config
}
/**
+ * Contains configuration files values
+ *
+ * @var array
+ */
+ protected $initialized = false;
+ protected $configGlobal = array();
+ protected $configLocal = array();
+ protected $configCache = array();
+ protected $pathGlobal = null;
+ protected $pathLocal = null;
+
+ protected function __construct()
+ {
+ $this->pathGlobal = self::getGlobalConfigPath();
+ $this->pathLocal = self::getLocalConfigPath();
+ }
+
+ /**
+ * @var boolean
+ */
+ protected $isTest = false;
+
+ /**
* Enable test environment
*
* @param string $pathLocal
@@ -56,6 +88,8 @@ class Piwik_Config
*/
public function setTestEnvironment($pathLocal = null, $pathGlobal = null)
{
+ $this->isTest = true;
+
$this->clear();
if ($pathLocal)
@@ -82,24 +116,6 @@ class Piwik_Config
}
/**
- * Contains configuration files values
- *
- * @var array
- */
- protected $initialized = false;
- protected $configGlobal = array();
- protected $configLocal = array();
- protected $configCache = array();
- protected $pathGlobal = null;
- protected $pathLocal = null;
-
- protected function __construct()
- {
- $this->pathGlobal = self::getGlobalConfigPath();
- $this->pathLocal = self::getLocalConfigPath();
- }
-
- /**
* Returns absolute path to the global configuration file
*
* @return string
@@ -212,6 +228,28 @@ class Piwik_Config
}
/**
+ * Encode HTML entities
+ *
+ * @param mixed $values
+ * @return mixed
+ */
+ protected function encodeValues($values)
+ {
+ if(is_array($values))
+ {
+ foreach($values as &$value)
+ {
+ $value = $this->encodeValues($value);
+ }
+ }
+ else
+ {
+ $values = htmlentities($values, ENT_COMPAT);
+ }
+ return $values;
+ }
+
+ /**
* Magic get methods catching calls to $config->var_name
* Returns the value if found in the configuration
*
@@ -269,4 +307,143 @@ class Piwik_Config
{
$this->configCache[$name] = $value;
}
+
+ /**
+ * Comparison function
+ *
+ * @param mixed $elem1
+ * @param mixed $elem2
+ * @return int;
+ */
+ static function compareElements($elem1, $elem2)
+ {
+ if (is_array($elem1)) {
+ if (is_array($elem2))
+ {
+ return strcmp(serialize($elem1), serialize($elem2));
+ }
+ return 1;
+ }
+ if (is_array($elem2))
+ return -1;
+
+ if ((string)$elem1 === (string)$elem2)
+ return 0;
+
+ return ((string)$elem1 > (string)$elem2) ? 1 : -1;
+ }
+
+ /**
+ * Compare arrays and return difference, such that:
+ *
+ * $modified = array_merge($original, $difference);
+ *
+ * @param array $original original array
+ * @param array $modified modified array
+ * @return array differences between original and modified
+ */
+ public function array_unmerge($original, $modified)
+ {
+ // return key/value pairs for keys in $modified but not in $original
+ // return key/value pairs for keys in both $modified and $original, but values differ
+ // ignore keys that are in $original but not in $modified
+
+ return array_udiff_assoc($modified, $original, array(__CLASS__, 'compareElements'));
+ }
+
+ /**
+ * Write user configuration file
+ *
+ * @param array $configLocal
+ * @param array $configGlobal
+ * @param array $configCache
+ * @param string $pathLocal
+ */
+ public function writeConfig($configLocal, $configGlobal, $configCache, $pathLocal)
+ {
+ if ($this->isTest)
+ {
+ return;
+ }
+
+ $dirty = false;
+
+ $output = "; <?php exit; ?> DO NOT REMOVE THIS LINE\n";
+ $output .= "; file automatically generated or modified by Piwik; you can manually override the default values in global.ini.php by redefining them in this file.\n";
+
+ if ($configCache)
+ {
+ foreach($configLocal as $name => $section)
+ {
+ if (!isset($configCache[$name]))
+ {
+ $configCache[$name] = $this->decodeValues($section);
+ }
+ }
+
+ foreach($configCache as $name => $section)
+ {
+ $configLocal = $this->array_unmerge($configGlobal[$name], $configCache[$name]);
+ if (count($configLocal) == 0)
+ {
+ continue;
+ }
+
+ $dirty = true;
+
+ $output .= "[$name]\n";
+
+ foreach($configLocal as $name => $value)
+ {
+ $value = $this->encodeValues($value);
+
+ if(is_numeric($name))
+ {
+ $name = $section;
+ $value = array($value);
+ }
+
+ if(is_array($value))
+ {
+ foreach($value as $currentValue)
+ {
+ $output .= $name."[] = \"$currentValue\"\n";
+ }
+ }
+ else
+ {
+ if(!is_numeric($value))
+ {
+ $value = "\"$value\"";
+ }
+ $output .= $name.' = '.$value."\n";
+ }
+ }
+ $output .= "\n";
+ }
+
+ if ($dirty)
+ {
+ @file_put_contents($pathLocal, $output );
+ }
+ }
+
+ $this->clear();
+ }
+
+ /**
+ * Force save
+ */
+ public function forceSave()
+ {
+ $this->writeConfig($this->configLocal, $this->configGlobal, $this->configCache, $this->pathLocal);
+ }
+
+ /**
+ * At the script shutdown, we save the new configuration file, if the user has set some values
+ */
+ public function __destruct()
+ {
+ $this->forceSave();
+ }
}
diff --git a/core/Config/Compat.php b/core/Config/Compat.php
index ff8495a154..742a763412 100644
--- a/core/Config/Compat.php
+++ b/core/Config/Compat.php
@@ -85,7 +85,7 @@ class Piwik_Config_Compat
*/
public function __construct()
{
- $this->config = Piwik_Config_Writer::getInstance();
+ $this->config = Piwik_Config::getInstance();
$this->data = array();
$this->enabled = true;
}
diff --git a/core/Config/Writer.php b/core/Config/Writer.php
deleted file mode 100644
index b605ecdeb2..0000000000
--- a/core/Config/Writer.php
+++ /dev/null
@@ -1,228 +0,0 @@
-<?php
-/**
- * Piwik - Open source web analytics
- *
- * @link http://piwik.org
- * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
- * @version $Id$
- *
- * @category Piwik
- * @package Piwik
- */
-
-/**
- * This class extends the base Piwik_Config class to save in-memory changes to the local
- * configuration file.
- *
- * Example reading a value from the configuration:
- *
- * $minValue = Piwik_Config_Writer::getInstance()->General['minimum_memory_limit'];
- *
- * will read the value minimum_memory_limit under the [General] section of the config file.
- *
- * Example setting a section in the configuration:
- *
- * $brandingConfig = array(
- * 'use_custom_logo' => 1,
- * );
- * Piwik_Config_Writer::getInstance()->setConfigSection('branding', $brandingConfig);
- *
- * Example setting an option within a section in the configuration:
- *
- * Piwik_Config_Writer::getInstance()->setConfigOption('branding', 'use_custom_logo', '1');
- *
- * @package Piwik
- * @subpackage Piwik_Config
- */
-class Piwik_Config_Writer extends Piwik_Config
-{
- static private $instance = null;
-
- /**
- * Returns the singleton Piwik_Config
- *
- * @return Piwik_Config
- */
- static public function getInstance()
- {
- if (self::$instance == null)
- {
- self::$instance = new self;
- }
- return self::$instance;
- }
-
- /**
- * Read configuration files into memory
- *
- * @throws Exception if file is not read/writable or contains no configuration
- */
- public function init()
- {
- Piwik::checkDirectoriesWritableOrDie( array('/config/') );
-
- if(file_exists($this->pathLocal)
- && !is_writable($this->pathLocal))
- {
- throw new Exception(Piwik_TranslateException('General_ExceptionUnwritableFileDisabledMethod', array($this->pathLocal)));
- }
-
- parent::init();
- }
-
- /**
- * Comparison function
- *
- * @param mixed $elem1
- * @param mixed $elem2
- * @return int;
- */
- static function compareElements($elem1, $elem2)
- {
- if (is_array($elem1)) {
- if (is_array($elem2))
- {
- return strcmp(serialize($elem1), serialize($elem2));
- }
- return 1;
- }
- if (is_array($elem2))
- return -1;
-
- if ((string)$elem1 === (string)$elem2)
- return 0;
-
- return ((string)$elem1 > (string)$elem2) ? 1 : -1;
- }
-
- /**
- * Compare arrays and return difference, such that:
- *
- * $modified = array_merge($original, $difference);
- *
- * @param array $original original array
- * @param array $modified modified array
- * @return array differences between original and modified
- */
- public function array_unmerge($original, $modified)
- {
- // return key/value pairs for keys in $modified but not in $original
- // return key/value pairs for keys in both $modified and $original, but values differ
- // ignore keys that are in $original but not in $modified
-
- return array_udiff_assoc($modified, $original, array(__CLASS__, 'compareElements'));
- }
-
- /**
- * Encode HTML entities
- *
- * @param mixed $values
- * @return mixed
- */
- protected function encodeValues($values)
- {
- if(is_array($values))
- {
- foreach($values as &$value)
- {
- $value = $this->encodeValues($value);
- }
- }
- else
- {
- $values = htmlentities($values, ENT_COMPAT);
- }
- return $values;
- }
-
- /**
- * Write user configuration file
- *
- * @param array $configLocal
- * @param array $configGlobal
- * @param array $configCache
- * @param string $pathLocal
- */
- public function writeConfig($configLocal, $configGlobal, $configCache, $pathLocal)
- {
- $dirty = false;
-
- $output = "; <?php exit; ?> DO NOT REMOVE THIS LINE\n";
- $output .= "; file automatically generated or modified by Piwik; you can manually override the default values in global.ini.php by redefining them in this file.\n";
-
- if ($configCache)
- {
- foreach($configLocal as $name => $section)
- {
- if (!isset($configCache[$name]))
- {
- $configCache[$name] = $this->decodeValues($section);
- }
- }
-
- foreach($configCache as $name => $section)
- {
- $configLocal = $this->array_unmerge($configGlobal[$name], $configCache[$name]);
- if (count($configLocal) == 0)
- {
- continue;
- }
-
- $dirty = true;
-
- $output .= "[$name]\n";
-
- foreach($configLocal as $name => $value)
- {
- $value = $this->encodeValues($value);
-
- if(is_numeric($name))
- {
- $name = $section;
- $value = array($value);
- }
-
- if(is_array($value))
- {
- foreach($value as $currentValue)
- {
- $output .= $name."[] = \"$currentValue\"\n";
- }
- }
- else
- {
- if(!is_numeric($value))
- {
- $value = "\"$value\"";
- }
- $output .= $name.' = '.$value."\n";
- }
- }
- $output .= "\n";
- }
-
- if ($dirty)
- {
- @file_put_contents($pathLocal, $output );
- }
- }
-
- $this->clear();
- }
-
- /**
- * Force save
- */
- public function forceSave()
- {
- $this->writeConfig($this->configLocal, $this->configGlobal, $this->configCache, $this->pathLocal);
- }
-
- /**
- * At the script shutdown, we save the new configuration file, if the user has set some values
- */
- public function __destruct()
- {
- $this->forceSave();
- }
-}
diff --git a/core/PluginsManager.php b/core/PluginsManager.php
index f9b5c036b1..43c356d78a 100644
--- a/core/PluginsManager.php
+++ b/core/PluginsManager.php
@@ -131,7 +131,7 @@ class Piwik_PluginsManager
*/
public function deactivatePlugin($pluginName)
{
- $configWriter = Piwik_Config_Writer::getInstance();
+ $configWriter = Piwik_Config::getInstance();
$plugins = $this->pluginsToLoad;
$key = array_search($pluginName, $plugins);
@@ -196,10 +196,18 @@ class Piwik_PluginsManager
$this->installPluginIfNecessary($plugin);
// we add the plugin to the list of activated plugins
- $plugins[] = $pluginName;
+ if(!in_array($pluginName, $plugins))
+ {
+ $plugins[] = $pluginName;
+ }
+ else
+ {
+ // clean up if we find a dupe
+ $plugins = array_unique($plugins);
+ }
// the config file will automatically be saved with the new plugin
- $configWriter = Piwik_Config_Writer::getInstance();
+ $configWriter = Piwik_Config::getInstance();
$configWriter->Plugins['Plugins'] = $plugins;
// Delete merged js/css files to force regenerations to include the activated plugin
@@ -549,7 +557,7 @@ class Piwik_PluginsManager
{
$this->installPlugin($plugin);
$pluginsInstalled[] = $pluginName;
- $configWriter = Piwik_Config_Writer::getInstance();
+ $configWriter = Piwik_Config::getInstance();
$configWriter->PluginsInstalled['PluginsInstalled'] = $pluginsInstalled;
}
@@ -567,7 +575,7 @@ class Piwik_PluginsManager
if(!in_array($pluginName, $pluginsTracker))
{
$pluginsTracker[] = $pluginName;
- $configWriter = Piwik_Config_Writer::getInstance();
+ $configWriter = Piwik_Config::getInstance();
$configWriter->Plugins_Tracker['Plugins_Tracker'] = $pluginsTracker;
}
}
diff --git a/core/Updates/0.5.4.php b/core/Updates/0.5.4.php
index d00f4f1d90..e40a326d88 100644
--- a/core/Updates/0.5.4.php
+++ b/core/Updates/0.5.4.php
@@ -25,12 +25,12 @@ class Piwik_Updates_0_5_4 extends Piwik_Updates
static function update()
{
- $config = Piwik_Config_Writer::getInstance();
+ $config = Piwik_Config::getInstance();
$salt = Piwik_Common::generateUniqId();
if(!isset($config->superuser['salt']))
{
try {
- if(is_writable( Piwik_Config_Writer::getLocalConfigPath() ))
+ if(is_writable( Piwik_Config::getLocalConfigPath() ))
{
$config->setConfigOption('superuser', 'salt', $salt);
$config->__destruct();
@@ -45,12 +45,12 @@ class Piwik_Updates_0_5_4 extends Piwik_Updates
}
}
- $config = Piwik_Config_Writer::getInstance();
+ $config = Piwik_Config::getInstance();
$plugins = $config->Plugins;
if(!in_array('MultiSites', $plugins))
{
try {
- if(is_writable( Piwik_Config_Writer::getLocalConfigPath() ))
+ if(is_writable( Piwik_Config::getLocalConfigPath() ))
{
$plugins[] = 'MultiSites';
$config->setConfigSection('Plugins', $plugins);
diff --git a/core/Updates/0.6.3.php b/core/Updates/0.6.3.php
index 2610365602..e0c94747a2 100644
--- a/core/Updates/0.6.3.php
+++ b/core/Updates/0.6.3.php
@@ -27,12 +27,12 @@ class Piwik_Updates_0_6_3 extends Piwik_Updates
static function update()
{
- $config = Piwik_Config_Writer::getInstance();
+ $config = Piwik_Config::getInstance();
$dbInfos = $config->database;
if(!isset($dbInfos['schema']))
{
try {
- if(is_writable( Piwik_Config_Writer::getLocalConfigPath() ))
+ if(is_writable( Piwik_Config::getLocalConfigPath() ))
{
$config->setConfigOption('database', 'schema', 'Myisam');
$config->__destruct();
diff --git a/plugins/CoreAdminHome/Controller.php b/plugins/CoreAdminHome/Controller.php
index b2a354b4a8..834e37ff0c 100644
--- a/plugins/CoreAdminHome/Controller.php
+++ b/plugins/CoreAdminHome/Controller.php
@@ -84,10 +84,10 @@ class Piwik_CoreAdminHome_Controller extends Piwik_Controller_Admin
$mail['username'] = Piwik_Common::unsanitizeInputValue(Piwik_Common::getRequestVar('mailUsername', ''));
$mail['password'] = Piwik_Common::unsanitizeInputValue(Piwik_Common::getRequestVar('mailPassword', ''));
$mail['encryption'] = Piwik_Common::getRequestVar('mailEncryption', '');
- Piwik_Config_Writer::getInstance()->mail = $mail;
+ Piwik_Config::getInstance()->mail = $mail;
// update branding settings
- Piwik_Config_Writer::getInstance()->branding['use_custom_logo'] = Piwik_Common::getRequestVar('useCustomLogo', '0');
+ Piwik_Config::getInstance()->branding['use_custom_logo'] = Piwik_Common::getRequestVar('useCustomLogo', '0');
$toReturn = $response->getResponse();
} catch(Exception $e ) {
diff --git a/plugins/Installation/Controller.php b/plugins/Installation/Controller.php
index 4da8bed3f8..2a2f7fb96e 100644
--- a/plugins/Installation/Controller.php
+++ b/plugins/Installation/Controller.php
@@ -74,7 +74,7 @@ class Piwik_Installation_Controller extends Piwik_Controller
{
// Delete merged js/css files to force regenerations based on updated activated plugin list
Piwik::deleteAllCacheOnUpdate();
-
+
$view = new Piwik_Installation_View(
$this->pathView . 'welcome.tpl',
$this->getInstallationSteps(),
@@ -566,7 +566,7 @@ class Piwik_Installation_Controller extends Piwik_Controller
return;
}
- $config = Piwik_Config_Writer::getInstance();
+ $config = Piwik_Config::getInstance();
try {
// expect exception since config.ini.php doesn't exist yet
$config->init();
diff --git a/plugins/Login/Controller.php b/plugins/Login/Controller.php
index a727519779..6ce7fef930 100644
--- a/plugins/Login/Controller.php
+++ b/plugins/Login/Controller.php
@@ -324,7 +324,7 @@ class Piwik_Login_Controller extends Piwik_Controller
}
$user['password'] = md5($password);
- Piwik_Config_Writer::getInstance()->superuser = $user;
+ Piwik_Config::getInstance()->superuser = $user;
}
else
{
diff --git a/plugins/PrivacyManager/Controller.php b/plugins/PrivacyManager/Controller.php
index c45b208f58..b83826a8f4 100644
--- a/plugins/PrivacyManager/Controller.php
+++ b/plugins/PrivacyManager/Controller.php
@@ -29,20 +29,20 @@ class Piwik_PrivacyManager_Controller extends Piwik_Controller_Admin
{
case("formMaskLength"):
$this->handlePluginState(Piwik_Common::getRequestVar("anonymizeIPEnable", 0));
- $trackerConfig = Piwik_Config_Writer::getInstance()->Tracker;
+ $trackerConfig = Piwik_Config::getInstance()->Tracker;
$trackerConfig['ip_address_mask_length'] = Piwik_Common::getRequestVar("maskLength", 1);
- Piwik_Config_Writer::getInstance()->Tracker = $trackerConfig;
+ Piwik_Config::getInstance()->Tracker = $trackerConfig;
break;
case("formDeleteSettings"):
- $deleteLogs = Piwik_Config_Writer::getInstance()->Deletelogs;
+ $deleteLogs = Piwik_Config::getInstance()->Deletelogs;
$deleteLogs['delete_logs_enable'] = Piwik_Common::getRequestVar("deleteEnable", 0);
$deleteLogs['delete_logs_schedule_lowest_interval'] = Piwik_Common::getRequestVar("deleteLowestInterval", 7);
$deleteLogs['delete_logs_older_than'] = ((int)Piwik_Common::getRequestVar("deleteOlderThan", 180) < 7) ?
7 : Piwik_Common::getRequestVar("deleteOlderThan", 180);
$deleteLogs['delete_max_rows_per_run'] = Piwik_Common::getRequestVar("deleteMaxRows", 100);
- Piwik_Config_Writer::getInstance()->Deletelogs = $deleteLogs;
+ Piwik_Config::getInstance()->Deletelogs = $deleteLogs;
break;
default: //do nothing
diff --git a/plugins/UsersManager/Controller.php b/plugins/UsersManager/Controller.php
index e7e5a7ca4a..106ed4be9c 100644
--- a/plugins/UsersManager/Controller.php
+++ b/plugins/UsersManager/Controller.php
@@ -277,7 +277,7 @@ class Piwik_UsersManager_Controller extends Piwik_Controller_Admin
$userLogin = Piwik::getCurrentUserLogin();
if(Piwik::isUserIsSuperUser())
{
- $config = Piwik_Config_Writer::getInstance();
+ $config = Piwik_Config::getInstance();
$superUser = $config->superuser;
$updatedSuperUser = false;
diff --git a/tests/core/Config.test.php b/tests/core/Config.test.php
index 2f19ea6659..452cf1e98b 100644
--- a/tests/core/Config.test.php
+++ b/tests/core/Config.test.php
@@ -81,4 +81,98 @@ class Test_Piwik_Config extends UnitTestCase
Piwik_Config::getInstance()->clear();
}
+
+ public function test_compareElements()
+ {
+ $tests = array(
+ 'string = string' => array(
+ 'a', 'a', 0,
+ ),
+ 'string > string' => array(
+ 'b', 'a', 1,
+ ),
+ 'string < string' => array(
+ 'a', 'b', -1,
+ ),
+ 'string vs array' => array(
+ 'a', array('a'), -1,
+ ),
+ 'array vs string' => array(
+ array('a'), 'a', 1,
+ ),
+ 'array = array' => array(
+ array('a'), array('a'), 0,
+ ),
+ 'array > array' => array(
+ array('b'), array('a'), 1,
+ ),
+ 'array < array' => array(
+ array('a'), array('b'), -1,
+ ),
+ );
+
+ foreach ($tests as $description => $test)
+ {
+ list($a, $b, $expected) = $test;
+
+ $result = Piwik_Config::compareElements($a, $b);
+ $this->assertEqual($result, $expected, $description);
+ }
+ }
+
+ public function test_array_unmerge()
+ {
+ $tests = array(
+ 'description of test' => array(
+ array(),
+ array(),
+ ),
+ 'override with empty' => array(
+ array('login' => 'root', 'password' => 'b33r'),
+ array('password' => ''),
+ ),
+ 'override with non-empty' => array(
+ array('login' => 'root', 'password' => ''),
+ array('password' => 'b33r'),
+ ),
+ 'add element' => array(
+ array('login' => 'root', 'password' => ''),
+ array('auth' => 'Login'),
+ ),
+ 'override with empty array' => array(
+ array('headers' => ''),
+ array('headers' => array()),
+ ),
+ 'override with array' => array(
+ array('headers' => ''),
+ array('headers' => array('Content-Length', 'Content-Type')),
+ ),
+ 'override an array' => array(
+ array('headers' => array()),
+ array('headers' => array('Content-Length', 'Content-Type')),
+ ),
+ 'override similar arrays' => array(
+ array('headers' => array('Content-Length', 'Set-Cookie')),
+ array('headers' => array('Content-Length', 'Content-Type')),
+ ),
+ 'override dyslexic arrays' => array(
+ array('headers' => array('Content-Type', 'Content-Length')),
+ array('headers' => array('Content-Length', 'Content-Type')),
+ ),
+ );
+
+ $configWriter = Piwik_Config::getInstance();
+
+ foreach ($tests as $description => $test)
+ {
+ list($a, $b) = $test;
+
+ $combined = array_merge($a, $b);
+
+ $diff = $configWriter->array_unmerge($a, $combined);
+
+ // expect $b == $diff
+ $this->assertEqual(serialize($b), serialize($diff), $description);
+ }
+ }
}
diff --git a/tests/core/Config/Writer.test.php b/tests/core/Config/Writer.test.php
deleted file mode 100644
index d7efecf19d..0000000000
--- a/tests/core/Config/Writer.test.php
+++ /dev/null
@@ -1,107 +0,0 @@
-<?php
-if(!defined('PIWIK_CONFIG_TEST_INCLUDED'))
-{
- require_once dirname(__FILE__)."/../../../tests/config_test.php";
-}
-
-class Test_Piwik_Config_Writer extends UnitTestCase
-{
- public function test_getInstance()
- {
- $this->assertEqual(get_class(Piwik_Config_Writer::getInstance()), 'Piwik_Config_Writer');
- }
-
- public function test_compareElements()
- {
- $tests = array(
- 'string = string' => array(
- 'a', 'a', 0,
- ),
- 'string > string' => array(
- 'b', 'a', 1,
- ),
- 'string < string' => array(
- 'a', 'b', -1,
- ),
- 'string vs array' => array(
- 'a', array('a'), -1,
- ),
- 'array vs string' => array(
- array('a'), 'a', 1,
- ),
- 'array = array' => array(
- array('a'), array('a'), 0,
- ),
- 'array > array' => array(
- array('b'), array('a'), 1,
- ),
- 'array < array' => array(
- array('a'), array('b'), -1,
- ),
- );
-
- foreach ($tests as $description => $test)
- {
- list($a, $b, $expected) = $test;
-
- $result = Piwik_Config_Writer::compareElements($a, $b);
- $this->assertEqual($result, $expected, $description);
- }
- }
-
- public function test_array_unmerge()
- {
- $tests = array(
- 'description of test' => array(
- array(),
- array(),
- ),
- 'override with empty' => array(
- array('login' => 'root', 'password' => 'b33r'),
- array('password' => ''),
- ),
- 'override with non-empty' => array(
- array('login' => 'root', 'password' => ''),
- array('password' => 'b33r'),
- ),
- 'add element' => array(
- array('login' => 'root', 'password' => ''),
- array('auth' => 'Login'),
- ),
- 'override with empty array' => array(
- array('headers' => ''),
- array('headers' => array()),
- ),
- 'override with array' => array(
- array('headers' => ''),
- array('headers' => array('Content-Length', 'Content-Type')),
- ),
- 'override an array' => array(
- array('headers' => array()),
- array('headers' => array('Content-Length', 'Content-Type')),
- ),
- 'override similar arrays' => array(
- array('headers' => array('Content-Length', 'Set-Cookie')),
- array('headers' => array('Content-Length', 'Content-Type')),
- ),
- 'override dyslexic arrays' => array(
- array('headers' => array('Content-Type', 'Content-Length')),
- array('headers' => array('Content-Length', 'Content-Type')),
- ),
- );
-
- $configWriter = Piwik_Config_Writer::getInstance();
-
- foreach ($tests as $description => $test)
- {
- list($a, $b) = $test;
-
- $combined = array_merge($a, $b);
-
- $diff = $configWriter->array_unmerge($a, $combined);
-
- // expect $b == $diff
- $this->assertEqual(serialize($b), serialize($diff), $description);
- }
- }
-}