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

TransitionsMaxAllowedPeriodTest.php « Integration « tests « Transitions « plugins - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b074e7d3ab33f94a27504dab85cb020660b57af2 (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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?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\Plugins\Transitions\tests\Integration;

use Piwik\Plugins\Transitions\Transitions;
use Piwik\Tests\Framework\TestCase\IntegrationTestCase;
use Piwik\Config;
use Piwik\Tests\Framework\Fixture;
use Piwik\Plugins\Transitions\API;

/**
 * Tests the transitions plugin max_period_allowed setting
 *
 * @group TransitionsMaxAllowedPeriodTest
 * @group Plugins
 */
class TransitionsMaxAllowedPeriodTest extends IntegrationTestCase
{

    public $api;

    protected static function configureFixture($fixture)
    {
        parent::configureFixture($fixture);
        $fixture->createSuperUser = true;
    }

    public function setUp(): void
    {
        parent::setUp();
        Fixture::createWebsite('2010-02-03 00:00:00');
        $this->api = API::getInstance();

        $t = Fixture::getTracker(1, '2012-08-09 01:02:03', $defaultInit = true, $useLocalTracker = false);

        $t->setUrl('http://example.org/page/one.html');
        $t->doTrackPageView('incredible title ');
    }

    public function test_ShouldThrowException_IfPeriodNotAllowed()
    {
        $invalidPeriods = [
            'day' => ['week', 'month', 'year'],
            'week' => ['month', 'year'],
            'month' => ['year'],
        ];
        foreach ($invalidPeriods as $period => $invalids) {
            Config::setSetting('Transitions_1', 'max_period_allowed', $period);
            foreach ($invalids as $ip) {
                try {
                    $this->api->getTransitionsForAction('http://example.org/page/one.html', 'url',
                        1, $ip, '2012-08-09');
                    $this->fail("Failed asserting that exception 'PeriodNotAllowed' was thrown");
                } catch (\Exception $e) {
                    $this->assertEquals('PeriodNotAllowed', $e->getMessage());
                }
            }
        }
    }

    public function test_ShouldReturnData_IfPeriodAllowed()
    {
        $validPeriods = [
            'day' => ['day'],
            'week' => ['day', 'week'],
            'month' => ['day', 'week', 'month'],
            'year' => ['day', 'week', 'month', 'year'],
            'all' => ['day', 'week', 'month', 'year'],
        ];
        foreach ($validPeriods as $period => $valids) {
            Config::setSetting('Transitions_1', 'max_period_allowed', $period);
            foreach ($valids as $vp) {
                $r = $this->api->getTransitionsForAction('http://example.org/page/one.html', 'url',
                    1, $vp, '2012-08-09');
                self::assertEquals(1, $r['pageMetrics']['pageviews']);
            }
        }
    }

    public function test_ShouldThrowException_IfRangeDayCountIsLargerThanDayPeriod()
    {
        Config::setSetting('Transitions_1', 'max_period_allowed', 'day');
        $this->expectException(\Exception::class);
        $this->expectExceptionMessage('PeriodNotAllowed');
        $this->api->getTransitionsForAction('http://example.org/page/one.html', 'url', 1,
            'range','2012-08-09,2012-08-10');
    }

    public function test_ShouldThrowException_IfRangeDayCountIsLargerThanWeekPeriod()
    {
        Config::setSetting('Transitions_1', 'max_period_allowed', 'day');
        $this->expectException(\Exception::class);
        $this->expectExceptionMessage('PeriodNotAllowed');
        $this->api->getTransitionsForAction('http://example.org/page/one.html', 'url', 1,
            'range','2012-08-09,2012-08-17');
    }

    public function test_ShouldThrowException_IfRangeDayCountIsLargerThanMonthPeriod()
    {
        Config::setSetting('Transitions_1', 'max_period_allowed', 'day');
        $this->expectException(\Exception::class);
        $this->expectExceptionMessage('PeriodNotAllowed');
        $this->api->getTransitionsForAction('http://example.org/page/one.html', 'url', 1,
            'range','2012-08-09,2012-09-10');
    }

    public function test_ShouldThrowException_IfRangeDayCountIsLargerThanYearPeriod()
    {
        Config::setSetting('Transitions_1', 'max_period_allowed', 'day');
        $this->expectException(\Exception::class);
        $this->expectExceptionMessage('PeriodNotAllowed');
        $this->api->getTransitionsForAction('http://example.org/page/one.html', 'url', 1,
            'range','2012-08-09,2013-08-10');
    }

    public function test_ShouldUseSiteConfigInsteadOfGeneral_IfSiteConfigExists()
    {
        Config::setSetting('Transitions_1', 'max_period_allowed', null);
        Config::setSetting('Transitions', 'max_period_allowed', 'month');
        $maxAllowedPeriod = Transitions::getPeriodAllowedConfig(1);
        $this->assertEquals('month', $maxAllowedPeriod);

        Config::setSetting('Transitions_1', 'max_period_allowed', 'week');
        $maxAllowedPeriod = Transitions::getPeriodAllowedConfig(1);
        $this->assertEquals('week', $maxAllowedPeriod);
    }

}