3 * @copyright Copyright (C) 2010-2022, the Friendica project
5 * @license GNU AGPL version 3 or any later version
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.
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.
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/>.
22 namespace Friendica\Test\src\Core\Config;
24 use Friendica\Core\Config\Type\JitConfig;
26 class JitConfigTest extends ConfigTest
28 public function getInstance()
30 return new JitConfig($this->configCache, $this->configModel);
34 * @dataProvider dataConfigLoad
36 public function testSetUp(array $data)
38 $this->configModel->shouldReceive('load')
40 ->andReturn(['config' => $data['config']])
43 parent::testSetUp($data);
47 * @dataProvider dataConfigLoad
52 public function testLoad(array $data, array $load)
54 $this->configModel->shouldReceive('isConnected')
56 ->times(count($load) + 1);
58 $this->configModel->shouldReceive('load')
60 ->andReturn(['config' => $data['config']])
63 foreach ($load as $loadCat) {
64 $this->configModel->shouldReceive('load')
66 ->andReturn([$loadCat => $data[$loadCat]])
70 parent::testLoad($data, $load);
74 * @dataProvider dataDoubleLoad
76 public function testCacheLoadDouble(array $data1, array $data2, array $expect = [])
78 $this->configModel->shouldReceive('isConnected')
80 ->times(count($data1) + count($data2) + 1);
82 $this->configModel->shouldReceive('load')
84 ->andReturn(['config' => $data1['config']])
87 foreach ($data1 as $cat => $data) {
88 $this->configModel->shouldReceive('load')
90 ->andReturn([$cat => $data])
95 foreach ($data2 as $cat => $data) {
96 $this->configModel->shouldReceive('load')
98 ->andReturn([$cat => $data])
102 parent::testCacheLoadDouble($data1, $data2);
104 // Assert the expected categories
105 foreach ($data2 as $cat => $data) {
106 self::assertConfig($cat, $expect[$cat]);
111 * @dataProvider dataTests
113 public function testSetGetWithDB($data)
115 $this->configModel->shouldReceive('isConnected')
119 $this->configModel->shouldReceive('load')->with('config')->andReturn(['config' => []])->once();
121 parent::testSetGetWithDB($data);
125 * @dataProvider dataTests
127 public function testGetWithRefresh($data)
129 $this->configModel->shouldReceive('isConnected')
133 // constructor loading
134 $this->configModel->shouldReceive('load')
136 ->andReturn(['config' => []])
139 // mocking one get without result
140 $this->configModel->shouldReceive('get')
145 // mocking the data get
146 $this->configModel->shouldReceive('get')
151 // mocking second get
152 $this->configModel->shouldReceive('get')
153 ->with('test', 'not')
157 parent::testGetWithRefresh($data);
160 public function testGetWrongWithoutDB()
162 $this->configModel->shouldReceive('isConnected')
166 parent::testGetWrongWithoutDB();
170 * @dataProvider dataTests
172 public function testDeleteWithoutDB($data)
174 $this->configModel->shouldReceive('isConnected')
178 parent::testDeleteWithoutDB($data);
181 public function testDeleteWithDB()
183 $this->configModel->shouldReceive('isConnected')
187 // constructor loading
188 $this->configModel->shouldReceive('load')
190 ->andReturn(['config' => []])
193 // mocking one get without result
194 $this->configModel->shouldReceive('get')
199 parent::testDeleteWithDB();
202 public function testSetGetHighPrio()
204 $this->configModel->shouldReceive('isConnected')
207 // constructor loading
208 $this->configModel->shouldReceive('load')
210 ->andReturn(['config' => []])
213 $this->configModel->shouldReceive('get')
214 ->with('config', 'test')
218 $this->configModel->shouldReceive('set')
219 ->with('config', 'test', '123')
223 $this->configModel->shouldReceive('get')
224 ->with('config', 'test')
228 parent::testSetGetHighPrio();
231 public function testSetGetLowPrio()
233 $this->configModel->shouldReceive('isConnected')
236 // constructor loading
237 $this->configModel->shouldReceive('load')
239 ->andReturn(['config' => ['test' => 'it']])
242 $this->configModel->shouldReceive('set')
243 ->with('config', 'test', '123')
247 // mocking one get without result
248 $this->configModel->shouldReceive('get')
249 ->with('config', 'test')
253 parent::testSetGetLowPrio();