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
<?php
/**
* Tests the URL normalization.
*/
class Test_Piwik_Integration_UrlNormalization extends IntegrationTestCase
{
protected static $dateTime = '2010-03-06 11:22:33';
protected static $idSite = 1;
public static function setUpBeforeClass()
{
parent::setUpBeforeClass();
try {
self::setUpWebsitesAndGoals();
self::trackVisits();
} catch(Exception $e) {
// Skip whole test suite if an error occurs while setup
throw new PHPUnit_Framework_SkippedTestSuiteError($e->getMessage());
}
}
/**
* @dataProvider getApiForTesting
* @group Integration
* @group UrlNormalization
*/
public function testApi($api, $params)
{
$this->runApiTests($api, $params);
}
public function getApiForTesting()
{
$return = array();
$return[] = array('Actions.getPageUrls', array(
'testSuffix' => '_urls',
'idSite' => self::$idSite,
'date' => self::$dateTime,
));
$return[] = array('Actions.getPageTitles', array(
'testSuffix' => '_titles',
'idSite' => self::$idSite,
'date' => self::$dateTime,
));
$return[] = array('Actions.getPageUrls', array(
'testSuffix' => '_pagesSegmented',
'idSite' => self::$idSite,
'date' => self::$dateTime,
'segment' => 'pageUrl==https://WWw.example.org/foo/bar2.html',
));
$return[] = array('Actions.getPageUrls', array(
'testSuffix' => '_pagesSegmented',
'idSite' => self::$idSite,
'date' => self::$dateTime,
'segment' => 'pageUrl==example.org/foo/bar2.html',
));
$return[] = array('Actions.getPageUrls', array(
'testSuffix' => '_pagesSegmentedRef',
'idSite' => self::$idSite,
'date' => self::$dateTime,
'segment' => 'referrerUrl==http://www.google.com/search?q=piwik',
));
$return[] = array('Referers.getKeywordsForPageUrl', array(
'testSuffix' => '_keywords',
'idSite' => self::$idSite,
'date' => self::$dateTime,
'otherRequestParameters' => array(
'url' => 'http://WWW.example.org/foo/bar.html'
)
));
return $return;
}
/**
* @@depends testApi
* @group Integration
* @group UrlNormalization
*/
public function testCheckPostConditions()
{
$sql = "SELECT count(*) FROM " . Piwik_Common::prefixTable('log_action');
$count = Zend_Registry::get('db')->fetchOne($sql);
$expected = 9; // 4 urls + 5 titles
$this->assertEquals($expected, $count, "only $expected actions expected");
$sql = "SELECT name, url_prefix FROM " . Piwik_Common::prefixTable('log_action')
. " WHERE type = " . Piwik_Tracker_Action::TYPE_ACTION_URL
. " ORDER BY idaction ASC";
$urls = Zend_Registry::get('db')->fetchAll($sql);
$expected = array(
array('name' => 'example.org/foo/bar.html', 'url_prefix' => 0),
array('name' => 'example.org/foo/bar2.html', 'url_prefix' => 3),
array('name' => 'example.org/foo/bar3.html', 'url_prefix' => 1),
array('name' => 'example.org/foo/bar4.html', 'url_prefix' => 2)
);
$this->assertEquals($expected, $urls, "normalization went wrong");
}
public function getOutputPrefix()
{
return 'UrlNormalization';
}
protected static function setUpWebsitesAndGoals()
{
self::createWebsite(self::$dateTime);
}
protected static function trackVisits()
{
$dateTime = self::$dateTime;
$idSite = self::$idSite;
$t = self::getTracker($idSite, $dateTime, $defaultInit = true, $useThirdPartyCookie = 1);
$t->setUrlReferrer('http://www.google.com/search?q=piwik');
$t->setUrl('http://example.org/foo/bar.html');
self::checkResponse($t->doTrackPageView('http://incredible.title/'));
$t->setUrl('https://example.org/foo/bar.html');
$t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.2)->getDatetime());
self::checkResponse($t->doTrackPageView('https://incredible.title/'));
$t->setUrl('https://wWw.example.org/foo/bar2.html');
$t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.3)->getDatetime());
self::checkResponse($t->doTrackPageView('http://www.incredible.title/'));
$t->setUrl('http://WwW.example.org/foo/bar2.html');
$t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.4)->getDatetime());
self::checkResponse($t->doTrackPageView('https://www.incredible.title/'));
$t->setUrl('http://www.example.org/foo/bar3.html');
$t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.5)->getDatetime());
self::checkResponse($t->doTrackPageView('incredible.title/'));
$t->setUrl('https://example.org/foo/bar4.html');
$t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.6)->getDatetime());
self::checkResponse($t->doTrackPageView('incredible.title/'));
}
}