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->assertNull($configCache->get('something', 'value'));
145 * Test the get() method with a category
147 public function testGetCat()
149 $configCache = new ConfigCache([
159 $this->assertEquals([
162 ], $configCache->get('system'));
166 * Test the delete() method
167 * @dataProvider dataTests
169 public function testDelete($data)
171 $configCache = new ConfigCache($data);
173 foreach ($data as $cat => $values) {
174 foreach ($values as $key => $value) {
175 $configCache->delete($cat, $key);
179 $this->assertEmpty($configCache->getAll());
183 * Test the setP() and getP() methods
184 * @dataProvider dataTests
186 public function testSetGetP($data)
188 $configCache = new ConfigCache();
191 foreach ($data as $cat => $values) {
192 foreach ($values as $key => $value) {
193 $configCache->setP($uid, $cat, $key, $value);
197 $this->assertConfigValues($data, $configCache, $uid);
202 * Test the getP() method with a category
204 public function testGetPCat()
206 $configCache = new ConfigCache();
209 $configCache->loadP($uid, [
219 $this->assertEquals([
222 ], $configCache->get($uid, 'system'));
226 * Test the deleteP() method
227 * @dataProvider dataTests
229 public function testDeleteP($data)
231 $configCache = new ConfigCache();
234 foreach ($data as $cat => $values) {
235 foreach ($values as $key => $value) {
236 $configCache->setP($uid, $cat, $key, $value);
240 foreach ($data as $cat => $values) {
241 foreach ($values as $key => $value) {
242 $configCache->deleteP($uid, $cat, $key);
246 $this->assertEmpty($configCache->getAll());