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
|
<?php
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
/**
* Tests use of custom variable segments.
*/
class Test_Piwik_Integration_TwoVisitsWithCustomVariables_SegmentMatchVisitorType extends IntegrationTestCase
{
public static $fixture = null; // initialized below class definition
/**
* @dataProvider getApiForTesting
* @group Integration
* @group TwoVisitsWithCustomVariables_SegmentMatchVisitorType
*/
public function testApi($api, $params)
{
$this->runApiTests($api, $params);
}
public function getApiForTesting()
{
// Segment matching some
$segments = array('customVariableName1==VisitorType;customVariableValue1==LoggedIn',
'customVariableName1==VisitorType;customVariableValue1=@LoggedI');
$apiToCall = array('Referers.getKeywords', 'CustomVariables.getCustomVariables', 'VisitsSummary.get');
$periods = array('day', 'week');
// We run it twice just to check that running archiving twice for same input parameters doesn't create more records/overhead
$result = array();
for ($i = 1; $i <= 2; $i++) {
foreach ($segments as $segment) {
$result[] = array(
$apiToCall, array('idSite' => 'all',
'date' => self::$fixture->dateTime,
'periods' => $periods,
'setDateLastN' => true,
'segment' => $segment)
);
}
}
return $result;
}
/**
* @depends testApi
* @group Integration
* @group TwoVisitsWithCustomVariables_SegmentMatchVisitorType
*/
public function testCheck()
{
// ----------------------------------------------
// Implementation Checks
// ----------------------------------------------
// Verify that, when a segment is specified, only the requested report is processed
// In this case, check that only the Custom Variables blobs have been processed
$tests = array(
// 1) CHECK 'day' archive stored in January
// We expect 2 segments * (1 custom variable name + 2 ref metrics + 6 subtable for the custom var values + 5 Referers blob)
'archive_blob_2010_01' => 28,
// This contains all 'last N' weeks & days,
// (1 metrics
// + 2 referer metrics
// + 3 done flag )
// * 2 segments
// + 1 Done flag per Plugin, for each "Last N" date
'archive_numeric_2010_01' => 142,
// 2) CHECK 'week' archive stored in December (week starts the month before)
// We expect 2 segments * (1 custom variable name + 2 ref metrics + 6 subtable for the values of the name + 5 referers blob)
'archive_blob_2009_12' => 30,
// 6 metrics,
// 2 Referer metrics (Referers_distinctSearchEngines/Referers_distinctKeywords),
// 3 done flag (referers, CustomVar, VisitsSummary),
// X * 2 segments
'archive_numeric_2009_12' => (6 + 2 + 3) * 2,
);
foreach ($tests as $table => $expectedRows) {
$sql = "SELECT count(*) FROM " . Piwik_Common::prefixTable($table);
$countBlobs = Zend_Registry::get('db')->fetchOne($sql);
if($expectedRows != $countBlobs) {
var_export(Zend_Registry::get('db')->fetchAll("SELECT * FROM " . Piwik_Common::prefixTable($table) . " ORDER BY name, idarchive ASC"));
}
$this->assertEquals($expectedRows, $countBlobs, "$table: %s");
}
}
public function getOutputPrefix()
{
return 'twoVisitsWithCustomVariables_segmentMatchVisitorType';
}
}
Test_Piwik_Integration_TwoVisitsWithCustomVariables_SegmentMatchVisitorType::$fixture
= new Test_Piwik_Fixture_TwoVisitsWithCustomVariables();
Test_Piwik_Integration_TwoVisitsWithCustomVariables_SegmentMatchVisitorType::$fixture->doExtraQuoteTests = false;
|