File size: 3,013 Bytes
a3a72f2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<?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\DeviceDetectorCache\tests\Integration;

use Piwik\Config;
use Piwik\Plugins\DeviceDetectorCache\Configuration;
use Piwik\Tests\Framework\TestCase\IntegrationTestCase;

/**
 * @group DeviceDetectorCache
 * @group ConfigurationTest
 * @group Configuration
 * @group Plugins
 */
class ConfigurationTest extends IntegrationTestCase
{
    /**
     * @var Configuration
     */
    private $configuration;

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

        $this->configuration = new Configuration();
        $this->configuration->install();
    }

    public function test_shouldInstallConfig()
    {
        $this->configuration->install();

        $configs = Config::getInstance()->DeviceDetectorCache;
        $this->assertEquals([
            'num_cache_entries' => '200000',
            'access_log_path'   => '/var/log/httpd/access_log',
            'access_log_regex'  => Configuration::DEFAULT_ACCESS_LOG_REGEX,
            'regex_match_entry' => 14,
        ], $configs);
    }

    public function test_getRegexMatchEntry()
    {
        $this->assertSame(Configuration::DEFAULT_ACCESS_LOG_REGEX_MATCH_ENTRY, $this->configuration->getRegexMatchEntry());
    }

    public function test_getRegexMatchEntry_customValue()
    {
        Config::getInstance()->DeviceDetectorCache = [
            Configuration::KEY_ACCESS_LOG_REGEX_MATCH_ENTRY => '5',
        ];
        $this->assertEquals(5, $this->configuration->getRegexMatchEntry());
    }

    public function test_getAccessLogPath()
    {
        $this->assertSame(Configuration::DEFAULT_ACCESS_LOG_PATH, $this->configuration->getAccessLogPath());
    }

    public function test_getAccessLogPath_customValue()
    {
        Config::getInstance()->DeviceDetectorCache = [
            Configuration::KEY_ACCESS_LOG_PATH => '/var/log/foo',
        ];
        $this->assertEquals('/var/log/foo', $this->configuration->getAccessLogPath());
    }

    public function test_getNumEntriesToCache()
    {
        $this->assertSame(Configuration::DEFAULT_NUM_ENTRIES_TO_CACHE, $this->configuration->getNumEntriesToCache());
    }

    public function test_getNumEntriesToCache_customValue()
    {
        Config::getInstance()->DeviceDetectorCache = [
            Configuration::KEY_NUM_ENTRIES_TO_CACHE => '145',
        ];
        $this->assertEquals(145, $this->configuration->getNumEntriesToCache());
    }

    public function test_getAccessLogRegex()
    {
        $this->assertSame(Configuration::DEFAULT_ACCESS_LOG_REGEX, $this->configuration->getAccessLogRegex());
    }

    public function test_getAccessLogRegex_customValue()
    {
        Config::getInstance()->DeviceDetectorCache = [
            Configuration::KEY_ACCESS_LOG_REGEX => '(.*)',
        ];
        $this->assertEquals('(.*)', $this->configuration->getAccessLogRegex());
    }
}