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