3 * @copyright Copyright (C) 2010-2021, 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\PConfig;
24 use Friendica\Core\PConfig\JitPConfig;
26 class JitPConfigTest extends PConfigTest
28 public function getInstance()
30 return new JitPConfig($this->configCache, $this->configModel);
34 * @dataProvider dataConfigLoad
36 public function testLoad(int $uid, array $data, array $possibleCats, array $load)
38 $this->configModel->shouldReceive('isConnected')
40 ->times(count($load));
42 foreach ($load as $loadCat) {
43 $this->configModel->shouldReceive('load')
44 ->with($uid, $loadCat)
45 ->andReturn([$loadCat => $data[$loadCat]])
49 parent::testLoad($uid, $data, $possibleCats, $load);
53 * @dataProvider dataDoubleLoad
55 public function testCacheLoadDouble(int $uid, array $data1, array $data2, array $expect)
57 $this->configModel->shouldReceive('isConnected')
59 ->times(count($data1) + count($data2));
61 foreach ($data1 as $cat => $data) {
62 $this->configModel->shouldReceive('load')
64 ->andReturn([$cat => $data])
69 foreach ($data2 as $cat => $data) {
70 $this->configModel->shouldReceive('load')
72 ->andReturn([$cat => $data])
76 parent::testCacheLoadDouble($uid, $data1, $data2, $expect);
78 // Assert the expected categories
79 foreach ($data2 as $cat => $data) {
80 self::assertConfig($uid, $cat, $expect[$cat]);
85 * @dataProvider dataTests
87 public function testSetGetWithoutDB(int $uid, $data)
89 $this->configModel->shouldReceive('isConnected')
93 parent::testSetGetWithoutDB($uid, $data);
97 * @dataProvider dataTests
99 public function testSetGetWithDB(int $uid, $data)
101 $this->configModel->shouldReceive('isConnected')
105 parent::testSetGetWithDB($uid, $data);
109 * @dataProvider dataTests
111 public function testGetWithRefresh(int $uid, $data)
113 $this->configModel->shouldReceive('isConnected')
117 // mocking one get without result
118 $this->configModel->shouldReceive('get')
119 ->with($uid, 'test', 'it')
123 // mocking the data get
124 $this->configModel->shouldReceive('get')
125 ->with($uid, 'test', 'it')
129 // mocking second get
130 $this->configModel->shouldReceive('get')
131 ->with($uid, 'test', 'not')
135 parent::testGetWithRefresh($uid, $data);
139 * @dataProvider dataTests
141 public function testDeleteWithoutDB(int $uid, $data)
143 $this->configModel->shouldReceive('isConnected')
147 parent::testDeleteWithoutDB($uid, $data);
150 public function testDeleteWithDB()
152 $this->configModel->shouldReceive('isConnected')
156 // mocking one get without result
157 $this->configModel->shouldReceive('get')
158 ->with(42, 'test', 'it')
162 parent::testDeleteWithDB();