]> git.mxchange.org Git - friendica.git/blob - tests/src/Core/PConfig/PreloadPConfigTest.php
Merge pull request #11195 from annando/issue-10966
[friendica.git] / tests / src / Core / PConfig / PreloadPConfigTest.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\PreloadPConfig;
25
26 class PreloadPConfigTest extends PConfigTest
27 {
28         public function getInstance()
29         {
30                 return new \Friendica\Core\PConfig\Type\PreloadPConfig($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                                   ->once();
41
42                 $this->configModel->shouldReceive('load')
43                                   ->with($uid)
44                                   ->andReturn($data)
45                                   ->once();
46
47                 parent::testLoad($uid, $data, $possibleCats, $load);
48
49                 // Assert that every category is loaded everytime
50                 foreach ($data as $cat => $values) {
51                         self::assertConfig($uid, $cat, $values);
52                 }
53         }
54
55         /**
56          * @dataProvider dataDoubleLoad
57          */
58         public function testCacheLoadDouble(int $uid, array $data1, array $data2, array $expect)
59         {
60                 $this->configModel->shouldReceive('isConnected')
61                                   ->andReturn(true)
62                                   ->once();
63
64                 $this->configModel->shouldReceive('load')
65                                   ->with($uid)
66                                   ->andReturn($data1)
67                                   ->once();
68
69                 parent::testCacheLoadDouble($uid, $data1, $data2, $expect);
70
71                 // Assert that every category is loaded everytime and is NOT overwritten
72                 foreach ($data1 as $cat => $values) {
73                         self::assertConfig($uid, $cat, $values);
74                 }
75         }
76
77         /**
78          * @dataProvider dataTests
79          */
80         public function testSetGetWithoutDB(int $uid, $data)
81         {
82                 $this->configModel->shouldReceive('isConnected')
83                                   ->andReturn(false)
84                                   ->times(3);
85
86                 parent::testSetGetWithoutDB($uid, $data);
87         }
88
89         /**
90          * @dataProvider dataTests
91          */
92         public function testSetGetWithDB(int $uid, $data)
93         {
94                 $this->configModel->shouldReceive('isConnected')
95                                   ->andReturn(true)
96                                   ->twice();
97
98                 $this->configModel->shouldReceive('load')
99                                   ->with($uid)
100                                   ->andReturn(['config' => []])
101                                   ->once();
102
103                 parent::testSetGetWithDB($uid, $data);
104         }
105
106         /**
107          * @dataProvider dataTests
108          */
109         public function testGetWithRefresh(int $uid, $data)
110         {
111                 $this->configModel->shouldReceive('isConnected')
112                                   ->andReturn(true)
113                                   ->times(2);
114
115                 // constructor loading
116                 $this->configModel->shouldReceive('load')
117                                   ->with($uid)
118                                   ->andReturn(['config' => []])
119                                   ->once();
120
121                 // mocking one get
122                 $this->configModel->shouldReceive('get')
123                                   ->with($uid, 'test', 'it')
124                                   ->andReturn($data)
125                                   ->once();
126
127                 parent::testGetWithRefresh($uid, $data);
128         }
129
130         /**
131          * @dataProvider dataTests
132          */
133         public function testDeleteWithoutDB(int $uid, $data)
134         {
135                 $this->configModel->shouldReceive('isConnected')
136                                   ->andReturn(false)
137                                   ->times(4);
138
139                 parent::testDeleteWithoutDB($uid, $data);
140         }
141
142         public function testDeleteWithDB()
143         {
144                 $this->configModel->shouldReceive('isConnected')
145                                   ->andReturn(true)
146                                   ->times(5);
147
148                 // constructor loading
149                 $this->configModel->shouldReceive('load')
150                                   ->with(42)
151                                   ->andReturn(['config' => []])
152                                   ->once();
153
154                 parent::testDeleteWithDB();
155         }
156 }