blob: 6a1de31dc1d95004d1559376b203557fe10b73cd (
plain)
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
|
<?php
/**
* Piwik - free/libre analytics platform
*
* @link https://matomo.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Plugins\SitesManager\tests\Integration;
use Piwik\Common;
use Piwik\Db;
use Piwik\Plugins\SitesManager;
use Piwik\Tests\Framework\Fixture;
use Piwik\Tests\Framework\TestCase\IntegrationTestCase;
/**
* @group SitesManager
* @group SitesManager_Integration
*/
class TrackingTest extends IntegrationTestCase
{
public function test_TrackingOldVisits_ResetsSiteCreatedTime_SoDataCanBeViewedInUI()
{
Fixture::createWebsite('2015-01-01 00:00:00');
$createdTime = $this->getSiteCreatedTime($idSite = 1);
$this->assertEquals('2014-12-31 00:00:00', $createdTime);
$t = $this->getLocalTracker();
$t->setForceVisitDateTime('2014-05-05 05:05:05');
Fixture::checkResponse($t->doTrackPageView('page view'));
$createdTime = $this->getSiteCreatedTime($idSite = 1);
$this->assertEquals('2014-05-04 00:00:00', $createdTime);
}
public function test_TrackingOldVisit_ThatIsExcluded_DoesNotResetCreatedTime()
{
Fixture::createWebsite('2015-01-01 00:00:00');
SitesManager\API::getInstance()->setGlobalExcludedIps('123.44.67.43');
$createdTime = $this->getSiteCreatedTime($idSite = 1);
$this->assertEquals('2014-12-31 00:00:00', $createdTime);
$t = $this->getLocalTracker();
$t->setForceVisitDateTime('2014-05-05 05:05:05');
$t->setIp('123.44.67.43');
Fixture::checkResponse($t->doTrackPageView('page view'));
$createdTime = $this->getSiteCreatedTime($idSite = 1);
$this->assertEquals('2014-12-31 00:00:00', $createdTime);
}
public function test_TrackingOldVisit_ForSiteWithNoTsCreatedTime_DoesNotResetCreatedTime()
{
Fixture::createWebsite('2015-01-01 00:00:00');
$this->unsetCreatedTime($idSite = 1);
$createdTime = $this->getSiteCreatedTime($idSite = 1);
$this->assertEquals(null, $createdTime);
$t = $this->getLocalTracker();
$t->setForceVisitDateTime('2014-08-06 07:53:09');
Fixture::checkResponse($t->doTrackPageView('page view'));
$createdTime = $this->getSiteCreatedTime($idSite = 1);
$this->assertEquals(null, $createdTime);
}
private function getLocalTracker()
{
return self::$fixture->getTracker($idSite = 1, '2015-01-01', $defaultInit = true, $useLocalTracker = true);
}
private function getSiteCreatedTime($idSite)
{
return Db::fetchOne("SELECT ts_created FROM " . Common::prefixTable('site') . " WHERE idsite = ?", array($idSite));
}
private function unsetCreatedTime($idSite)
{
Db::query("UPDATE " . Common::prefixTable('site') . " SET ts_created = NULL WHERE idsite = ?", array($idSite));
}
protected static function configureFixture($fixture)
{
parent::configureFixture($fixture);
$fixture->createSuperUser = true;
}
}
|