]> git.mxchange.org Git - friendica.git/blob - tests/src/Core/Config/JitConfigTest.php
Merge pull request #9033 from nupplaphil/bug/travis
[friendica.git] / tests / src / Core / Config / JitConfigTest.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2020, Friendica
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 namespace Friendica\Test\src\Core\Config;
23
24 use Friendica\Core\Config\JitConfig;
25
26 class JitConfigTest extends ConfigTest
27 {
28         public function getInstance()
29         {
30                 return new JitConfig($this->configCache, $this->configModel);
31         }
32
33         /**
34          * @dataProvider dataConfigLoad
35          */
36         public function testSetUp(array $data)
37         {
38                 $this->configModel->shouldReceive('load')
39                                   ->with('config')
40                                   ->andReturn(['config' => $data['config']])
41                                   ->once();
42
43                 parent::testSetUp($data);
44         }
45
46         /**
47          * @dataProvider dataConfigLoad
48          */
49         public function testLoad(array $data, array $possibleCats, array $load)
50         {
51                 $this->configModel->shouldReceive('isConnected')
52                                   ->andReturn(true)
53                                   ->times(count($load) + 1);
54
55                 $this->configModel->shouldReceive('load')
56                                   ->with('config')
57                                   ->andReturn(['config' => $data['config']])
58                                   ->once();
59
60                 foreach ($load as $loadCat) {
61                         $this->configModel->shouldReceive('load')
62                                           ->with($loadCat)
63                                           ->andReturn([$loadCat => $data[$loadCat]])
64                                           ->once();
65                 }
66
67                 parent::testLoad($data, $possibleCats, $load);
68         }
69
70         /**
71          * @dataProvider dataDoubleLoad
72          */
73         public function testCacheLoadDouble(array $data1, array $data2, array $expect)
74         {
75                 $this->configModel->shouldReceive('isConnected')
76                                   ->andReturn(true)
77                                   ->times(count($data1) + count($data2) + 1);
78
79                 $this->configModel->shouldReceive('load')
80                                   ->with('config')
81                                   ->andReturn(['config' => $data1['config']])
82                                   ->once();
83
84                 foreach ($data1 as $cat => $data) {
85                         $this->configModel->shouldReceive('load')
86                                           ->with($cat)
87                                           ->andReturn([$cat => $data])
88                                           ->once();
89                 }
90
91
92                 foreach ($data2 as $cat => $data) {
93                         $this->configModel->shouldReceive('load')
94                                           ->with($cat)
95                                           ->andReturn([$cat => $data])
96                                           ->once();
97                 }
98
99                 parent::testCacheLoadDouble($data1, $data2, $expect);
100
101                 // Assert the expected categories
102                 foreach ($data2 as $cat => $data) {
103                         $this->assertConfig($cat, $expect[$cat]);
104                 }
105         }
106
107         /**
108          * @dataProvider dataTests
109          */
110         public function testSetGetWithDB($data)
111         {
112                 $this->configModel->shouldReceive('isConnected')
113                                   ->andReturn(true)
114                                   ->times(3);
115
116                 $this->configModel->shouldReceive('load')->with('config')->andReturn(['config' => []])->once();
117
118                 parent::testSetGetWithDB($data);
119         }
120
121         /**
122          * @dataProvider dataTests
123          */
124         public function testGetWithRefresh($data)
125         {
126                 $this->configModel->shouldReceive('isConnected')
127                                   ->andReturn(true)
128                                   ->times(4);
129
130                 // constructor loading
131                 $this->configModel->shouldReceive('load')
132                                   ->with('config')
133                                   ->andReturn(['config' => []])
134                                   ->once();
135
136                 // mocking one get without result
137                 $this->configModel->shouldReceive('get')
138                                   ->with('test', 'it')
139                                   ->andReturn(null)
140                                   ->once();
141
142                 // mocking the data get
143                 $this->configModel->shouldReceive('get')
144                                   ->with('test', 'it')
145                                   ->andReturn($data)
146                                   ->once();
147
148                 // mocking second get
149                 $this->configModel->shouldReceive('get')
150                                   ->with('test', 'not')
151                                   ->andReturn(null)
152                                   ->once();
153
154                 parent::testGetWithRefresh($data);
155         }
156
157         public function testGetWrongWithoutDB()
158         {
159                 $this->configModel->shouldReceive('isConnected')
160                                   ->andReturn(false)
161                                   ->times(4);
162
163                 parent::testGetWrongWithoutDB();
164         }
165
166         /**
167          * @dataProvider dataTests
168          */
169         public function testDeleteWithoutDB($data)
170         {
171                 $this->configModel->shouldReceive('isConnected')
172                                   ->andReturn(false)
173                                   ->times(4);
174
175                 parent::testDeleteWithoutDB($data);
176         }
177
178         public function testDeleteWithDB()
179         {
180                 $this->configModel->shouldReceive('isConnected')
181                                   ->andReturn(true)
182                                   ->times(6);
183
184                 // constructor loading
185                 $this->configModel->shouldReceive('load')
186                                   ->with('config')
187                                   ->andReturn(['config' => []])
188                                   ->once();
189
190                 // mocking one get without result
191                 $this->configModel->shouldReceive('get')
192                                   ->with('test', 'it')
193                                   ->andReturn(null)
194                                   ->once();
195
196                 parent::testDeleteWithDB();
197         }
198 }