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

SettingsTest.php « Tracker « Integration « PHPUnit « tests - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: fa2dee2969d7797a3139bf359d4d0d568717f599 (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
<?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\Integration\Tracker;

use Piwik\Tests\Framework\Fixture;
use Piwik\Tracker\Cache;
use Piwik\Tests\Framework\TestCase\IntegrationTestCase;
use Piwik\Tracker\Request;
use Piwik\Tracker\Settings;

/**
 * @group SettingsTest
 * @group TrackerVisitSettingsTest
 * @group Tracker
 */
class SettingsTest extends IntegrationTestCase
{
    /**
     * @var string
     */
    protected $ip = '123.30.30.30';

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

        Fixture::createWebsite('2014-01-01 00:00:00');
        Fixture::createWebsite('2014-01-01 00:00:00');
        Cache::deleteTrackerCache();

        $_SERVER['HTTP_USER_AGENT'] = '';
    }

    public function test_getConfigId_isSame()
    {
        $settings1 = $this->makeSettings(array('idsite' => 1));
        $settings2 = $this->makeSettings(array('idsite' => 1));

        $this->assertEquals($settings1->getConfigId(), $settings2->getConfigId());
    }


    public function test_getConfigId_isSame_whenConfiguredUserHasSameFingerprintAcrossWebsites()
    {
        $isSameFingerprintAcrossWebsites = true;

        $settingsSite1 = $this->makeSettings(array('idsite' => 1), $isSameFingerprintAcrossWebsites);
        $settingsSite2 = $this->makeSettings(array('idsite' => 2), $isSameFingerprintAcrossWebsites);

        $this->assertEquals($settingsSite1->getConfigId(), $settingsSite2->getConfigId());
    }

    public function test_getConfigId_isDifferent_whenConfiguredUserHasDifferentFingerprintAcrossWebsites()
    {
        $isSameFingerprintAcrossWebsites = false;

        $settingsSite1 = $this->makeSettings(array('idsite' => 1), $isSameFingerprintAcrossWebsites);
        $settingsSite2 = $this->makeSettings(array('idsite' => 2), $isSameFingerprintAcrossWebsites);

        $this->assertNotSame($settingsSite1->getConfigId(), $settingsSite2->getConfigId());
    }

    public function test_getConfigId_isSame_whenBrowserSamebutDifferentUserAgent()
    {
        $settingsFirefox = $this->makeSettings(array('ua' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10; rv:33.0) Gecko/20100101 Firefox/33.0'));
        $settingsSlightlyDifferentUserAgent = $this->makeSettings(array('ua' => 'Mozilla/5.0 (Macintosh; Extra; string; here; Hello; world; Intel Mac OS X 10_10; rv:33.0) Gecko/20100101 Firefox/33.0'));

        $this->assertSame($settingsSlightlyDifferentUserAgent->getConfigId(), $settingsFirefox->getConfigId());
    }

    public function test_getConfigId_isDifferent_whenBrowserChanges()
    {
        $settingsFirefox = $this->makeSettings(array('ua' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10; rv:33.0) Gecko/20100101 Firefox/33.0'));
        $settingsChrome = $this->makeSettings(array('ua' => 'Mozilla/5.0 (Linux; Android 4.0.4; Galaxy Nexus Build/IMM76B) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.133 Mobile Safari/535.19 '));

        $this->assertNotSame($settingsChrome->getConfigId(), $settingsFirefox->getConfigId());
    }

    public function test_getConfigId_isDifferent_whenOSChanges()
    {
        $settingsFirefoxMac = $this->makeSettings(array('ua' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10; rv:33.0) Gecko/20100101 Firefox/33.0'));
        $settingsFirefoxLinux = $this->makeSettings(array('ua' => 'Mozilla/5.0 (Linux; rv:33.0) Gecko/20100101 Firefox/33.0'));

        $this->assertNotSame($settingsFirefoxLinux->getConfigId(), $settingsFirefoxMac->getConfigId());
    }

    public function test_getConfigId_isDifferent_whenPluginChanges()
    {
        $params = array(
            'pdf' => 1,
            'cookie' => 1,
            'fla' => 0,
            'idsite' => 1,
        );
        $settingsWithoutFlash = $this->makeSettings($params);

        // activate flash
        $params['fla'] = 1;
        $settingsWithFlash = $this->makeSettings($params);

        $this->assertNotSame($settingsWithoutFlash->getConfigId(), $settingsWithFlash->getConfigId());
    }

    public function test_getConfigId_isDifferent_whenIPIsAnonimised()
    {
        $settingsIpIsNotAnon = $this->makeSettings(array(), true, '125.1.55.55');
        $settingsIpIsAnon = $this->makeSettings(array(), true, '125.1.0.0');

        $this->assertNotSame($settingsIpIsNotAnon->getConfigId(), $settingsIpIsAnon->getConfigId());
    }

    public function test_getConfigId_isSame_whenIPIsAnonimisedAndBothSame()
    {
        $settingsIpIsNotAnon = $this->makeSettings(array(), true, '125.2.0.0');
        $settingsIpIsAnon = $this->makeSettings(array(), true, '125.2.0.0');

        $this->assertSame($settingsIpIsNotAnon->getConfigId(), $settingsIpIsAnon->getConfigId());
    }

    /**
     * @param $params array
     * @param $isSameFingerprintAcrossWebsites
     * @param $ip
     * @return Settings
     */
    protected function makeSettings($params, $isSameFingerprintAcrossWebsites = false, $ip = null)
    {
        if(is_null($ip)) {
            $ip = $this->ip;
        }
        $requestSite1 = $this->makeRequest($params);
        $settingsSite1 = new Settings($requestSite1, $ip, $isSameFingerprintAcrossWebsites);
        return $settingsSite1;
    }

    /**
     * @param $extraParams array
     * @return array
     */
    private function makeRequest($extraParams)
    {
        // default
        $params = array(
            'pdf' => 1,
            'cookie' => 1,
            'fla' => 0,
            'idsite' => 1,
        );
        $params = array_merge($params, $extraParams);
        $request = new Request($params);
        return $request;
    }
}