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

TwoVisitsWithContents.php « Fixtures « tests « Contents « plugins - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4285d3ee0881d3f2d796472a04b3cfdea436c325 (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
<?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\Contents\tests\Fixtures;

use Piwik\Date;
use Piwik\Plugins\Goals\API as APIGoals;
use Piwik\Tests\Framework\Fixture;
use PiwikTracker;

/**
 * Tracks contents
 */
class TwoVisitsWithContents extends Fixture
{
    public $dateTime = '2010-01-03 11:22:33';
    public $idSite = 1;
    public $idGoal1 = 1;

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

    private function setUpWebsitesAndGoals()
    {
        // tests run in UTC, the Tracker in UTC
        if (!self::siteCreated($idSite = 1)) {
            self::createWebsite($this->dateTime);
        }

        if (!self::goalExists($idSite = 1, $idGoal = 1)) {
            // These two goals are to check contents don't trigger for URL or Title matching
            APIGoals::getInstance()->addGoal($this->idSite, 'triggered js', 'url', 'webradio', 'contains');
            APIGoals::getInstance()->addGoal($this->idSite, 'triggered js', 'title', 'Music', 'contains');
        }
    }

    public function trackVisits()
    {
        $uselocal = false;
        $vis = self::getTracker($this->idSite, $this->dateTime, $useDefault = true, $uselocal);

        $this->trackContentImpressionsAndInteractions($vis);

        $this->dateTime = Date::factory($this->dateTime)->addHour(0.5);
        $vis2 = self::getTracker($this->idSite, $this->dateTime, $useDefault = true, $uselocal);
        $vis2->setIp('111.1.1.1');
        $vis2->setPlugins($flash = false, $java = false, $director = true);

        $this->trackContentImpressionsAndInteractions($vis2);
    }

    private function moveTimeForward(PiwikTracker $vis, $minutes)
    {
        $hour = $minutes / 60;
        $vis->setForceVisitDateTime(Date::factory($this->dateTime)->addHour($hour)->getDatetime());
    }

    protected function trackContentImpressionsAndInteractions(PiwikTracker $vis)
    {
        $vis->setUrl('http://www.example.org/page');
        $vis->setGenerationTime(333);
        self::checkResponse($vis->doTrackPageView('Ads'));

        self::checkResponse($vis->doTrackContentImpression('ImageAd'));
        self::checkResponse($vis->doTrackContentImpression('ImageAd', ''));

        $this->moveTimeForward($vis, 2);
        self::checkResponse($vis->doTrackContentImpression('ImageAd', '/path/ad.jpg', 'http://www.example.com'));
        self::checkResponse($vis->doTrackContentImpression('ImageAd', '/path/ad2.jpg', 'http://www.example.com'));
        self::checkResponse($vis->doTrackContentInteraction('submit', 'ImageAd', '/path/ad.jpg', 'http://www.example.com'));
        $this->moveTimeForward($vis, 3);
        self::checkResponse($vis->doTrackContentImpression('Text Ad', 'Click to download Piwik now', 'http://piwik.org/download'));
        self::checkResponse($vis->doTrackContentImpression('Text Ad', 'Click NOW', 'http://piwik.org/'));
        self::checkResponse($vis->doTrackContentInteraction('click', 'Text Ad', 'Click to download Piwik now', 'http://piwik.org/download'));
        self::checkResponse($vis->doTrackContentInteraction('click', 'Text Ad', 'Click NOW', 'http://piwik.org/download'));
        $this->moveTimeForward($vis, 4);
        self::checkResponse($vis->doTrackContentImpression('Text Ad', 'Click to download Piwik now', ''));

        $this->moveTimeForward($vis, 4.5);
        self::checkResponse($vis->doTrackContentImpression('Video Ad', 'movie.mov'));

        $vis->setUrl('http://www.example.com/de/suche?q=foo');
        $this->moveTimeForward($vis, 4.5);
        self::checkResponse($vis->doTrackContentImpression('Video Ad', 'movie.mov'));
    }

    public function tearDown()
    {
    }
}