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
|
<?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\Archive;
use Piwik\ArchiveProcessor\PluginsArchiver;
use Piwik\Config;
use Piwik\Piwik;
use Piwik\Segment;
use Piwik\Site;
use Piwik\Db;
use Piwik\ArchiveProcessor\Parameters;
use Exception;
use Piwik\Plugin\Archiver;
use Piwik\Tests\Framework\Fixture;
use Piwik\Tests\Framework\TestCase\IntegrationTestCase;
use Piwik\Period\Factory as PeriodFactory;
use Piwik\Tracker\Db\DbException;
class CustomArchiver extends Archiver
{
public function aggregateDayReport()
{
throw new DbException('Failed query foo bar', 42);
}
public function aggregateMultipleReports()
{
throw new DbException('Failed query foo bar baz', 43);
}
}
class CustomPluginsArchiver extends PluginsArchiver
{
protected static function getPluginArchivers()
{
return array(
'MyPluginName' => 'Piwik\Tests\Integration\Archive\CustomArchiver'
);
}
}
/**
* @group PluginsArchiver
* @group PluginsArchiverTest
* @group Core
*/
class PluginsArchiverTest extends IntegrationTestCase
{
/**
* @var PluginsArchiver
*/
private $pluginsArchiver;
public function setUp()
{
parent::setUp();
Fixture::createWebsite('2015-01-01 00:00:00');
Fixture::createWebsite('2015-01-01 00:00:00');
Fixture::createWebsite('2015-01-01 00:00:00');
$this->pluginsArchiver = new CustomPluginsArchiver($this->createArchiveProcessorParamaters());
}
private function createArchiveProcessorParamaters()
{
$oPeriod = PeriodFactory::makePeriodFromQueryParams('UTC', 'day', '2015-01-01');
$segment = new Segment(false, array(1));
$params = new Parameters(new Site(1), $oPeriod, $segment);
return $params;
}
/**
* @expectedException \Piwik\ArchiveProcessor\PluginsArchiverException
* @expectedExceptionMessage Failed query foo bar - in plugin MyPluginName
* @expectedExceptionCode 42
*/
public function test_purgeOutdatedArchives_PurgesCorrectTemporaryArchives_WhileKeepingNewerTemporaryArchives_WithBrowserTriggeringEnabled()
{
$this->pluginsArchiver->callAggregateAllPlugins(1, 1);
}
public function test_archiveMultipleSites()
{
Piwik::addAction('ArchiveProcessor.Parameters.getIdSites', function (&$idSites, $period) {
if (count($idSites) === 1 && reset($idSites) === 1) {
$idSites = array(2,3);
}
});
Piwik::addAction('ArchiveProcessor.shouldAggregateFromRawData', function (&$shouldAggregateRawData, Parameters $params) {
// needed as by default we would only aggregate for single site
if ($params->isDayArchive()) {
$shouldAggregateRawData = true;
}
});
$this->pluginsArchiver = new PluginsArchiver($this->createArchiveProcessorParamaters());
$this->pluginsArchiver->callAggregateCoreMetrics();
$this->pluginsArchiver->callAggregateAllPlugins(1, 1, $forceArchivingWithoutVisits = true);
}
}
|