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
|
<?php
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
use Piwik\Access;
/**
* A fixture that adds two websites and annotations for each website.
*/
class Test_Piwik_Fixture_TwoSitesWithAnnotations extends Test_Piwik_BaseFixture
{
public $dateTime = '2011-01-01 00:11:42';
public $idSite1 = 1;
public $idSite2 = 2;
public function setUp()
{
$this->setUpWebsitesAndGoals();
$this->addAnnotations();
}
public function tearDown()
{
// empty
}
private function addAnnotations()
{
// create fake access for fake username
$access = new FakeAccess();
FakeAccess::$superUser = true;
Access::setSingletonInstance($access);
// add two annotations per week for three months, starring every third annotation
// first month in 2011, second two in 2012
$count = 0;
$dateStart = Piwik_Date::factory('2011-12-01');
$dateEnd = Piwik_Date::factory('2012-03-01');
while ($dateStart->getTimestamp() < $dateEnd->getTimestamp()) {
$starred = $count % 3 == 0 ? 1 : 0;
$site1Text = "$count: Site 1 annotation for " . $dateStart->toString();
$site2Text = "$count: Site 2 annotation for " . $dateStart->toString();
Piwik_Annotations_API::getInstance()->add($this->idSite1, $dateStart->toString(), $site1Text, $starred);
Piwik_Annotations_API::getInstance()->add($this->idSite2, $dateStart->toString(), $site2Text, $starred);
$nextDay = $dateStart->addDay(1);
++$count;
$starred = $count % 3 == 0 ? 1 : 0;
$site1Text = "$count: Site 1 annotation for " . $nextDay->toString();
$site2Text = "$count: Site 2 annotation for " . $nextDay->toString();
Piwik_Annotations_API::getInstance()->add($this->idSite1, $nextDay->toString(), $site1Text, $starred);
Piwik_Annotations_API::getInstance()->add($this->idSite2, $nextDay->toString(), $site2Text, $starred);
$dateStart = $dateStart->addPeriod(1, 'WEEK');
++$count;
}
}
private function setUpWebsitesAndGoals()
{
// add two websites
self::createWebsite($this->dateTime, $ecommerce = 1);
self::createWebsite($this->dateTime, $ecommerce = 1);
}
}
|