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

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

use Piwik\Common;
use Piwik\Db;
use Piwik\Plugins\CoreUpdater\CoreUpdater;
use Piwik\Plugins\VisitFrequency\API as VisitFrequencyApi;
use Piwik\Updater;

/**
 * Tests that Piwik 2.0 works w/ data from Piwik 1.12.
 */
class Test_Piwik_Integration_BackwardsCompatibility1XTest extends IntegrationTestCase
{
    const FIXTURE_LOCATION = '/tests/resources/piwik-1.13-dump.sql';

    public static $fixture = null; // initialized below class

    public static function setUpBeforeClass()
    {
        parent::setUpBeforeClass();

        self::updateDatabase();

        // truncate log tables so old data won't be re-archived
        foreach (array('log_visit', 'log_link_visit_action', 'log_conversion', 'log_conversion_item') as $table) {
            Db::query("TRUNCATE TABLE " . Common::prefixTable($table));
        }

        // add two visits from same visitor on dec. 29
        $t = Fixture::getTracker(1, '2012-12-29 01:01:30', $defaultInit = true);
        $t->setUrl('http://site.com/index.htm');
        $t->setIp('136.5.3.2');
        Fixture::checkResponse($t->doTrackPageView('incredible title!'));

        $t->setForceVisitDateTime('2012-12-29 03:01:30');
        $t->setUrl('http://site.com/other/index.htm');
        $t->DEBUG_APPEND_URL = '&_idvc=2'; // make sure visit is marked as returning
        Fixture::checkResponse($t->doTrackPageView('other incredible title!'));

        // launch archiving
        VisitFrequencyApi::getInstance()->get(1, 'year', '2012-12-29');
    }

    private static function updateDatabase()
    {
        $updater = new Updater();
        $componentsWithUpdateFile = CoreUpdater::getComponentUpdates($updater);
        if (empty($componentsWithUpdateFile)) {
            throw new \Exception("Failed to update pre-2.0 database (nothing to update).");
        }

        $result = CoreUpdater::updateComponents($updater, $componentsWithUpdateFile);
        if (!empty($result['coreError'])
            && !empty($result['warnings'])
            && !empty($result['errors'])
        ) {
            throw new \Exception("Failed to update pre-2.0 database (errors or warnings found): " . print_r($result, true));
        }
    }

    public function setUp()
    {
        parent::setUp();

        $this->defaultApiNotToCall[] = 'Referrers';

        // changes made to SQL dump to test VisitFrequency change the day of week
        $this->defaultApiNotToCall[] = 'VisitTime.getByDayOfWeek';

        // we test VisitFrequency explicitly
        $this->defaultApiNotToCall[] = 'VisitFrequency.get';
    }

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

    public function getApiForTesting()
    {
        $idSite = 1;
        $dateTime = '2012-03-06 11:22:33';

        return array(
            array('all', array('idSite' => $idSite, 'date' => $dateTime,
                               'compareAgainst' => 'OneVisitorTwoVisits',
                               'disableArchiving' => true,

                               // the Action.getPageTitles test fails for unknown reason, so skipping it
                               // eg. https://travis-ci.org/piwik/piwik/jobs/24449365
                               'skipGetPageTitles' => true )),

            array('VisitFrequency.get', array('idSite' => $idSite, 'date' => '2012-03-03', 'setDateLastN' => true,
                                              'disableArchiving' => true, 'testSuffix' => '_multipleDates')),

            array('VisitFrequency.get', array('idSite' => $idSite, 'date' => $dateTime,
                                              'periods' => array('day', 'week', 'month', 'year'),
                                              'disableArchiving' => false)),

            array('VisitFrequency.get', array('idSite' => $idSite, 'date' => '2012-03-06,2012-12-31',
                                              'periods' => array('range'), 'disableArchiving' => true)),

            array('VisitFrequency.get', array('idSite' => $idSite, 'date' => '2012-03-03,2012-12-12', 'periods' => array('month'),
                                              'testSuffix' => '_multipleOldNew', 'disableArchiving' => true))
        );
    }
}

Test_Piwik_Integration_BackwardsCompatibility1XTest::$fixture = new Piwik_Test_Fixture_SqlDump();
Test_Piwik_Integration_BackwardsCompatibility1XTest::$fixture->dumpUrl =
    PIWIK_INCLUDE_PATH . Test_Piwik_Integration_BackwardsCompatibility1XTest::FIXTURE_LOCATION;
Test_Piwik_Integration_BackwardsCompatibility1XTest::$fixture->tablesPrefix = 'piwiktests_';