]> git.mxchange.org Git - friendica.git/blob - tests/src/Core/Config/PreloadPConfigurationTest.php
Merge pull request #8079 from ozero/patch-1
[friendica.git] / tests / src / Core / Config / PreloadPConfigurationTest.php
1 <?php
2
3 namespace Friendica\Test\src\Core\Config;
4
5 use Friendica\Core\Config\PreloadPConfiguration;
6
7 class PreloadPConfigurationTest extends PConfigurationTest
8 {
9         public function getInstance()
10         {
11                 return new PreloadPConfiguration($this->configCache, $this->configModel);
12         }
13
14         /**
15          * @dataProvider dataConfigLoad
16          */
17         public function testLoad(int $uid, array $data, array $possibleCats, array $load)
18         {
19                 $this->configModel->shouldReceive('isConnected')
20                                   ->andReturn(true)
21                                   ->once();
22
23                 $this->configModel->shouldReceive('load')
24                                   ->with($uid)
25                                   ->andReturn($data)
26                                   ->once();
27
28                 parent::testLoad($uid, $data, $possibleCats, $load);
29
30                 // Assert that every category is loaded everytime
31                 foreach ($data as $cat => $values) {
32                         $this->assertConfig($uid, $cat, $values);
33                 }
34         }
35
36         /**
37          * @dataProvider dataDoubleLoad
38          */
39         public function testCacheLoadDouble(int $uid, array $data1, array $data2, array $expect)
40         {
41                 $this->configModel->shouldReceive('isConnected')
42                                   ->andReturn(true)
43                                   ->once();
44
45                 $this->configModel->shouldReceive('load')
46                                   ->with($uid)
47                                   ->andReturn($data1)
48                                   ->once();
49
50                 parent::testCacheLoadDouble($uid, $data1, $data2, $expect);
51
52                 // Assert that every category is loaded everytime and is NOT overwritten
53                 foreach ($data1 as $cat => $values) {
54                         $this->assertConfig($uid, $cat, $values);
55                 }
56         }
57
58         /**
59          * @dataProvider dataTests
60          */
61         public function testSetGetWithoutDB(int $uid, $data)
62         {
63                 $this->configModel->shouldReceive('isConnected')
64                                   ->andReturn(false)
65                                   ->times(3);
66
67                 parent::testSetGetWithoutDB($uid, $data);
68         }
69
70         /**
71          * @dataProvider dataTests
72          */
73         public function testSetGetWithDB(int $uid, $data)
74         {
75                 $this->configModel->shouldReceive('isConnected')
76                                   ->andReturn(true)
77                                   ->twice();
78
79                 $this->configModel->shouldReceive('load')
80                                   ->with($uid)
81                                   ->andReturn(['config' => []])
82                                   ->once();
83
84                 parent::testSetGetWithDB($uid, $data);
85         }
86
87         /**
88          * @dataProvider dataTests
89          */
90         public function testGetWithRefresh(int $uid, $data)
91         {
92                 $this->configModel->shouldReceive('isConnected')
93                                   ->andReturn(true)
94                                   ->times(2);
95
96                 // constructor loading
97                 $this->configModel->shouldReceive('load')
98                                   ->with($uid)
99                                   ->andReturn(['config' => []])
100                                   ->once();
101
102                 // mocking one get
103                 $this->configModel->shouldReceive('get')
104                                   ->with($uid, 'test', 'it')
105                                   ->andReturn($data)
106                                   ->once();
107
108                 parent::testGetWithRefresh($uid, $data);
109         }
110
111         /**
112          * @dataProvider dataTests
113          */
114         public function testDeleteWithoutDB(int $uid, $data)
115         {
116                 $this->configModel->shouldReceive('isConnected')
117                                   ->andReturn(false)
118                                   ->times(4);
119
120                 parent::testDeleteWithoutDB($uid, $data);
121         }
122
123         public function testDeleteWithDB()
124         {
125                 $this->configModel->shouldReceive('isConnected')
126                                   ->andReturn(true)
127                                   ->times(5);
128
129                 // constructor loading
130                 $this->configModel->shouldReceive('load')
131                                   ->with(42)
132                                   ->andReturn(['config' => []])
133                                   ->once();
134
135                 parent::testDeleteWithDB();
136         }
137 }