]> git.mxchange.org Git - friendica.git/blob - tests/src/Core/PConfig/JitPConfigTest.php
Merge pull request #11195 from annando/issue-10966
[friendica.git] / tests / src / Core / PConfig / JitPConfigTest.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2022, the Friendica project
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\PConfig;
23
24 use Friendica\Core\PConfig\Type\JitPConfig;
25
26 class JitPConfigTest extends PConfigTest
27 {
28         public function getInstance()
29         {
30                 return new JitPConfig($this->configCache, $this->configModel);
31         }
32
33         /**
34          * @dataProvider dataConfigLoad
35          */
36         public function testLoad(int $uid, array $data, array $possibleCats, array $load)
37         {
38                 $this->configModel->shouldReceive('isConnected')
39                                   ->andReturn(true)
40                                   ->times(count($load));
41
42                 foreach ($load as $loadCat) {
43                         $this->configModel->shouldReceive('load')
44                                           ->with($uid, $loadCat)
45                                           ->andReturn([$loadCat => $data[$loadCat]])
46                                           ->once();
47                 }
48
49                 parent::testLoad($uid, $data, $possibleCats, $load);
50         }
51
52         /**
53          * @dataProvider dataDoubleLoad
54          */
55         public function testCacheLoadDouble(int $uid, array $data1, array $data2, array $expect)
56         {
57                 $this->configModel->shouldReceive('isConnected')
58                                   ->andReturn(true)
59                                   ->times(count($data1) + count($data2));
60
61                 foreach ($data1 as $cat => $data) {
62                         $this->configModel->shouldReceive('load')
63                                           ->with($uid, $cat)
64                                           ->andReturn([$cat => $data])
65                                           ->once();
66                 }
67
68
69                 foreach ($data2 as $cat => $data) {
70                         $this->configModel->shouldReceive('load')
71                                           ->with($uid, $cat)
72                                           ->andReturn([$cat => $data])
73                                           ->once();
74                 }
75
76                 parent::testCacheLoadDouble($uid, $data1, $data2, $expect);
77
78                 // Assert the expected categories
79                 foreach ($data2 as $cat => $data) {
80                         self::assertConfig($uid, $cat, $expect[$cat]);
81                 }
82         }
83
84         /**
85          * @dataProvider dataTests
86          */
87         public function testSetGetWithoutDB(int $uid, $data)
88         {
89                 $this->configModel->shouldReceive('isConnected')
90                                   ->andReturn(false)
91                                   ->times(2);
92
93                 parent::testSetGetWithoutDB($uid, $data);
94         }
95
96         /**
97          * @dataProvider dataTests
98          */
99         public function testSetGetWithDB(int $uid, $data)
100         {
101                 $this->configModel->shouldReceive('isConnected')
102                                   ->andReturn(true)
103                                   ->times(2);
104
105                 parent::testSetGetWithDB($uid, $data);
106         }
107
108         /**
109          * @dataProvider dataTests
110          */
111         public function testGetWithRefresh(int $uid, $data)
112         {
113                 $this->configModel->shouldReceive('isConnected')
114                                   ->andReturn(true)
115                                   ->times(3);
116
117                 // mocking one get without result
118                 $this->configModel->shouldReceive('get')
119                                   ->with($uid, 'test', 'it')
120                                   ->andReturn(null)
121                                   ->once();
122
123                 // mocking the data get
124                 $this->configModel->shouldReceive('get')
125                                   ->with($uid, 'test', 'it')
126                                   ->andReturn($data)
127                                   ->once();
128
129                 // mocking second get
130                 $this->configModel->shouldReceive('get')
131                                   ->with($uid, 'test', 'not')
132                                   ->andReturn(null)
133                                   ->once();
134
135                 parent::testGetWithRefresh($uid, $data);
136         }
137
138         /**
139          * @dataProvider dataTests
140          */
141         public function testDeleteWithoutDB(int $uid, $data)
142         {
143                 $this->configModel->shouldReceive('isConnected')
144                                   ->andReturn(false)
145                                   ->times(3);
146
147                 parent::testDeleteWithoutDB($uid, $data);
148         }
149
150         public function testDeleteWithDB()
151         {
152                 $this->configModel->shouldReceive('isConnected')
153                                   ->andReturn(true)
154                                   ->times(5);
155
156                 // mocking one get without result
157                 $this->configModel->shouldReceive('get')
158                                   ->with(42, 'test', 'it')
159                                   ->andReturn(null)
160                                   ->once();
161
162                 parent::testDeleteWithDB();
163         }
164 }