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

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

namespace Piwik\Plugins\PrivacyManager\tests;

use Piwik\Option;
use Piwik\Plugins\PrivacyManager\Config as PrivacyManagerConfig;
use Piwik\Plugins\PrivacyManager\ReferrerAnonymizer;
use Piwik\Tests\Framework\TestCase\IntegrationTestCase;

/**
 * @group Plugins
 */
class PrivacyManagerConfigTest extends IntegrationTestCase
{
    /**
     * @var PrivacyManagerConfig
     */
    private $config;

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

        $this->config = new PrivacyManagerConfig();
    }

    public function test_useAnonymizedIpForVisitEnrichment()
    {
        $this->assertFalse($this->config->useAnonymizedIpForVisitEnrichment);

        $this->config->useAnonymizedIpForVisitEnrichment = true;

        $this->assertTrue($this->config->useAnonymizedIpForVisitEnrichment);

        $this->config->useAnonymizedIpForVisitEnrichment = false;

        $this->assertFalse($this->config->useAnonymizedIpForVisitEnrichment);
    }

    public function test_doNotTrackEnabled()
    {
        $this->assertTrue($this->config->doNotTrackEnabled);

        $this->config->doNotTrackEnabled = true;

        $this->assertTrue($this->config->doNotTrackEnabled);

        $this->config->doNotTrackEnabled = false;

        $this->assertFalse($this->config->doNotTrackEnabled);
    }

    public function test_ipAnonymizerEnabled()
    {
        $this->assertTrue($this->config->ipAnonymizerEnabled);

        $this->config->ipAnonymizerEnabled = false;

        $this->assertFalse($this->config->ipAnonymizerEnabled);
    }

    public function test_ipAddressMaskLength()
    {
        $this->assertSame(2, $this->config->ipAddressMaskLength);

        $this->config->ipAddressMaskLength = '19';

        $this->assertSame(19, $this->config->ipAddressMaskLength);
    }

    public function test_anonymizeOrderId()
    {
        $this->assertFalse($this->config->anonymizeOrderId);

        $this->config->anonymizeOrderId = true;

        $this->assertTrue($this->config->anonymizeOrderId);
    }

    public function test_anonymizeUserId()
    {
        $this->assertFalse($this->config->anonymizeUserId);

        $this->config->anonymizeUserId = true;

        $this->assertTrue($this->config->anonymizeUserId);
    }

    public function test_anonymizeReferrer()
    {
        $this->assertSame('', $this->config->anonymizeReferrer);

        $this->config->anonymizeReferrer = ReferrerAnonymizer::EXCLUDE_PATH;

        $this->assertSame(ReferrerAnonymizer::EXCLUDE_PATH, $this->config->anonymizeReferrer);
    }

    public function test_setTrackerCacheContent()
    {
        $content = $this->config->setTrackerCacheGeneral(array('existingEntry' => 'test'));

        $expected = array(
            'existingEntry' => 'test',
            'PrivacyManager.ipAddressMaskLength' => 2,
            'PrivacyManager.ipAnonymizerEnabled' => true,
            'PrivacyManager.doNotTrackEnabled'   => true,
            'PrivacyManager.anonymizeUserId'     => false,
            'PrivacyManager.anonymizeOrderId'    => false,
            'PrivacyManager.anonymizeReferrer'   => '',
            'PrivacyManager.useAnonymizedIpForVisitEnrichment' => false,
        );

        $this->assertEquals($expected, $content);
    }

    public function test_setTrackerCacheContent_ShouldGetValuesFromConfig()
    {
        Option::set('PrivacyManager.ipAddressMaskLength', '232');

        $content = $this->config->setTrackerCacheGeneral(array('existingEntry' => 'test'));

        $this->assertEquals(232, $content['PrivacyManager.ipAddressMaskLength']);
    }

}