3 namespace Friendica\Test\src\Core\Config\Cache;
5 use Friendica\Core\Config\Cache\PConfigCache;
6 use Friendica\Test\MockedTest;
8 class PConfigCacheTest extends MockedTest
10 public function dataTests()
21 'array' => ['1', 2, '3', true, false],
31 private function assertConfigValues($data, PConfigCache $configCache, $uid)
33 foreach ($data as $cat => $values) {
34 foreach ($values as $key => $value) {
35 $this->assertEquals($data[$cat][$key], $configCache->get($uid, $cat, $key));
41 * Test the setP() and getP() methods
43 * @dataProvider dataTests
45 public function testSetGet($data)
47 $configCache = new PConfigCache();
50 foreach ($data as $cat => $values) {
51 foreach ($values as $key => $value) {
52 $configCache->set($uid, $cat, $key, $value);
56 $this->assertConfigValues($data, $configCache, $uid);
61 * Test the getP() method with a category
63 public function testGetCat()
65 $configCache = new PConfigCache();
68 $configCache->load($uid, [
81 ], $configCache->get($uid, 'system'));
85 * Test the deleteP() method
87 * @dataProvider dataTests
89 public function testDelete($data)
91 $configCache = new PConfigCache();
94 foreach ($data as $cat => $values) {
95 foreach ($values as $key => $value) {
96 $configCache->set($uid, $cat, $key, $value);
100 foreach ($data as $cat => $values) {
101 foreach ($values as $key => $value) {
102 $configCache->delete($uid, $cat, $key);
106 $this->assertEmpty($configCache->getAll());
110 * Test the keyDiff() method with result
112 * @dataProvider dataTests
114 public function testKeyDiffWithResult($data)
116 $configCache = new PConfigCache($data);
120 'fakeKey' => 'value',
124 $this->assertEquals($diffConfig, $configCache->keyDiff($diffConfig));
128 * Test the keyDiff() method without result
130 * @dataProvider dataTests
132 public function testKeyDiffWithoutResult($data)
134 $configCache = new PConfigCache();
136 $configCache->load(1, $data);
138 $diffConfig = $configCache->getAll();
140 $this->assertEmpty($configCache->keyDiff($diffConfig));
144 * Test the default hiding of passwords inside the cache
146 public function testPasswordHide()
148 $configCache = new PConfigCache();
150 $configCache->load(1, [
152 'password' => 'supersecure',
153 'username' => 'notsecured',
157 $this->assertEquals('supersecure', $configCache->get(1, 'database', 'password'));
158 $this->assertNotEquals('supersecure', print_r($configCache->get(1, 'database', 'password'), true));
159 $this->assertEquals('notsecured', print_r($configCache->get(1, 'database', 'username'), true));
163 * Test disabling the hiding of passwords inside the cache
165 public function testPasswordShow()
167 $configCache = new PConfigCache(false);
169 $configCache->load(1, [
171 'password' => 'supersecure',
172 'username' => 'notsecured',
176 $this->assertEquals('supersecure', $configCache->get(1, 'database', 'password'));
177 $this->assertEquals('supersecure', print_r($configCache->get(1, 'database', 'password'), true));
178 $this->assertEquals('notsecured', print_r($configCache->get(1, 'database', 'username'), true));
182 * Test a empty password
184 public function testEmptyPassword()
186 $configCache = new PConfigCache();
188 $configCache->load(1, [
195 $this->assertEmpty($configCache->get(1, 'database', 'password'));
196 $this->assertEmpty($configCache->get(1, 'database', 'username'));
199 public function testWrongTypePassword()
201 $configCache = new PConfigCache();
203 $configCache->load(1, [
205 'password' => new \stdClass(),
210 $this->assertNotEmpty($configCache->get(1, 'database', 'password'));
211 $this->assertEmpty($configCache->get(1, 'database', 'username'));
213 $configCache = new PConfigCache();
215 $configCache->load(1, [
222 $this->assertEquals(23, $configCache->get(1, 'database', 'password'));
223 $this->assertEmpty($configCache->get(1, 'database', 'username'));
227 * Test two different UID configs and make sure that there is no overlapping possible
229 public function testTwoUid()
231 $configCache = new PConfigCache();
233 $configCache->load(1, [
240 $configCache->load(2, [
246 $this->assertEquals('value1', $configCache->get(1, 'cat1', 'key1'));
247 $this->assertEquals('value2', $configCache->get(2, 'cat2', 'key2'));
249 $this->assertNull($configCache->get(1, 'cat2', 'key2'));
250 $this->assertNull($configCache->get(2, 'cat1', 'key1'));