Welcome to mirror list, hosted at ThFree Co, Russian Federation.

VisitsInDifferentTimezones.php « Fixtures « PHPUnit « tests - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c5cf8eee6b366430e616620dfb3185ae052e707e (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
<?php
/**
 * Matomo - free/libre analytics platform
 *
 * @link https://matomo.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 */
namespace Piwik\Tests\Fixtures;

use Piwik\Date;
use Piwik\Tests\Framework\Fixture;

/**
 * Adds one site with a non UTC timezone and tracks a couple visits near the end of the day.
 */
class VisitsInDifferentTimezones extends Fixture
{
    public $idSite = 1;
    public $idSite2 = 2;
    public $dateTime = '2010-03-06';
    public $date;

    public function __construct()
    {
        $this->date = Date::factory($this->dateTime)->toString();
    }

    public function setUp(): void
    {
        $this->setUpWebsitesAndGoals();
        $this->trackVisits();
    }

    public function tearDown(): void
    {
        // empty
    }

    private function setUpWebsitesAndGoals()
    {
        // tests run in UTC, the Tracker in UTC
        if (!self::siteCreated($idSite = 1)) {
            self::createWebsite($this->dateTime, $ecommerce = 0, $siteName = 'site in EST', $siteUrl = false,
                                $siteSearch = 1, $searchKeywordParameters = null,
                                $searchCategoryParameters = null, $timezone = 'America/New_York');
        }
        if (!self::siteCreated($idSite = 2)) {
            self::createWebsite($this->dateTime, $ecommerce = 0, $siteName = 'site in UTC', $siteUrl = false,
                $siteSearch = 1, $searchKeywordParameters = null,
                $searchCategoryParameters = null, $timezone = 'UTC');
        }
    }

    private function trackVisits()
    {
        // track 2 hours before today in UTC. for utc website, there will be 1 visit yesterday, 0 today.
        // for est website, there will be 0 visit yesterday, 1 today.
        $dateTime = Date::factory('today')->subHour(2)->getDatetime();

        foreach ([$this->idSite, $this->idSite2] as $idSite) {
            $t = self::getTracker($idSite, $dateTime, $defaultInit = true);

            // visit that is 'tomorrow' in UTC
            $t->setUrl('http://example.org/index.htm');
            self::checkResponse($t->doTrackPageView('incredible title!'));
        }
    }

    public function provideContainerConfig()
    {
        $this->setMockNow();

        return parent::provideContainerConfig();
    }

    public function setMockNow()
    {
        // set now to 1:00 am today
        $now = time();
        $now = $now - ($now % 86400);
        $now = $now + 3600;
        Date::$now = $now;
    }
}