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
46
47
48
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
<?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\Fixtures;
use Piwik\Date;
use Piwik\Access;
use Piwik\Option;
use ReflectionClass;
use Piwik\Plugins\VisitsSummary\API as VisitsSummaryAPI;
/**
* This fixture is the combination of every other fixture defined by Piwik. Should be used
* with year periods.
*/
class OmniFixture extends \Fixture
{
public $month = '2012-01';
public $idSite = 'all';
public $dateTime = '2012-02-01';
public $now = null;
public $segment = "browserCode==FF";
// Visitor profile screenshot test needs visitor id
public $visitorIdDeterministic = null;
public $fixtures = array();
/**
* Constructor.
*/
public function __construct()
{
$date = $this->month . '-01';
$classes = get_declared_classes();
sort($classes);
foreach ($classes as $className) {
if (is_subclass_of($className, 'Fixture')
&& !is_subclass_of($className, __CLASS__)
&& $className != __CLASS__
&& $className != "Piwik_Test_Fixture_SqlDump"
&& $className != "Piwik\\Tests\\Fixtures\\UpdaterTestFixture"
&& $className != "Piwik\\Tests\\Fixtures\\UITestFixture"
) {
$klassReflect = new ReflectionClass($className);
if (!strpos($klassReflect->getFilename(), "tests/PHPUnit/Fixtures")
&& $className != "Test_Piwik_Fixture_CustomAlerts"
&& $className != "Piwik\\Plugins\\Insights\\tests\\Fixtures\\SomeVisitsDifferentPathsOnTwoDays"
) {
continue;
}
$fixture = new $className();
if (!property_exists($fixture, 'dateTime')) {
continue;
}
$fixture->dateTime = $this->adjustDateTime($fixture->dateTime, $date);
$this->fixtures[$className] = $fixture;
$date = Date::factory($date)->addDay(1)->toString();
}
}
$this->now = $this->fixtures['Test_Piwik_Fixture_ManySitesImportedLogsWithXssAttempts']->now;
// make sure Test_Piwik_Fixture_ManySitesImportedLogsWithXssAttempts is the first fixture
$fixture = $this->fixtures['Test_Piwik_Fixture_ManySitesImportedLogsWithXssAttempts'];
unset($this->fixtures['Test_Piwik_Fixture_ManySitesImportedLogsWithXssAttempts']);
$this->fixtures = array_merge(array('Test_Piwik_Fixture_ManySitesImportedLogsWithXssAttempts' => $fixture), $this->fixtures);
}
private function adjustDateTime($dateTime, $adjustToDate)
{
$parts = explode(' ', $dateTime);
$result = $adjustToDate . ' ';
$result .= isset($parts[1]) ? $parts[1] : '11:22:33';
return $result;
}
public function setUp()
{
foreach ($this->fixtures as $name => $fixture) {
$fixture->setUp();
}
Option::set("Tests.forcedNowTimestamp", $this->now->getTimestamp());
// launch archiving so tests don't run out of time
$date = Date::factory($this->dateTime)->toString();
VisitsSummaryAPI::getInstance()->get($this->idSite, 'year', $date);
VisitsSummaryAPI::getInstance()->get($this->idSite, 'year', $date, urlencode($this->segment));
}
public function tearDown()
{
foreach ($this->fixtures as $fixture) {
$fixture->tearDown();
}
}
public static function createAccessInstance()
{
Access::setSingletonInstance($access = new \Test_Access_OverrideLogin());
\Piwik\Piwik::postEvent('Request.initAuthenticationObject');
}
}
|