]> git.mxchange.org Git - friendica.git/blob - tests/src/Core/Config/JitConfigurationTest.php
Move L10n class from L10n subdir to Core (replacing old wrapper)
[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 without result
118                 $this->configModel->shouldReceive('get')
119                                   ->with('test', 'it')
120                                   ->andReturn(null)
121                                   ->once();
122
123                 // mocking the data get
124                 $this->configModel->shouldReceive('get')
125                                   ->with('test', 'it')
126                                   ->andReturn($data)
127                                   ->once();
128
129                 // mocking second get
130                 $this->configModel->shouldReceive('get')
131                                   ->with('test', 'not')
132                                   ->andReturn(null)
133                                   ->once();
134
135                 parent::testGetWithRefresh($data);
136         }
137
138         public function testGetWrongWithoutDB()
139         {
140                 $this->configModel->shouldReceive('isConnected')
141                                   ->andReturn(false)
142                                   ->times(4);
143
144                 parent::testGetWrongWithoutDB();
145         }
146
147         /**
148          * @dataProvider dataTests
149          */
150         public function testDeleteWithoutDB($data)
151         {
152                 $this->configModel->shouldReceive('isConnected')
153                                   ->andReturn(false)
154                                   ->times(4);
155
156                 parent::testDeleteWithoutDB($data);
157         }
158
159         public function testDeleteWithDB()
160         {
161                 $this->configModel->shouldReceive('isConnected')
162                                   ->andReturn(true)
163                                   ->times(6);
164
165                 // constructor loading
166                 $this->configModel->shouldReceive('load')
167                                   ->with('config')
168                                   ->andReturn(['config' => []])
169                                   ->once();
170
171                 // mocking one get without result
172                 $this->configModel->shouldReceive('get')
173                                   ->with('test', 'it')
174                                   ->andReturn(null)
175                                   ->once();
176
177                 parent::testDeleteWithDB();
178         }
179 }