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

TwoSitesManyVisitsOverSeveralDaysWithSearchEngineReferrers.php « Fixtures « PHPUnit « tests - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a122bb5436ea1518c1477a1e27cb50686da73d4f (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
95
96
97
98
99
100
<?php
/**
 * Piwik - Open source web analytics
 *
 * @link http://piwik.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 */
use Piwik\Date;

/**
 * Adds one website and tracks visits on different days over a month
 * using referrer URLs with search engines.
 */
class Test_Piwik_Fixture_TwoSitesManyVisitsOverSeveralDaysWithSearchEngineReferrers extends Test_Piwik_BaseFixture
{
    public $today = '2010-03-06 11:22:33';
    public $idSite = 1;
    public $idSite2 = 2;
    public $keywords = array(
        'free > proprietary', // testing a keyword containing >
        'peace "," not war', // testing a keyword containing ,
        'justice )(&^#%$ NOT corruption!',
    );

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

    public function tearDown()
    {
        // empty
    }

    private function setUpWebsitesAndGoals()
    {
        $siteCreated = '2010-02-01 11:22:33';

        self::createWebsite($siteCreated);
        Piwik_Goals_API::getInstance()->addGoal($this->idSite, 'triggered php', 'manually', '', '');
        Piwik_Goals_API::getInstance()->addGoal(
            $this->idSite, 'another triggered php', 'manually', '', '', false, false, true);

        self::createWebsite($siteCreated);
    }

    private function trackVisits()
    {
        $dateTime = $this->today;
        $idSite = $this->idSite;
        $idSite2 = $this->idSite2;

        $mozillaUserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; fr; rv:1.9.1.6) Gecko/20100101 Firefox/6.0";
        $operaUserAgent = "Opera/9.80 (iPod; U; CPU iPhone OS 4_3_3 like Mac OS X; ja-jp) Presto/2.9.181 Version/12.00";

        $t = self::getTracker($idSite, $dateTime, $defaultInit = true);
        $t->setTokenAuth(self::getTokenAuth());
        $t->enableBulkTracking();
        for ($daysIntoPast = 30; $daysIntoPast >= 0; $daysIntoPast--) {
            // Visit 1: referrer website + test page views
            $visitDateTime = Date::factory($dateTime)->subDay($daysIntoPast)->getDatetime();

            $t->setNewVisitorId();
            $t->setIdSite($idSite);
            $t->setUserAgent($mozillaUserAgent);

            $t->setUrlReferrer('http://www.referrer' . ($daysIntoPast % 5) . '.com/theReferrerPage' . ($daysIntoPast % 2) . '.html');
            $t->setUrl('http://example.org/my/dir/page' . ($daysIntoPast % 4) . '?foo=bar&baz=bar');
            $t->setForceVisitDateTime($visitDateTime);
            $t->setGenerationTime($daysIntoPast * 100 + 100);
            self::assertTrue($t->doTrackPageView('incredible title ' . ($daysIntoPast % 3)));

            // Trigger goal n°1 once
            self::assertTrue($t->doTrackGoal(1));

            // Trigger goal n°2 twice
            self::assertTrue($t->doTrackGoal(2));
            $t->setForceVisitDateTime(Date::factory($visitDateTime)->addHour(0.1)->getDatetime());
            self::assertTrue($t->doTrackGoal(2));

            // VISIT 2: search engine
            $t->setForceVisitDateTime(Date::factory($visitDateTime)->addHour(3)->getDatetime());
            $t->setUrlReferrer('http://google.com/search?q=' . urlencode($this->keywords[$daysIntoPast % 3]));
            $t->setGenerationTime($daysIntoPast * 100 + 200);
            self::assertTrue($t->doTrackPageView('not an incredible title '));

            // VISIT 1 for idSite = 2
            $t->setIdSite($idSite2);
            $t->setNewVisitorId();
            $t->setUserAgent($daysIntoPast % 2 == 0 ? $mozillaUserAgent : $operaUserAgent);

            $t->setForceVisitDateTime($visitDateTime);
            $t->setUrl('http://example.org/');
            $t->setGenerationTime($daysIntoPast * 100 + 300);
            self::assertTrue($t->doTrackPageView('so-so page title'));
        }
        self::checkResponse($t->doBulkTrack());
    }
}