]> git.mxchange.org Git - friendica.git/blob - tests/src/Core/Config/ConfigCacheTest.php
Merge pull request #6638 from Ixiter/develop-markdown-anchors
[friendica.git] / tests / src / Core / Config / ConfigCacheTest.php
1 <?php
2
3 namespace Friendica\Test\Core\Config;
4
5 use Friendica\Core\Config\ConfigCache;
6 use Friendica\Test\MockedTest;
7
8 class ConfigCacheTest extends MockedTest
9 {
10         public function dataTests()
11         {
12                 return [
13                         'normal' => [
14                                 'data' => [
15                                         'system' => [
16                                                 'test' => 'it',
17                                                 'boolTrue' => true,
18                                                 'boolFalse' => false,
19                                                 'int' => 235,
20                                                 'dec' => 2.456,
21                                                 'array' => ['1', 2, '3', true, false],
22                                         ],
23                                         'config' => [
24                                                 'a' => 'value',
25                                         ],
26                                 ]
27                         ]
28                 ];
29         }
30
31         private function assertConfigValues($data, ConfigCache $configCache, $uid = null)
32         {
33                 foreach ($data as $cat => $values) {
34                         foreach ($values as $key => $value) {
35                                 if (isset($uid)) {
36                                         $this->assertEquals($data[$cat][$key], $configCache->getP($uid, $cat, $key));
37                                 } else {
38                                         $this->assertEquals($data[$cat][$key], $configCache->get($cat, $key));
39                                 }
40                         }
41                 }
42         }
43
44         /**
45          * Test the loadConfigArray() method without override
46          * @dataProvider dataTests
47          */
48         public function testLoadConfigArray($data)
49         {
50                 $configCache = new ConfigCache();
51                 $configCache->loadConfigArray($data);
52
53                 $this->assertConfigValues($data, $configCache);
54         }
55
56         /**
57          * Test the loadConfigArray() method with overrides
58          * @dataProvider dataTests
59          */
60         public function testLoadConfigArrayOverride($data)
61         {
62                 $override = [
63                         'system' => [
64                                 'test' => 'not',
65                                 'boolTrue' => false,
66                         ]
67                 ];
68
69                 $configCache = new ConfigCache();
70                 $configCache->loadConfigArray($data);
71                 $configCache->loadConfigArray($override);
72
73                 $this->assertConfigValues($data, $configCache);
74
75                 // override the value
76                 $configCache->loadConfigArray($override, true);
77
78                 $this->assertEquals($override['system']['test'], $configCache->get('system', 'test'));
79                 $this->assertEquals($override['system']['boolTrue'], $configCache->get('system', 'boolTrue'));
80         }
81
82         /**
83          * Test the getAll() method
84          * @dataProvider dataTests
85          */
86         public function testGetAll($data)
87         {
88                 $configCache = new ConfigCache();
89                 $configCache->loadConfigArray($data);
90
91                 $all = $configCache->getAll();
92
93                 $this->assertContains($data['system'], $all);
94
95                 // config values are stored directly in the array base
96                 $this->assertEquals($data['config']['a'], $all['a']);
97         }
98
99         /**
100          * Test the set() and get() method
101          * @dataProvider dataTests
102          */
103         public function testSetGet($data)
104         {
105                 $configCache = new ConfigCache();
106
107                 foreach ($data as $cat => $values) {
108                         foreach ($values as $key => $value) {
109                                 $configCache->set($cat, $key, $value);
110                         }
111                 }
112
113                 $this->assertConfigValues($data, $configCache);
114         }
115
116         /**
117          * Test the delete() method
118          * @dataProvider dataTests
119          */
120         public function testDelete($data)
121         {
122                 $configCache = new ConfigCache($data);
123
124                 foreach ($data as $cat => $values) {
125                         foreach ($values as $key => $value) {
126                                 $configCache->delete($cat, $key);
127                         }
128                 }
129
130                 $this->assertEmpty($configCache->getAll());
131         }
132
133         /**
134          * Test the setP() and getP() methods
135          * @dataProvider dataTests
136          */
137         public function testSetGetP($data)
138         {
139                 $configCache = new ConfigCache();
140                 $uid = 345;
141
142                 foreach ($data as $cat => $values) {
143                         foreach ($values as $key => $value) {
144                                 $configCache->setP($uid, $cat, $key, $value);
145                         }
146                 }
147
148                 $this->assertConfigValues($data, $configCache, $uid);
149         }
150
151
152         /**
153          * Test the deleteP() method
154          * @dataProvider dataTests
155          */
156         public function testDeleteP($data)
157         {
158                 $configCache = new ConfigCache();
159                 $uid = 345;
160
161                 foreach ($data as $cat => $values) {
162                         foreach ($values as $key => $value) {
163                                 $configCache->setP($uid, $cat, $key, $value);
164                         }
165                 }
166
167                 foreach ($data as $cat => $values) {
168                         foreach ($values as $key => $value) {
169                                 $configCache->deleteP($uid, $cat, $key);
170                         }
171                 }
172
173                 $this->assertEmpty($configCache->getAll());
174         }
175 }