diff --git a/tests/PHPUnit/Framework/TestingEnvironmentVariables.php b/tests/PHPUnit/Framework/TestingEnvironmentVariables.php index 923ac3915224a3f1aea1618d2cc861dec3791ff1..b2548837b3967dacc38161912da479fb880cfd70 100644 --- a/tests/PHPUnit/Framework/TestingEnvironmentVariables.php +++ b/tests/PHPUnit/Framework/TestingEnvironmentVariables.php @@ -1,93 +1,95 @@ -<?php -/** - * Piwik - free/libre analytics platform - * - * @link http://piwik.org - * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later - */ - -namespace Piwik\Tests\Framework; - -use Piwik\Plugin\Manager as PluginManager; - -/** - * Sets the test environment. - * - * For testing purposes, we don't want this class to reference PIWIK_INCLUDE_PATH or other constants. - */ -class TestingEnvironmentVariables -{ - private $behaviorOverrideProperties = array(); - - public function __construct() - { - $this->reload(); - } - - public function __get($key) - { - return isset($this->behaviorOverrideProperties[$key]) ? $this->behaviorOverrideProperties[$key] : null; - } - - public function __set($key, $value) - { - $this->behaviorOverrideProperties[$key] = $value; - } - - public function __isset($name) - { - return isset($this->behaviorOverrideProperties[$name]); - } - - public function save() - { - $includePath = __DIR__ . '/../../..'; - - @mkdir($includePath . '/tmp'); - - $overridePath = $includePath . '/tmp/testingPathOverride.json'; - file_put_contents($overridePath, json_encode($this->behaviorOverrideProperties)); - } - - public function delete() - { - $this->behaviorOverrideProperties = array(); - $this->save(); - } - - public function getCoreAndSupportedPlugins() - { - $settings = new \Piwik\Application\Kernel\GlobalSettingsProvider(); - $pluginList = new \Piwik\Application\Kernel\PluginList($settings); - $pluginManager = new PluginManager($pluginList); - - $disabledPlugins = $pluginList->getCorePluginsDisabledByDefault(); - $disabledPlugins[] = 'LoginHttpAuth'; - $disabledPlugins[] = 'ExampleVisualization'; - - $disabledPlugins = array_diff($disabledPlugins, array( - 'DBStats', 'ExampleUI', 'ExampleCommand', 'ExampleSettingsPlugin' - )); - - $plugins = array_filter($pluginManager->readPluginsDirectory(), function ($pluginName) use ($disabledPlugins, $pluginManager) { - if (in_array($pluginName, $disabledPlugins)) { - return false; - } - - return $pluginManager->isPluginBundledWithCore($pluginName) - || $pluginManager->isPluginOfficialAndNotBundledWithCore($pluginName); - }); - - sort($plugins); - - return $plugins; - } - - public function reload() - { - $overridePath = __DIR__ . '/../../../tmp/testingPathOverride.json'; - if (file_exists($overridePath)) { - $this->behaviorOverrideProperties = json_decode(file_get_contents($overridePath), true); - } - } +<?php +/** + * Piwik - free/libre analytics platform + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ + +namespace Piwik\Tests\Framework; + +use Piwik\Plugin\Manager as PluginManager; + +/** + * Sets the test environment. + * + * For testing purposes, we don't want this class to reference PIWIK_INCLUDE_PATH or other constants. + */ +class TestingEnvironmentVariables +{ + private $behaviorOverrideProperties = array(); + + public function __construct() + { + $this->reload(); + } + + public function __get($key) + { + return isset($this->behaviorOverrideProperties[$key]) ? $this->behaviorOverrideProperties[$key] : null; + } + + public function __set($key, $value) + { + $this->behaviorOverrideProperties[$key] = $value; + } + + public function __isset($name) + { + return isset($this->behaviorOverrideProperties[$name]); + } + + public function save() + { + $includePath = __DIR__ . '/../../..'; + + if(!file_exists($includePath . '/tmp')){ + mkdir($includePath . '/tmp'); + } + + $overridePath = $includePath . '/tmp/testingPathOverride.json'; + file_put_contents($overridePath, json_encode($this->behaviorOverrideProperties)); + } + + public function delete() + { + $this->behaviorOverrideProperties = array(); + $this->save(); + } + + public function getCoreAndSupportedPlugins() + { + $settings = new \Piwik\Application\Kernel\GlobalSettingsProvider(); + $pluginList = new \Piwik\Application\Kernel\PluginList($settings); + $pluginManager = new PluginManager($pluginList); + + $disabledPlugins = $pluginList->getCorePluginsDisabledByDefault(); + $disabledPlugins[] = 'LoginHttpAuth'; + $disabledPlugins[] = 'ExampleVisualization'; + + $disabledPlugins = array_diff($disabledPlugins, array( + 'DBStats', 'ExampleUI', 'ExampleCommand', 'ExampleSettingsPlugin' + )); + + $plugins = array_filter($pluginManager->readPluginsDirectory(), function ($pluginName) use ($disabledPlugins, $pluginManager) { + if (in_array($pluginName, $disabledPlugins)) { + return false; + } + + return $pluginManager->isPluginBundledWithCore($pluginName) + || $pluginManager->isPluginOfficialAndNotBundledWithCore($pluginName); + }); + + sort($plugins); + + return $plugins; + } + + public function reload() + { + $overridePath = __DIR__ . '/../../../tmp/testingPathOverride.json'; + if (file_exists($overridePath)) { + $this->behaviorOverrideProperties = json_decode(file_get_contents($overridePath), true); + } + } } \ No newline at end of file