Newer
Older
diosmosis
a validé
<?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\Application\EnvironmentManipulator;
use Piwik\Application\Kernel\GlobalSettingsProvider;
use Piwik\DbHelper;
use Piwik\Option;
diosmosis
a validé
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/**
* Manipulates an environment for tests.
*/
class TestingEnvironmentManipulator implements EnvironmentManipulator
{
/**
* @var TestingEnvironmentVariables
*/
private $vars;
private $globalObservers;
public function __construct(TestingEnvironmentVariables $testingEnvironment, array $globalObservers = array())
{
$this->vars = $testingEnvironment;
$this->globalObservers = $globalObservers;
}
public function makeGlobalSettingsProvider()
{
return new GlobalSettingsProvider($this->vars->configFileGlobal, $this->vars->configFileLocal, $this->vars->configFileCommon);
}
public function beforeContainerCreated()
{
if ($this->vars->queryParamOverride) {
foreach ($this->vars->queryParamOverride as $key => $value) {
$_GET[$key] = $value;
}
}
if ($this->vars->globalsOverride) {
foreach ($this->vars->globalsOverride as $key => $value) {
$GLOBALS[$key] = $value;
}
}
if ($this->vars->hostOverride) {
\Piwik\Url::setHost($this->vars->hostOverride);
}
if ($this->vars->useXhprof) {
\Piwik\Profiler::setupProfilerXHProf($mainRun = false, $setupDuringTracking = true);
}
\Piwik\Cache\Backend\File::$invalidateOpCacheBeforeRead = true;
}
public function onEnvironmentBootstrapped()
{
if (empty($_GET['ignoreClearAllViewDataTableParameters'])) { // TODO: should use testingEnvironment variable, not query param
try {
\Piwik\ViewDataTable\Manager::clearAllViewDataTableParameters();
} catch (\Exception $ex) {
// ignore (in case DB is not setup)
}
}
if ($this->vars->optionsOverride) {
try {
foreach ($this->vars->optionsOverride as $name => $value) {
Option::set($name, $value);
}
} catch (\Exception $ex) {
// ignore (in case DB is not setup)
}
}
\Piwik\Plugins\CoreVisualizations\Visualizations\Cloud::$debugDisableShuffle = true;
\Piwik\Visualization\Sparkline::$enableSparklineImages = false;
\Piwik\Plugins\ExampleUI\API::$disableRandomness = true;
if ($this->vars->deleteArchiveTables
&& !$this->vars->_archivingTablesDeleted
) {
$this->vars->_archivingTablesDeleted = true;
DbHelper::deleteArchiveTables();
}
}
diosmosis
a validé
public function getExtraDefinitions()
{
$testVarDefinitionSource = new TestingEnvironmentVariablesDefinitionSource($this->vars);
diosmosis
a validé
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// Apply DI config from the fixture
$diConfig = array();
if ($this->vars->fixtureClass) {
$fixtureClass = $this->vars->fixtureClass;
if (class_exists($fixtureClass)) {
/** @var Fixture $fixture */
$fixture = new $fixtureClass;
$diConfig = $fixture->provideContainerConfig();
}
}
if ($this->vars->testCaseClass) {
$testCaseClass = $this->vars->testCaseClass;
if (class_exists($testCaseClass)) {
$testCase = new $testCaseClass();
if (method_exists($testCase, 'provideContainerConfigBeforeClass')) {
$diConfig = array_merge($diConfig, $testCaseClass::provideContainerConfigBeforeClass());
}
if (method_exists($testCase, 'provideContainerConfig')) {
$diConfig = array_merge($diConfig, $testCase->provideContainerConfig());
}
}
}
return array(
$testVarDefinitionSource,
diosmosis
a validé
$diConfig,
array('observers.global' => \DI\add($this->globalObservers)),
diosmosis
a validé
);
}
public function getExtraEnvironments()
{
return array('test');
}