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
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?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\Integration;
use Piwik\API\Request;
use Piwik\Config;
use Piwik\Tests\Fixtures\SiteVisitsWithInvalidation;
use Piwik\Tests\IntegrationTestCase;
use Exception;
/**
* Track visits before website creation date and test that Piwik handles them correctly.
*
* @group Integration
* @group ArchiveInvalidationTest
*/
class ArchiveInvalidationTest extends IntegrationTestCase
{
public static $fixture = null; // initialized below class definition
/**
* @dataProvider getApiForTesting
*/
public function testApi($api, $params)
{
$this->runApiTests($api, $params);
}
/**
* This should NOT return data for old dates before website creation
*/
public function getApiForTesting()
{
$idSite = self::$fixture->idSite;
$dateTimeDateInPastWebsite = self::$fixture->dateTimeFirstDateWebsite;
// We test a typical Numeric and a Recursive blob reports
$apiToCall = array('VisitsSummary.get', 'Actions.getPageUrls');
// We also test a segment
//TODO
// Build tests for the 2 websites
return array(
array($apiToCall, array('idSite' => $idSite,
'testSuffix' => 'Website' . $idSite . '_NewDataShouldNotAppear',
'date' => $dateTimeDateInPastWebsite,
'periods' => 'month',
'setDateLastN' => 4, // 4months ahead
'otherRequestParameters' => array('expanded' => 1)))
);
}
/**
* @depends testApi
* @dataProvider getSameApiForTesting
*/
public function testSameApi($api, $params)
{
self::$fixture->trackMoreVisits();
Config::getInstance()->General['enable_browser_archiving_triggering'] = 0;
$idSite = self::$fixture->idSite;
$dateTimeDateInPastWebsite = new \DateTime(self::$fixture->dateTimeFirstDateWebsite);
$r = new Request("module=API&method=CoreAdminHome.invalidateArchivedReports&idSites=" . $idSite . "&dates=" . $dateTimeDateInPastWebsite->format('Y-m-d'));
$this->assertApiResponseHasNoError($r->process());
// 2) Call API again, with an older date, which should now return data
$this->runApiTests($api, $params);
Config::getInstance()->General['enable_browser_archiving_triggering'] = 1;
}
public function getSameApiForTesting()
{
$idSite = self::$fixture->idSite;
$dateTimeFirstDateWebsite = self::$fixture->dateTimeFirstDateWebsite;
$apiToCall = array('VisitsSummary.get', 'Actions.getPageUrls');
return array(
array($apiToCall, array('idSite' => $idSite,
'testSuffix' => 'Website' . $idSite . '_NewDataShouldNotAppear',
'date' => $dateTimeFirstDateWebsite,
'periods' => 'month',
'setDateLastN' => 4, // 4months ahead
'otherRequestParameters' => array('expanded' => 1))),
);
}
/**
* @depends testApi
* @depends testSameApi
* @dataProvider getAnotherApiForTesting
*/
public function testAnotherApi($api, $params)
{
Config::getInstance()->General['enable_browser_archiving_triggering'] = 1;
$idSite = self::$fixture->idSite;
$dateTimeDateInPastWebsite = new \DateTime(self::$fixture->dateTimeFirstDateWebsite);
$r = new Request("module=API&method=CoreAdminHome.invalidateArchivedReports&idSites=" . $idSite . "&dates=" . $dateTimeDateInPastWebsite->format('Y-m-d'));
$this->assertApiResponseHasNoError($r->process());
// 2) Call API again, with an older date, which should now return data
$this->runApiTests($api, $params);
}
/**
* This is called after getApiToTest()
* WE invalidate old reports and check that data is now returned for old dates
*/
public function getAnotherApiForTesting()
{
$idSite = self::$fixture->idSite;
$dateTimeFirstDateWebsite = self::$fixture->dateTimeFirstDateWebsite;
$apiToCall = array('VisitsSummary.get', 'Actions.getPageUrls');
return array(
array($apiToCall, array('idSite' => $idSite,
'testSuffix' => 'Website' . $idSite . '_NewDataShouldAppear',
'date' => $dateTimeFirstDateWebsite,
'periods' => 'month',
'setDateLastN' => 4, // 4months ahead
'otherRequestParameters' => array('expanded' => 1))),
);
}
public static function getOutputPrefix()
{
return 'Archive_Invalidation';
}
}
ArchiveInvalidationTest::$fixture = new SiteVisitsWithInvalidation();