mirror of
https://git.friendi.ca/friendica/friendica.git
synced 2025-06-08 12:34:27 +02:00
Config FollowUp
- New Configuration (Config is now only holding the instance) - New PConfiguration (PConfig is now only holding the instance) - Config & PConfig-Adapter don't need "ConfigCache" anymore - DB-Connection is now outside App->reload() for better dependency-chaining
This commit is contained in:
parent
c36a0eabdb
commit
eafcf3592d
59 changed files with 1754 additions and 1038 deletions
238
tests/src/Core/Config/Cache/ConfigCacheTest.php
Normal file
238
tests/src/Core/Config/Cache/ConfigCacheTest.php
Normal file
|
@ -0,0 +1,238 @@
|
|||
<?php
|
||||
|
||||
namespace Friendica\Test\Core\Config\Cache;
|
||||
|
||||
use Friendica\Core\Config\Cache\ConfigCache;
|
||||
use Friendica\Test\MockedTest;
|
||||
|
||||
class ConfigCacheTest extends MockedTest
|
||||
{
|
||||
public function dataTests()
|
||||
{
|
||||
return [
|
||||
'normal' => [
|
||||
'data' => [
|
||||
'system' => [
|
||||
'test' => 'it',
|
||||
'boolTrue' => true,
|
||||
'boolFalse' => false,
|
||||
'int' => 235,
|
||||
'dec' => 2.456,
|
||||
'array' => ['1', 2, '3', true, false],
|
||||
],
|
||||
'config' => [
|
||||
'a' => 'value',
|
||||
],
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
private function assertConfigValues($data, ConfigCache $configCache, $uid = null)
|
||||
{
|
||||
foreach ($data as $cat => $values) {
|
||||
foreach ($values as $key => $value) {
|
||||
if (isset($uid)) {
|
||||
$this->assertEquals($data[$cat][$key], $configCache->getP($uid, $cat, $key));
|
||||
} else {
|
||||
$this->assertEquals($data[$cat][$key], $configCache->get($cat, $key));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the loadConfigArray() method without override
|
||||
* @dataProvider dataTests
|
||||
*/
|
||||
public function testLoadConfigArray($data)
|
||||
{
|
||||
$configCache = new ConfigCache();
|
||||
$configCache->load($data);
|
||||
|
||||
$this->assertConfigValues($data, $configCache);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the loadConfigArray() method with overrides
|
||||
* @dataProvider dataTests
|
||||
*/
|
||||
public function testLoadConfigArrayOverride($data)
|
||||
{
|
||||
$override = [
|
||||
'system' => [
|
||||
'test' => 'not',
|
||||
'boolTrue' => false,
|
||||
]
|
||||
];
|
||||
|
||||
$configCache = new ConfigCache();
|
||||
$configCache->load($data);
|
||||
$configCache->load($override);
|
||||
|
||||
$this->assertConfigValues($data, $configCache);
|
||||
|
||||
// override the value
|
||||
$configCache->load($override, true);
|
||||
|
||||
$this->assertEquals($override['system']['test'], $configCache->get('system', 'test'));
|
||||
$this->assertEquals($override['system']['boolTrue'], $configCache->get('system', 'boolTrue'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the loadConfigArray() method with wrong/empty datasets
|
||||
*/
|
||||
public function testLoadConfigArrayWrong()
|
||||
{
|
||||
$configCache = new ConfigCache();
|
||||
|
||||
// empty dataset
|
||||
$configCache->load([]);
|
||||
$this->assertEmpty($configCache->getAll());
|
||||
|
||||
// wrong dataset
|
||||
$configCache->load(['system' => 'not_array']);
|
||||
$this->assertEmpty($configCache->getAll());
|
||||
|
||||
// incomplete dataset (key is integer ID of the array)
|
||||
$configCache->load(['system' => ['value']]);
|
||||
$this->assertEquals('value', $configCache->get('system', 0));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the getAll() method
|
||||
* @dataProvider dataTests
|
||||
*/
|
||||
public function testGetAll($data)
|
||||
{
|
||||
$configCache = new ConfigCache();
|
||||
$configCache->load($data);
|
||||
|
||||
$all = $configCache->getAll();
|
||||
|
||||
$this->assertContains($data['system'], $all);
|
||||
$this->assertContains($data['config'], $all);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the set() and get() method
|
||||
* @dataProvider dataTests
|
||||
*/
|
||||
public function testSetGet($data)
|
||||
{
|
||||
$configCache = new ConfigCache();
|
||||
|
||||
foreach ($data as $cat => $values) {
|
||||
foreach ($values as $key => $value) {
|
||||
$configCache->set($cat, $key, $value);
|
||||
}
|
||||
}
|
||||
|
||||
$this->assertConfigValues($data, $configCache);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the get() method without a value
|
||||
*/
|
||||
public function testGetEmpty()
|
||||
{
|
||||
$configCache = new ConfigCache();
|
||||
|
||||
$this->assertEquals('!<unset>!', $configCache->get('something', 'value'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the has() method
|
||||
*/
|
||||
public function testHas()
|
||||
{
|
||||
$configCache = new ConfigCache();
|
||||
|
||||
$this->assertFalse($configCache->has('system', 'test'));
|
||||
|
||||
$configCache->set('system', 'test', 'it');
|
||||
$this->assertTrue($configCache->has('system', 'test'));
|
||||
|
||||
$this->assertFalse($configCache->has('system', null));
|
||||
$configCache->set('system', null, 'it');
|
||||
$this->assertTrue($configCache->has('system', null));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the delete() method
|
||||
* @dataProvider dataTests
|
||||
*/
|
||||
public function testDelete($data)
|
||||
{
|
||||
$configCache = new ConfigCache($data);
|
||||
|
||||
foreach ($data as $cat => $values) {
|
||||
foreach ($values as $key => $value) {
|
||||
$configCache->delete($cat, $key);
|
||||
}
|
||||
}
|
||||
|
||||
$this->assertEmpty($configCache->getAll());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the setP() and getP() methods
|
||||
* @dataProvider dataTests
|
||||
*/
|
||||
public function testSetGetP($data)
|
||||
{
|
||||
$configCache = new ConfigCache();
|
||||
$uid = 345;
|
||||
|
||||
foreach ($data as $cat => $values) {
|
||||
foreach ($values as $key => $value) {
|
||||
$configCache->setP($uid, $cat, $key, $value);
|
||||
}
|
||||
}
|
||||
|
||||
$this->assertConfigValues($data, $configCache, $uid);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test the deleteP() method
|
||||
* @dataProvider dataTests
|
||||
*/
|
||||
public function testDeleteP($data)
|
||||
{
|
||||
$configCache = new ConfigCache();
|
||||
$uid = 345;
|
||||
|
||||
foreach ($data as $cat => $values) {
|
||||
foreach ($values as $key => $value) {
|
||||
$configCache->setP($uid, $cat, $key, $value);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($data as $cat => $values) {
|
||||
foreach ($values as $key => $value) {
|
||||
$configCache->deleteP($uid, $cat, $key);
|
||||
}
|
||||
}
|
||||
|
||||
$this->assertEmpty($configCache->getAll());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the hasP() method
|
||||
*/
|
||||
public function testHasP()
|
||||
{
|
||||
$configCache = new ConfigCache();
|
||||
$uid = 345;
|
||||
|
||||
$this->assertFalse($configCache->hasP($uid, 'system', 'test'));
|
||||
|
||||
$configCache->setP($uid, 'system', 'test', 'it');
|
||||
$this->assertTrue($configCache->hasP($uid, 'system', 'test'));
|
||||
|
||||
$this->assertFalse($configCache->hasP($uid, 'system', null));
|
||||
$configCache->setP($uid, 'system', null, 'it');
|
||||
$this->assertTrue($configCache->hasP($uid, 'system', null));
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue