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