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