summaryrefslogtreecommitdiffstats
path: root/tests/unit/config/AppConfigTest.php
blob: 01bacbf5c305d00a1aed3981b8fa5fba0e7a6584 (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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
<?php
/**
 * ownCloud - News
 *
 * This file is licensed under the Affero General Public License version 3 or
 * later. See the COPYING file.
 *
 * @author Alessandro Cosentino <cosenal@gmail.com>
 * @author Bernhard Posselt <dev@bernhard-posselt.com>
 * @copyright Alessandro Cosentino 2012
 * @copyright Bernhard Posselt 2012, 2014
 */

namespace OCA\News\Config;


class AppConfigTest extends \PHPUnit_Framework_TestCase {

    private $nav;
    private $config;
    private $url;

    public function setUp() {
        $this->nav = $this->getMockBuilder('\OCP\INavigationManager')
            ->disableOriginalConstructor()
            ->getMock();
        $this->url = $this->getMockBuilder('\OCP\IURLGenerator')
            ->disableOriginalConstructor()
            ->getMock();
        $phpVersion = '5.3';
        $ownCloudVersion = '6.0.3';
        $installedExtensions = ['curl' => '4.3'];
        $databaseType = 'oracle';

        $this->config = new AppConfig($this->nav, $this->url, $phpVersion,
            $ownCloudVersion, $installedExtensions, $databaseType);
    }

    public function testGetId() {
        $this->config->loadConfig(__DIR__ . '/../../../appinfo/app.json');
        $this->assertEquals('news', $this->config->getConfig('id'));
    }


    public function testGetConfig() {
        $config = file_get_contents(__DIR__ . '/../../../appinfo/app.json');
        $config = json_decode($config, true);
        $this->config->loadConfig($config);
        $config['navigation'] = [
            'id' => 'news',
            'order' => 10,
            'route' => 'news.page.index',
            'icon' => 'app.svg',
            'name' => 'News',
        ];
        $this->assertEquals($config, $this->config->getConfig());
    }


    public function testNoNavigation() {
        $this->config->loadConfig([]);

        $this->nav->expects($this->never())
            ->method('add');
    }


    public function testDefaultNavigation() {
        $expected = [
            'id' => 'news',
            'href' => 'news.page.index',
            'order' => 10,
            'icon' => 'app.svg',
            'name' => 'News'
        ];

        $this->url->expects($this->once())
            ->method('linkToRoute')
            ->with($this->equalTo('news.page.index'))
            ->will($this->returnValue('news.page.index'));

        $this->url->expects($this->once())
            ->method('imagePath')
            ->with($this->equalTo('news'),
                $this->equalTo('app.svg'))
            ->will($this->returnValue('app.svg'));

        $this->nav->expects($this->once())
            ->method('add')
            ->with($this->equalTo($expected));

        $this->config->loadConfig([
            'id' => 'news',
            'name' => 'News',
            'navigation' => []
        ]);
        $this->config->registerNavigation();
    }


    public function testCustomNavigation() {
        $expected = [
            'id' => 'abc',
            'href' => 'abc.page.index',
            'order' => 1,
            'icon' => 'test.svg',
            'name' => 'haha'
        ];

        $this->url->expects($this->once())
            ->method('linkToRoute')
            ->with($this->equalTo('abc.page.index'))
            ->will($this->returnValue('abc.page.index'));

        $this->url->expects($this->once())
            ->method('imagePath')
            ->with($this->equalTo('abc'),
                $this->equalTo('test.svg'))
            ->will($this->returnValue('test.svg'));

        $this->nav->expects($this->once())
            ->method('add')
            ->with($this->equalTo($expected));

        $this->config->loadConfig([
            'id' => 'abc',
            'name' => 'News',
            'navigation' => $expected
        ]);
        $this->config->registerNavigation();
    }


    /**
     * @expectedException \OCA\News\Config\DependencyException
     */
    public function testPHPVersion() {
        $this->config->loadConfig([
            'dependencies' => [
                'php' => '5.7'
            ]
        ]);
        $this->config->testDependencies();
    }


    /**
     * @expectedException \OCA\News\Config\DependencyException
     */
    public function testLibsVersion() {
        $this->config->loadConfig([
            'dependencies' => [
                'libs' => [
                    'curl' => '>=4.3,<=4.3'
                ]
            ]
        ]);
        $this->config->testDependencies();
    }


    /**
     * @expectedException \OCA\News\Config\DependencyException
     */
    public function testLibsExistence() {
        $this->config->loadConfig([
            'dependencies' => [
                'libs' => [
                    'dope' => '>=4.3,<=4.3'
                ]
            ]
        ]);
        $this->config->testDependencies();
    }



    /**
     * @expectedException \OCA\News\Config\DependencyException
     */
    public function testSupportedDb() {
        $this->config->loadConfig([
            'dependencies' => [
                "databases" => ['pgsql', 'sqlite']
            ]
        ]);
        $this->config->testDependencies();
    }
}