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

OneVisitorTwoVisitsTest.php « Integration « PHPUnit « tests - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e14e611d2676d1a0dd0fe1dd47fe573007e86e44 (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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
<?php
/**
 * Piwik - Open source web analytics
 *
 * @link    http://piwik.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 */
use Piwik\API\Proxy;
use Piwik\Archive;

/**
 * This use case covers many simple tracking features.
 * - Tracking Goal by manual trigger, and URL matching, with custom revenue
 * - Tracking the same Goal twice only records it once
 * - Tracks 4 page views: 3 clicks and a file download
 * - URLs parameters exclude is tested
 * - In a returning visit, tracks a Goal conversion
 *   URL matching, with custom referrer and keyword
 *   NO cookie support
 */
class Test_Piwik_Integration_OneVisitorTwoVisits extends IntegrationTestCase
{
    public static $fixture = null; // initialized below class

    public function setUp()
    {
        Proxy::getInstance()->setHideIgnoredFunctions(false);
    }

    public function tearDown()
    {
        Proxy::getInstance()->setHideIgnoredFunctions(true);
    }

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

    public function getApiForTesting()
    {
        $idSite = self::$fixture->idSite;
        $dateTime = self::$fixture->dateTime;

        $enExtraParam = array('expanded' => 1, 'flat' => 1, 'include_aggregate_rows' => 0, 'translateColumnNames' => 1);
        $bulkUrls = array(
            "idSite=" . $idSite . "&date=2010-03-06&expanded=1&period=day&method=VisitsSummary.get",
            "idSite=" . $idSite . "&date=2010-03-06&expanded=1&period=day&method=VisitorInterest.getNumberOfVisitsPerVisitDuration"
        );
        foreach ($bulkUrls as &$url) {
            $url = urlencode($url);
        }
        return array(
            array('all', array('idSite' => $idSite, 'date' => $dateTime)),

            // test API.get (for bug that incorrectly reorders columns of CSV output)
            //   note: bug only affects rows after first
            array('API.get', array('idSite'                 => $idSite,
                                   'date'                   => '2009-10-01',
                                   'format'                 => 'csv',
                                   'periods'                => array('month'),
                                   'setDateLastN'           => true,
                                   'otherRequestParameters' => $enExtraParam,
                                   'language'               => 'en',
                                   'testSuffix'             => '_csv')),

            array('API.getBulkRequest', array('format' => 'xml',
                                               'testSuffix' => '_bulk_xml',
                                               'otherRequestParameters' => array('urls' => $bulkUrls))),

            array('API.getBulkRequest', array('format' => 'json',
                                              'testSuffix' => '_bulk_json',
                                              'otherRequestParameters' => array('urls' => $bulkUrls))),

            // test API.getProcessedReport w/ report that is its own 'actionToLoadSubTables'
            array('API.getProcessedReport', array('idSite'        => $idSite,
                                                  'date'          => $dateTime,
                                                  'periods'       => array('week'),
                                                  'apiModule'     => 'Actions',
                                                  'apiAction'     => 'getPageUrls',
                                                  'supertableApi' => 'Actions.getPageUrls',
                                                  'testSuffix'    => '__subtable')),

            // test hideColumns && showColumns parameters
            array('VisitsSummary.get', array('idSite'                 => $idSite, 'date' => $dateTime, 'periods' => 'day',
                                             'testSuffix'             => '_hideColumns_',
                                             'otherRequestParameters' => array(
                                                 'hideColumns' => 'nb_visits_converted,max_actions,bounce_count,nb_hits,'
                                                     . 'nb_visits,nb_actions,sum_visit_length,avg_time_on_site'
                                             ))),
            array('VisitsSummary.get', array('idSite'                 => $idSite, 'date' => $dateTime, 'periods' => 'day',
                                             'testSuffix'             => '_showColumns_',
                                             'otherRequestParameters' => array(
                                                 'showColumns' => 'nb_visits,nb_actions,nb_hits'
                                             ))),
            array('VisitsSummary.get', array('idSite'                 => $idSite, 'date' => $dateTime, 'periods' => 'day',
                                             'testSuffix'             => '_hideAllColumns_',
                                             'otherRequestParameters' => array(
                                                 'hideColumns' => 'nb_visits_converted,max_actions,bounce_count,nb_hits,'
                                                     . 'nb_visits,nb_actions,sum_visit_length,avg_time_on_site,'
                                                     . 'bounce_rate,nb_uniq_visitors,nb_actions_per_visit,'
                                             ))),

            // test hideColumns w/ API.getProcessedReport
            array('API.getProcessedReport', array('idSite'                 => $idSite, 'date' => $dateTime,
                                                  'periods'                => 'day', 'apiModule' => 'Actions',
                                                  'apiAction'              => 'getPageTitles', 'testSuffix' => '_hideColumns_',
                                                  'otherRequestParameters' => array(
                                                      'hideColumns' => 'nb_visits_converted,xyzaug,entry_nb_visits,' .
                                                          'bounce_rate,nb_hits,nb_visits,avg_time_on_page,' .
														  'avg_time_generation,nb_hits_with_time_generation'
                                                  ))),

            array('API.getProcessedReport', array('idSite'                 => $idSite, 'date' => $dateTime,
                                                  'periods'                => 'day', 'apiModule' => 'Actions',
                                                  'apiAction'              => 'getPageTitles', 'testSuffix' => '_showColumns_',
                                                  'otherRequestParameters' => array(
                                                      'showColumns' => 'nb_visits_converted,xuena,entry_nb_visits,' .
                                                          'bounce_rate,nb_hits'
                                                  ))),
            array('API.getProcessedReport', array('idSite'                 => $idSite, 'date' => $dateTime,
                                                  'periods'                => 'day', 'apiModule' => 'VisitTime',
                                                  'apiAction'              => 'getVisitInformationPerServerTime',
                                                  'testSuffix'             => '_showColumnsWithProcessedMetrics_',
                                                  'otherRequestParameters' => array(
                                                      'showColumns' => 'nb_visits,revenue'
                                                  ))),

            // test hideColumns w/ expanded=1
            array('Actions.getPageTitles', array('idSite'                 => $idSite, 'date' => $dateTime,
                                                 'periods'                => 'day', 'testSuffix' => '_hideColumns_',
                                                 'otherRequestParameters' => array(
                                                     'hideColumns' => 'nb_visits_converted,entry_nb_visits,' .
                                                         'bounce_rate,nb_hits,nb_visits,sum_time_spent,' .
                                                         'entry_sum_visit_length,entry_bounce_count,exit_nb_visits,' .
                                                         'entry_nb_uniq_visitors,exit_nb_uniq_visitors,entry_nb_actions,' .
                                                         'avg_time_generation,nb_hits_with_time_generation',
                                                     'expanded'    => '1'
                                                 ))),

            // test showColumns on API.get
            array('API.get', array(
                'idSite'                 => $idSite,
                'date'                   => $dateTime,
                'periods'                => 'day',
                'testSuffix'             => '_showColumns', 
                'otherRequestParameters' => array(
                    'showColumns'        => 'nb_uniq_visitors,nb_pageviews,bounce_rate'
                )
            )),
        );
    }

    /**
     * Test that Archive::getBlob won't fetch extra unnecessary blobs.
     *
     * @group        Integration
     * @group        OneVisitorTwoVisits
     */
    public function testArchiveSingleGetBlob()
    {
        $archive = Archive::build(self::$fixture->idSite, 'day', self::$fixture->dateTime);
        $cache = $archive->getBlob('Actions_actions', 'all');

        $foundSubtable = false;

        $this->assertTrue(count($cache) > 0, "empty blob cache");
        foreach ($cache as $name => $value) {
            $this->assertTrue(strpos($name, "Actions_actions_url") === false, "found blob w/ name '$name'");

            if (strpos($name, "Actions_actions_") !== false) {
                $foundSubtable = true;
            }
        }

        $this->assertTrue($foundSubtable, "Actions_actions subtable was not loaded");
    }
    
    /**
     * Test that restricting the number of sites to those viewable to another login
     * works when building an archive query object.
     * 
     * @group        Integration
     * @group        OneVisitorTwoVisits
     */
    public function testArchiveSitesWhenRestrictingToLogin()
    {
        try
        {
            Archive::build(
                'all', 'day', self::$fixture->dateTime, $segment = false, $_restrictToLogin = 'anotherLogin');
            $this->fail("Restricting sites to invalid login did not return 0 sites.");
        }
        catch (Exception $ex)
        {
            // pass
        }
    }
}

Test_Piwik_Integration_OneVisitorTwoVisits::$fixture = new Test_Piwik_Fixture_OneVisitorTwoVisits();
Test_Piwik_Integration_OneVisitorTwoVisits::$fixture->excludeMozilla = true;