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

VisitsInCurrentYear.php « Fixtures « PHPUnit « tests - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b77c361dbb7fe1862351fd79895c157aad369dae (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
<?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\Common;
use Piwik\Date;
use Piwik\Db;
use Piwik\Plugins\Goals\API as APIGoals;
use Piwik\Plugins\SitesManager\API as APISitesManager;
use Piwik\Tests\Framework\Fixture;
use Piwik\Tracker\Cache;

/**
 * This fixture adds one website and tracks two visits by one visitor.
 */
class VisitsInCurrentYear extends Fixture
{
    public $idSite = 1;

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

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

    private function setUpWebsite()
    {
        if (!self::siteCreated($idSite = 1)) {
            self::createWebsite('2018-01-01 15:00:00');
        }
    }

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

        // Record 1st visit today
        $t = self::getTracker($idSite, date('Y-m-d H:i:s'), $defaultInit = true);
        $t->setUrl('http://example.org/index.htm?excluded_Parameter=SHOULD_NOT_DISPLAY&parameter=Should display');
        $t->setUrlReferrer('http://referrer.com/page.htm?param=valuewith some spaces');
        self::checkResponse($t->doTrackPageView('incredible title!'));

        // Record 2nd visit 7 days ago
        $t = self::getTracker($idSite, date('Y-m-d H:i:s', strtotime('-7days')), $defaultInit = true);
        $t->setUrl('http://example.org/index.htm?excluded_Parameter=SHOULD_NOT_DISPLAY&parameter=Should display');
        $t->setUrlReferrer('http://referrer.com/page.htm');
        self::checkResponse($t->doTrackPageView('incredible!'));

        // Record 3rd visit 1 month ago
        $t = self::getTracker($idSite, date('Y-m-d H:i:s', strtotime('-1month')), $defaultInit = true);
        $t->setUrl('http://example.org/store/purchase.htm');
        $t->setUrlReferrer('http://search.yahoo.com/search?p=purchase');
        self::checkResponse($t->doTrackPageView('Checkout/Purchasing...'));

        // Record 4th visit 1 year ago
        $t = self::getTracker($idSite, date('Y-m-d H:i:s', strtotime('-1year')), $defaultInit = true);
        $t->setUrl('http://example.org/shop/product.htm');
        self::checkResponse($t->doTrackPageView('Visit product'));
    }
}