]> git.mxchange.org Git - friendica.git/blob - tests/src/Core/Config/JitConfigurationTest.php
Improve & fixing Tests
[friendica.git] / tests / src / Core / Config / JitConfigurationTest.php
1 <?php
2
3 namespace Friendica\Test\src\Core\Config;
4
5 use Friendica\Core\Config\JitConfiguration;
6
7 class JitConfigurationTest extends ConfigurationTest
8 {
9         public function getInstance()
10         {
11                 return new JitConfiguration($this->configCache, $this->configModel);
12         }
13
14         /**
15          * @dataProvider dataConfigLoad
16          */
17         public function testSetUp(array $data)
18         {
19                 $this->configModel->shouldReceive('load')
20                                   ->with('config')
21                                   ->andReturn(['config' => $data['config']])
22                                   ->once();
23
24                 parent::testSetUp($data);
25         }
26
27         /**
28          * @dataProvider dataConfigLoad
29          */
30         public function testLoad(array $data, array $possibleCats, array $load)
31         {
32                 $this->configModel->shouldReceive('isConnected')
33                                   ->andReturn(true)
34                                   ->times(count($load) + 1);
35
36                 $this->configModel->shouldReceive('load')
37                                   ->with('config')
38                                   ->andReturn(['config' => $data['config']])
39                                   ->once();
40
41                 foreach ($load as $loadCat) {
42                         $this->configModel->shouldReceive('load')
43                                           ->with($loadCat)
44                                           ->andReturn([$loadCat => $data[$loadCat]])
45                                           ->once();
46                 }
47
48                 parent::testLoad($data, $possibleCats, $load);
49         }
50
51         /**
52          * @dataProvider dataDoubleLoad
53          */
54         public function testCacheLoadDouble(array $data1, array $data2, array $expect)
55         {
56                 $this->configModel->shouldReceive('isConnected')
57                                   ->andReturn(true)
58                                   ->times(count($data1) + count($data2) + 1);
59
60                 $this->configModel->shouldReceive('load')
61                                   ->with('config')
62                                   ->andReturn(['config' => $data1['config']])
63                                   ->once();
64
65                 foreach ($data1 as $cat => $data) {
66                         $this->configModel->shouldReceive('load')
67                                           ->with($cat)
68                                           ->andReturn([$cat => $data])
69                                           ->once();
70                 }
71
72
73                 foreach ($data2 as $cat => $data) {
74                         $this->configModel->shouldReceive('load')
75                                           ->with($cat)
76                                           ->andReturn([$cat => $data])
77                                           ->once();
78                 }
79
80                 parent::testCacheLoadDouble($data1, $data2, $expect);
81
82                 // Assert the expected categories
83                 foreach ($data2 as $cat => $data) {
84                         $this->assertConfig($cat, $expect[$cat]);
85                 }
86         }
87
88         /**
89          * @dataProvider dataTests
90          */
91         public function testSetGetWithDB($data)
92         {
93                 $this->configModel->shouldReceive('isConnected')
94                                   ->andReturn(true)
95                                   ->times(3);
96
97                 $this->configModel->shouldReceive('load')->with('config')->andReturn(['config' => []])->once();
98
99                 parent::testSetGetWithDB($data);
100         }
101
102         /**
103          * @dataProvider dataTests
104          */
105         public function testGetWithRefresh($data)
106         {
107                 $this->configModel->shouldReceive('isConnected')
108                                   ->andReturn(true)
109                                   ->times(4);
110
111                 // constructor loading
112                 $this->configModel->shouldReceive('load')
113                                   ->with('config')
114                                   ->andReturn(['config' => []])
115                                   ->once();
116
117                 // mocking one get
118                 $this->configModel->shouldReceive('get')
119                                   ->with('test', 'it')
120                                   ->andReturn($data)
121                                   ->once();
122
123                 // mocking second get
124                 $this->configModel->shouldReceive('get')
125                                   ->with('test', 'not')
126                                   ->andReturn(null)
127                                   ->once();
128
129                 parent::testGetWithRefresh($data);
130         }
131
132         public function testGetWrongWithoutDB()
133         {
134                 $this->configModel->shouldReceive('isConnected')
135                                   ->andReturn(false)
136                                   ->times(4);
137
138                 parent::testGetWrongWithoutDB();
139         }
140
141         /**
142          * @dataProvider dataTests
143          */
144         public function testDeleteWithoutDB($data)
145         {
146                 $this->configModel->shouldReceive('isConnected')
147                                   ->andReturn(false)
148                                   ->times(4);
149
150                 parent::testDeleteWithoutDB($data);
151         }
152
153         public function testDeleteWithDB()
154         {
155                 $this->configModel->shouldReceive('isConnected')
156                                   ->andReturn(true)
157                                   ->times(6);
158
159                 // constructor loading
160                 $this->configModel->shouldReceive('load')
161                                   ->with('config')
162                                   ->andReturn(['config' => []])
163                                   ->once();
164
165                 parent::testDeleteWithDB();
166         }
167 }