diff options
author | diosmosis <benaka@piwik.pro> | 2015-05-21 04:59:25 +0300 |
---|---|---|
committer | diosmosis <benaka@piwik.pro> | 2015-05-22 23:34:38 +0300 |
commit | b258ba71026fb3bce7e7410ef00f5d9cc93cda20 (patch) | |
tree | 2b6753d7692ac915ccc0626db778e1eb695a90e4 /tests/PHPUnit/Framework/Mock | |
parent | da15f597d67e29f1ef6d369d802c8eeb31ac74ee (diff) |
Move Config::setTestEnvironment() to TestConfig. This will require changing some non-pro plugins when merged (LoginLdap only I think).
Diffstat (limited to 'tests/PHPUnit/Framework/Mock')
-rw-r--r-- | tests/PHPUnit/Framework/Mock/TestConfig.php | 52 |
1 files changed, 31 insertions, 21 deletions
diff --git a/tests/PHPUnit/Framework/Mock/TestConfig.php b/tests/PHPUnit/Framework/Mock/TestConfig.php index 30ba74c3a6..ef8ad61a18 100644 --- a/tests/PHPUnit/Framework/Mock/TestConfig.php +++ b/tests/PHPUnit/Framework/Mock/TestConfig.php @@ -13,7 +13,6 @@ use Piwik\Config; class TestConfig extends Config { private $allowSave = false; - private $isSettingTestEnv = false; private $doSetTestEnvironment = false; public function __construct($pathGlobal = null, $pathLocal = null, $pathCommon = null, $allowSave = false, $doSetTestEnvironment = true) @@ -33,35 +32,46 @@ class TestConfig extends Config public function reload($pathLocal = null, $pathGlobal = null, $pathCommon = null) { - if ($this->isSettingTestEnv) { - parent::reload($pathGlobal, $pathLocal, $pathCommon); - } else { - $this->isSettingTestEnv = true; - $this->setTestEnvironment($pathLocal, $pathGlobal, $pathCommon, $this->allowSave); - $this->isSettingTestEnv = false; + parent::reload($pathGlobal, $pathLocal, $pathCommon); + + $this->setTestEnvironment(); + } + + public function forceSave() + { + if ($this->allowSave) { + parent::forceSave(); } } - public function setTestEnvironment($pathLocal = null, $pathGlobal = null, $pathCommon = null, $allowSaving = false) + public function setTestEnvironment() { - if ($this->doSetTestEnvironment) { - parent::setTestEnvironment($pathLocal, $pathGlobal, $pathCommon, $allowSaving); - } else { - $this->doNotWriteConfigInTests = !$allowSaving; + if (!$this->allowSave) { + $this->doNotWriteConfigInTests = true; + } - $this->pathLocal = $pathLocal ?: Config::getLocalConfigPath(); - $this->pathGlobal = $pathGlobal ?: Config::getGlobalConfigPath(); - $this->pathCommon = $pathCommon ?: Config::getCommonConfigPath(); + $chain = $this->settings->getIniFileChain(); - $this->reload(); + $databaseTestsSettings = $chain->get('database_tests'); // has to be __get otherwise when called from TestConfig, PHP will issue a NOTICE + if (!empty($databaseTestsSettings)) { + $chain->set('database', $databaseTestsSettings); } - } - public function forceSave() - { - if ($this->allowSave) { - parent::forceSave(); + // Ensure local mods do not affect tests + if (empty($pathGlobal)) { + $chain->set('Debug', $chain->getFrom($this->getGlobalPath(), 'Debug')); + $chain->set('mail', $chain->getFrom($this->getGlobalPath(), 'mail')); + $chain->set('General', $chain->getFrom($this->getGlobalPath(), 'General')); + $chain->set('Segments', $chain->getFrom($this->getGlobalPath(), 'Segments')); + $chain->set('Tracker', $chain->getFrom($this->getGlobalPath(), 'Tracker')); + $chain->set('Deletelogs', $chain->getFrom($this->getGlobalPath(), 'Deletelogs')); + $chain->set('Deletereports', $chain->getFrom($this->getGlobalPath(), 'Deletereports')); + $chain->set('Development', $chain->getFrom($this->getGlobalPath(), 'Development')); } + + // for unit tests, we set that no plugin is installed. This will force + // the test initialization to create the plugins tables, execute ALTER queries, etc. + $chain->set('PluginsInstalled', array('PluginsInstalled' => array())); } private function setFromTestEnvironment(\Piwik_TestingEnvironment $testingEnvironment) |