Skip to content
Extraits de code Groupes Projets
TestingEnvironmentVariables.php 2,65 ko
Newer Older
  • Learn to ignore specific revisions
  • <?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__ . '/../../..';
    
    
    ThaDafinser's avatar
    ThaDafinser a validé
            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);
            }
        }