3 namespace Friendica\Test\Core\Config\Cache;
5 use Friendica\Core\Config\Cache\ConfigCache;
6 use Friendica\Test\MockedTest;
8 class ConfigCacheTest extends MockedTest
10 public function dataTests()
21 'array' => ['1', 2, '3', true, false],
31 private function assertConfigValues($data, ConfigCache $configCache, $uid = null)
33 foreach ($data as $cat => $values) {
34 foreach ($values as $key => $value) {
36 $this->assertEquals($data[$cat][$key], $configCache->getP($uid, $cat, $key));
38 $this->assertEquals($data[$cat][$key], $configCache->get($cat, $key));
45 * Test the loadConfigArray() method without override
46 * @dataProvider dataTests
48 public function testLoadConfigArray($data)
50 $configCache = new ConfigCache();
51 $configCache->load($data);
53 $this->assertConfigValues($data, $configCache);
57 * Test the loadConfigArray() method with overrides
58 * @dataProvider dataTests
60 public function testLoadConfigArrayOverride($data)
69 $configCache = new ConfigCache();
70 $configCache->load($data);
71 $configCache->load($override);
73 $this->assertConfigValues($data, $configCache);
76 $configCache->load($override, true);
78 $this->assertEquals($override['system']['test'], $configCache->get('system', 'test'));
79 $this->assertEquals($override['system']['boolTrue'], $configCache->get('system', 'boolTrue'));
83 * Test the loadConfigArray() method with wrong/empty datasets
85 public function testLoadConfigArrayWrong()
87 $configCache = new ConfigCache();
90 $configCache->load([]);
91 $this->assertEmpty($configCache->getAll());
94 $configCache->load(['system' => 'not_array']);
95 $this->assertEmpty($configCache->getAll());
97 // incomplete dataset (key is integer ID of the array)
98 $configCache->load(['system' => ['value']]);
99 $this->assertEquals('value', $configCache->get('system', 0));
103 * Test the getAll() method
104 * @dataProvider dataTests
106 public function testGetAll($data)
108 $configCache = new ConfigCache();
109 $configCache->load($data);
111 $all = $configCache->getAll();
113 $this->assertContains($data['system'], $all);
114 $this->assertContains($data['config'], $all);
118 * Test the set() and get() method
119 * @dataProvider dataTests
121 public function testSetGet($data)
123 $configCache = new ConfigCache();
125 foreach ($data as $cat => $values) {
126 foreach ($values as $key => $value) {
127 $configCache->set($cat, $key, $value);
131 $this->assertConfigValues($data, $configCache);
135 * Test the get() method without a value
137 public function testGetEmpty()
139 $configCache = new ConfigCache();
141 $this->assertEquals('!<unset>!', $configCache->get('something', 'value'));
145 * Test the has() method
147 public function testHas()
149 $configCache = new ConfigCache();
151 $this->assertFalse($configCache->has('system', 'test'));
152 $this->assertFalse($configCache->has('system'));
154 $configCache->set('system', 'test', 'it');
155 $this->assertTrue($configCache->has('system', 'test'));
156 $this->assertTrue($configCache->has('system'));
160 * Test the get() method with a category
162 public function testGetCat()
164 $configCache = new ConfigCache([
174 $this->assertTrue($configCache->has('system'));
176 $this->assertEquals([
179 ], $configCache->get('system'));
183 * Test the delete() method
184 * @dataProvider dataTests
186 public function testDelete($data)
188 $configCache = new ConfigCache($data);
190 foreach ($data as $cat => $values) {
191 foreach ($values as $key => $value) {
192 $configCache->delete($cat, $key);
196 $this->assertEmpty($configCache->getAll());
200 * Test the setP() and getP() methods
201 * @dataProvider dataTests
203 public function testSetGetP($data)
205 $configCache = new ConfigCache();
208 foreach ($data as $cat => $values) {
209 foreach ($values as $key => $value) {
210 $configCache->setP($uid, $cat, $key, $value);
214 $this->assertConfigValues($data, $configCache, $uid);
219 * Test the getP() method with a category
221 public function testGetPCat()
223 $configCache = new ConfigCache();
226 $configCache->loadP($uid, [
236 $this->assertTrue($configCache->hasP($uid,'system'));
238 $this->assertEquals([
241 ], $configCache->get($uid, 'system'));
245 * Test the deleteP() method
246 * @dataProvider dataTests
248 public function testDeleteP($data)
250 $configCache = new ConfigCache();
253 foreach ($data as $cat => $values) {
254 foreach ($values as $key => $value) {
255 $configCache->setP($uid, $cat, $key, $value);
259 foreach ($data as $cat => $values) {
260 foreach ($values as $key => $value) {
261 $configCache->deleteP($uid, $cat, $key);
265 $this->assertEmpty($configCache->getAll());
269 * Test the hasP() method
271 public function testHasP()
273 $configCache = new ConfigCache();
276 $this->assertFalse($configCache->hasP($uid, 'system', 'test'));
277 $this->assertFalse($configCache->hasP($uid, 'system'));
279 $configCache->setP($uid, 'system', 'test', 'it');
280 $this->assertTrue($configCache->hasP($uid, 'system', 'test'));
281 $this->assertTrue($configCache->hasP($uid, 'system'));