3 namespace Friendica\Test\Core\Config;
5 use Friendica\Core\Config\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->loadConfigArray($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->loadConfigArray($data);
71 $configCache->loadConfigArray($override);
73 $this->assertConfigValues($data, $configCache);
76 $configCache->loadConfigArray($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 getAll() method
84 * @dataProvider dataTests
86 public function testGetAll($data)
88 $configCache = new ConfigCache();
89 $configCache->loadConfigArray($data);
91 $all = $configCache->getAll();
93 $this->assertContains($data['system'], $all);
95 // config values are stored directly in the array base
96 $this->assertEquals($data['config']['a'], $all['a']);
100 * Test the set() and get() method
101 * @dataProvider dataTests
103 public function testSetGet($data)
105 $configCache = new ConfigCache();
107 foreach ($data as $cat => $values) {
108 foreach ($values as $key => $value) {
109 $configCache->set($cat, $key, $value);
113 $this->assertConfigValues($data, $configCache);
117 * Test the delete() method
118 * @dataProvider dataTests
120 public function testDelete($data)
122 $configCache = new ConfigCache($data);
124 foreach ($data as $cat => $values) {
125 foreach ($values as $key => $value) {
126 $configCache->delete($cat, $key);
130 $this->assertEmpty($configCache->getAll());
134 * Test the setP() and getP() methods
135 * @dataProvider dataTests
137 public function testSetGetP($data)
139 $configCache = new ConfigCache();
142 foreach ($data as $cat => $values) {
143 foreach ($values as $key => $value) {
144 $configCache->setP($uid, $cat, $key, $value);
148 $this->assertConfigValues($data, $configCache, $uid);
153 * Test the deleteP() method
154 * @dataProvider dataTests
156 public function testDeleteP($data)
158 $configCache = new ConfigCache();
161 foreach ($data as $cat => $values) {
162 foreach ($values as $key => $value) {
163 $configCache->setP($uid, $cat, $key, $value);
167 foreach ($data as $cat => $values) {
168 foreach ($values as $key => $value) {
169 $configCache->deleteP($uid, $cat, $key);
173 $this->assertEmpty($configCache->getAll());