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

VisitsInPast_InvalidateOldReportsTest.php « Integration « PHPUnit « tests - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d93876413aee2c8facbeda164dff28ef7d1c76be (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
<?php
/**
 * Piwik - Open source web analytics
 *
 * @link    http://piwik.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 */

/**
 * Track visits before website creation date and test that Piwik handles them correctly.
 */
class Test_Piwik_Integration_VisitsInPast_InvalidateOldReports extends IntegrationTestCase
{
    public static $fixture = null; // initialized below class definition

    /**
     * @dataProvider getApiForTesting
     * @group        Integration
     * @group        VisitsInPast_InvalidateOldReports
     */
    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->dateTimeDateInPastWebsite1;
        $dateTimeDateInPastWebsite2 = self::$fixture->dateTimeDateInPastWebsite2;

        // 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
     * @group        Integration
     * @group        VisitsInPast_InvalidateOldReports
     */
    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 Piwik_API_Request("module=API&method=CoreAdminHome.invalidateArchivedReports&idSites=4,5,6,55,-1,s',1&dates=2010-01-03");
        ($r->process());
        // Test invalidate comma separated dates
        $r = new Piwik_API_Request("module=API&method=CoreAdminHome.invalidateArchivedReports&idSites=" . $idSite . "," . $idSite2 . "&dates=2010-01-06,2009-10-30");
        ($r->process());
        // test invalidate date in the past
        $r = new Piwik_API_Request("module=API&method=CoreAdminHome.invalidateArchivedReports&idSites=" . $idSite2 . "&dates=2009-06-29");
        ($r->process());
        // invalidate a date more recent to check the date is only updated when it's earlier than current
        $r = new Piwik_API_Request("module=API&method=CoreAdminHome.invalidateArchivedReports&idSites=" . $idSite2 . "&dates=2010-03-03");
        ($r->process());

        // 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->dateTimeDateInPastWebsite1;
        $dateTimeDateInPastWebsite2 = self::$fixture->dateTimeDateInPastWebsite2;

        $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 function getOutputPrefix()
    {
        return 'VisitsInPast_InvalidateOldReports';
    }
}

Test_Piwik_Integration_VisitsInPast_InvalidateOldReports::$fixture = new Test_Piwik_Fixture_TwoSitesVisitsInPast();