Newer
Older
<?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\Piwik;
use Piwik\Access;
use Piwik\Date;
mattab
a validé
use Piwik\Plugins\SitesManager\API;
/**
* Tests the archive.php cron script.
*/
class Test_Piwik_Integration_ArchiveCronTest extends IntegrationTestCase
{
public static $fixture = null; // initialized below class definition
Benaka Moorthi
a validé
public static function createAccessInstance()
{
Access::setSingletonInstance($access = new Test_Access_OverrideLogin());
Benaka Moorthi
a validé
Piwik_PostEvent('FrontController.initAuthenticationObject');
}
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
public function getApiForTesting()
{
$results = array();
$results[] = array('VisitsSummary.get', array('idSite' => 'all',
'date' => '2012-08-09',
'periods' => array('day', 'week', 'month', 'year')));
foreach (self::$fixture->getDefaultSegments() as $segmentName => $info) {
$results[] = array('VisitsSummary.get', array('idSite' => 'all',
'date' => '2012-08-09',
'periods' => array('day', 'week', 'month', 'year'),
'segment' => $info['definition'],
'testSuffix' => '_' . $segmentName));
}
$results[] = array('VisitsSummary.get', array('idSite' => 'all',
'date' => '2012-08-09',
'periods' => array('day', 'week', 'month', 'year'),
'segment' => 'browserCode==EP',
'testSuffix' => '_nonPreArchivedSegment'));
return $results;
}
public function getArchivePhpCronOptionsToTest()
{
return array(
array('noOptions', array()),
// segment archiving makes calling the script more than once impractical. if all 4 are
// called, this test can take up to 13min to complete.
/*array('forceAllWebsites', array('--force-all-websites' => false)),
array('forceAllPeriods_lastDay', array('--force-all-periods' => '86400')),
array('forceAllPeriods_allTime', array('--force-all-periods' => false)),*/
);
}
/**
* @dataProvider getArchivePhpCronOptionsToTest
* @group Integration
* @group ImportLogs
*/
public function testArchivePhpCron($optionGroupName, $archivePhpOptions)
{
self::deleteArchiveTables();
$this->setLastRunArchiveOptions();
$this->runArchivePhpCron($archivePhpOptions);
foreach ($this->getApiForTesting() as $testInfo) {
list($api, $params) = $testInfo;
if (!isset($params['testSuffix'])) {
$params['testSuffix'] = '';
}
$params['testSuffix'] .= '_' . $optionGroupName;
$params['disableArchiving'] = true;
// only do month for the last 3 option groups
if ($optionGroupName != 'noOptions') {
$params['periods'] = array('day');
}
$this->runApiTests($api, $params);
}
}
private function setLastRunArchiveOptions()
{
$periodTypes = array('day', 'periods');
mattab
a validé
$idSites = API::getInstance()->getAllSitesId();
$time = Date::factory(self::$fixture->dateTime)->subDay(1)->getTimestamp();
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
foreach ($periodTypes as $period) {
foreach ($idSites as $idSite) {
$lastRunArchiveOption = Piwik::getArchiveCronLastRunOptionName($period, $idSite);
Piwik_SetOption($lastRunArchiveOption, $time);
}
}
}
private function runArchivePhpCron($options)
{
$archivePhpScript = PIWIK_INCLUDE_PATH . '/tests/PHPUnit/proxy/archive.php';
$urlToProxy = Test_Piwik_BaseFixture::getRootUrl() . 'tests/PHPUnit/proxy/index.php';
// create the command
$cmd = "php \"$archivePhpScript\" --url=\"$urlToProxy\" ";
foreach ($options as $name => $value) {
$cmd .= $name;
if ($value !== false) {
$cmd .= '="' . $value . '"';
}
$cmd .= ' ';
}
$cmd .= '2>&1';
// run the command
exec($cmd, $output, $result);
if ($result !== 0) {
throw new Exception("log importer failed: " . implode("\n", $output) . "\n\ncommand used: $cmd");
}
return $output;
}
}
Test_Piwik_Integration_ArchiveCronTest::$fixture = new Test_Piwik_Fixture_ManySitesImportedLogs();
Test_Piwik_Integration_ArchiveCronTest::$fixture->addSegments = true;