3 * @copyright Copyright (C) 2020, Friendica
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\PConfig;
24 use Friendica\Core\PConfig\JitPConfig;
25 use Friendica\Test\src\Core\PConfig\PConfigTest;
27 class JitPConfigTest extends PConfigTest
29 public function getInstance()
31 return new JitPConfig($this->configCache, $this->configModel);
35 * @dataProvider dataConfigLoad
37 public function testLoad(int $uid, array $data, array $possibleCats, array $load)
39 $this->configModel->shouldReceive('isConnected')
41 ->times(count($load));
43 foreach ($load as $loadCat) {
44 $this->configModel->shouldReceive('load')
45 ->with($uid, $loadCat)
46 ->andReturn([$loadCat => $data[$loadCat]])
50 parent::testLoad($uid, $data, $possibleCats, $load);
54 * @dataProvider dataDoubleLoad
56 public function testCacheLoadDouble(int $uid, array $data1, array $data2, array $expect)
58 $this->configModel->shouldReceive('isConnected')
60 ->times(count($data1) + count($data2));
62 foreach ($data1 as $cat => $data) {
63 $this->configModel->shouldReceive('load')
65 ->andReturn([$cat => $data])
70 foreach ($data2 as $cat => $data) {
71 $this->configModel->shouldReceive('load')
73 ->andReturn([$cat => $data])
77 parent::testCacheLoadDouble($uid, $data1, $data2, $expect);
79 // Assert the expected categories
80 foreach ($data2 as $cat => $data) {
81 $this->assertConfig($uid, $cat, $expect[$cat]);
86 * @dataProvider dataTests
88 public function testSetGetWithoutDB(int $uid, $data)
90 $this->configModel->shouldReceive('isConnected')
94 parent::testSetGetWithoutDB($uid, $data);
98 * @dataProvider dataTests
100 public function testSetGetWithDB(int $uid, $data)
102 $this->configModel->shouldReceive('isConnected')
106 parent::testSetGetWithDB($uid, $data);
110 * @dataProvider dataTests
112 public function testGetWithRefresh(int $uid, $data)
114 $this->configModel->shouldReceive('isConnected')
118 // mocking one get without result
119 $this->configModel->shouldReceive('get')
120 ->with($uid, 'test', 'it')
124 // mocking the data get
125 $this->configModel->shouldReceive('get')
126 ->with($uid, 'test', 'it')
130 // mocking second get
131 $this->configModel->shouldReceive('get')
132 ->with($uid, 'test', 'not')
136 parent::testGetWithRefresh($uid, $data);
140 * @dataProvider dataTests
142 public function testDeleteWithoutDB(int $uid, $data)
144 $this->configModel->shouldReceive('isConnected')
148 parent::testDeleteWithoutDB($uid, $data);
151 public function testDeleteWithDB()
153 $this->configModel->shouldReceive('isConnected')
157 // mocking one get without result
158 $this->configModel->shouldReceive('get')
159 ->with(42, 'test', 'it')
163 parent::testDeleteWithDB();