Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?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');
}
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
$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);
}
}