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

VisitsInPastInvalidateOldReportsTest.php « System « PHPUnit « tests - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b9519953682cc90aaee8963415247ac61c91697d (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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?php
/**
 * Piwik - free/libre analytics platform
 *
 * @link    http://piwik.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 */
namespace Piwik\Tests\System;

use Piwik\API\Request;
use Piwik\Tests\Framework\TestCase\SystemTestCase;
use Piwik\Tests\Fixtures\TwoSitesVisitsInPast;
use Exception;

/**
 * Track visits before website creation date and test that Piwik handles them correctly.
 *
 * See also other test: ArchiveInvalidationTest
 *
 * @group Core
 * @group VisitsInPastInvalidateOldReportsTest
 */
class VisitsInPastInvalidateOldReportsTest extends SystemTestCase
{
    /**
     * @var TwoSitesVisitsInPast
     */
    public static $fixture = null; // initialized below class definition

    /**
     * @dataProvider getApiForTesting
     */
    public function testApi($api, $params)
    {
        $this->runApiTests($api, $params);
    }

    /**
     * This should NOT return data for old dates before website creation
     */
    public function getApiForTesting()
    {
        $idSite = self::$fixture->idSite;
        $idSite2 = self::$fixture->idSite2;
        $dateTimeDateInPastWebsite1 = self::$fixture->dateTimeInPastWebsite1;
        $dateTimeDateInPastWebsite2 = self::$fixture->dateTimeInPastWebsite2;

        // We test a typical Numeric and a Recursive blob reports
        $apiToCall = array('VisitsSummary.get', 'Actions.getPageUrls');

        // We also test a segment
        //TODO

        // Build tests for the 2 websites
        return array(
            array($apiToCall, array('idSite'                 => $idSite,
                                    'testSuffix'             => 'Website' . $idSite . '_OldReportsShouldNotAppear',
                                    'date'                   => $dateTimeDateInPastWebsite1,
                                    'periods'                => 'month',
                                    'setDateLastN'           => 4, // 4months ahead
                                    'otherRequestParameters' => array('expanded' => 1))),
            array($apiToCall, array('idSite'                 => $idSite2,
                                    'testSuffix'             => 'Website' . $idSite2 . '_OldReportsShouldNotAppear',
                                    'date'                   => $dateTimeDateInPastWebsite2,
                                    'periods'                => 'month',
                                    'setDateLastN'           => 4, // 4months ahead
                                    'otherRequestParameters' => array('expanded' => 1))),
        );
    }

    /**
     * @depends      testApi
     * @dataProvider getAnotherApiForTesting
     */
    public function testAnotherApi($api, $params)
    {
        $idSite = self::$fixture->idSite;
        $idSite2 = self::$fixture->idSite2;

        // 1) Invalidate old reports for the 2 websites
        // Test invalidate 1 date only
        $r = new Request("module=API&method=CoreAdminHome.invalidateArchivedReports&idSites=4,5,6,55,-1,s',1&dates=2010-01-03");
        $this->assertApiResponseHasNoError($r->process());

        // Test invalidate comma separated dates
        $r = new Request("module=API&method=CoreAdminHome.invalidateArchivedReports&idSites=" . $idSite . "," . $idSite2 . "&dates=2010-01-06,2009-10-30");
        $this->assertApiResponseHasNoError($r->process());

        // test invalidate date in the past
        // Format=original will re-throw exception
        $r = new Request("module=API&method=CoreAdminHome.invalidateArchivedReports&idSites=" . $idSite2 . "&dates=2009-06-29&format=original");
        $this->assertApiResponseHasNoError($r->process());

        // invalidate a date more recent to check the date is only updated when it's earlier than current
        $r = new Request("module=API&method=CoreAdminHome.invalidateArchivedReports&idSites=" . $idSite2 . "&dates=2010-03-03");
        $this->assertApiResponseHasNoError($r->process());


        // Make an invalid call
        $idSiteNoAccess = 777;
        try {
            $request = new Request("module=API&method=CoreAdminHome.invalidateArchivedReports&idSites=" . $idSiteNoAccess . "&dates=2010-03-03&format=original");
            $request->process();
            $this->fail();
        } catch(Exception $e) {}

        // test an invalidate period parameter
        try {
            $invalidPeriod = "day,month";
            $request = new Request("module=API&method=CoreAdminHome.invalidateArchivedReports&period=$invalidPeriod&idSites=$idSite&dates=2010-03-03&format=original");
            $request->process();
            $this->fail();
        } catch(Exception $e) {}

        // 2) Call API again, with an older date, which should now return data
        $this->runApiTests($api, $params);
    }

    /**
     * This is called after getApiToTest()
     * WE invalidate old reports and check that data is now returned for old dates
     */
    public function getAnotherApiForTesting()
    {
        $idSite = self::$fixture->idSite;
        $idSite2 = self::$fixture->idSite2;
        $dateTimeDateInPastWebsite1 = self::$fixture->dateTimeInPastWebsite1;
        $dateTimeDateInPastWebsite2 = self::$fixture->dateTimeInPastWebsite2;

        $apiToCall = array('VisitsSummary.get', 'Actions.getPageUrls');

        return array(
            array($apiToCall, array('idSite'                 => $idSite,
                                    'testSuffix'             => 'Website' . $idSite . '_OldReportsShouldAppear',
                                    'date'                   => $dateTimeDateInPastWebsite1,
                                    'periods'                => 'month',
                                    'setDateLastN'           => 4, // 4months ahead
                                    'otherRequestParameters' => array('expanded' => 1))),
            array($apiToCall, array('idSite'                 => $idSite2,
                                    'testSuffix'             => 'Website' . $idSite2 . '_OldReportsShouldAppear',
                                    'date'                   => $dateTimeDateInPastWebsite2,
                                    'periods'                => 'month',
                                    'setDateLastN'           => 4, // 4months ahead
                                    'otherRequestParameters' => array('expanded' => 1))),
        );
    }

    public static function getOutputPrefix()
    {
        return 'VisitsInPast_InvalidateOldReports';
    }
}

VisitsInPastInvalidateOldReportsTest::$fixture = new TwoSitesVisitsInPast();