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

ConfigTest.php « Plugin « Core « PHPUnit « tests - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a6d2924d296d58466e915044018f8f04313cf2d3 (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
<?php
/**
 * Piwik - Open source web analytics
 *
 * @link http://piwik.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 */
class Plugin_ConfigTest extends PHPUnit_Framework_TestCase
{

    function setUp()
    {
        $path = PIWIK_USER_PATH . '/plugins/ExamplePlugin/config/local.config.php';
        if (file_exists($path))
        {
            @unlink($path);
        }

        $this->assertFalse(file_exists($path), 'unable to remove local.config.php');
    }

    /**
     * @group Core
     * @group Plugin
     * @group Plugin_Config
     */
    function testLoadWithNoConfig()
    {
        $objectUnderTest = new Piwik_Plugin_Config('ExamplePlugin');

        $this->assertFalse($objectUnderTest->load(), 'load() with no config should fail');
    }

    /**
     * @group Core
     * @group Plugin
     * @group Plugin_Config
     */
    function testLoadAlternatePath()
    {
        $objectUnderTest = new Piwik_Plugin_Config('ExamplePlugin', 'local.config.sample.php');
        $config = $objectUnderTest->load();

        $this->assertTrue($config !== false);
        $this->assertTrue($config['id'] === 'Example');
        $this->assertTrue($config['name'] === 'ExamplePlugin');
        $this->assertTrue($config['description'] === 'This is an example');
    }

    /**
     * @group Core
     * @group Plugin
     * @group Plugin_Config
     */
    function testLoad()
    {
        $dir = PIWIK_USER_PATH . '/plugins/ExamplePlugin/config';
        @copy($dir . '/local.config.sample.php', $dir . '/local.config.php');

        $objectUnderTest = new Piwik_Plugin_Config('ExamplePlugin');
        $config = $objectUnderTest->load();

        $this->assertTrue($config !== false);
        $this->assertTrue($config['id'] === 'Example');
        $this->assertTrue($config['name'] === 'ExamplePlugin');
        $this->assertTrue($config['description'] === 'This is an example');
    }

    /**
     * @group Core
     * @group Plugin
     * @group Plugin_Config
     */
    function testStore()
    {
        $config = array(
            1, 'mixed', array('a'), 'b' => 'c'
        );

        $objectUnderTest = new Piwik_Plugin_Config('ExamplePlugin');
        $objectUnderTest->store($config);

        $path = PIWIK_USER_PATH . '/plugins/ExamplePlugin/config/local.config.php';
        $this->assertTrue(file_exists($path));

        $objectUnderTest = new Piwik_Plugin_Config('ExamplePlugin');
        $newConfig = $objectUnderTest->load();

        $this->assertTrue($config !== false);
        $this->assertTrue($config[0] === 1);
        $this->assertTrue($config[1] === 'mixed');
        $this->assertTrue(is_array($config[2]) && $config[2][0] === 'a');
        $this->assertTrue($config['b'] === 'c');
    }
}