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