]> git.mxchange.org Git - friendica.git/commitdiff
Fix tests & Router is now using Dependency Injection instead of DI Registry
authornupplaPhil <admin@philipp.info>
Sun, 19 Jan 2020 21:38:33 +0000 (22:38 +0100)
committernupplaPhil <admin@philipp.info>
Sun, 19 Jan 2020 21:38:33 +0000 (22:38 +0100)
20 files changed:
src/App/Router.php
tests/src/App/ModuleTest.php
tests/src/App/RouterTest.php
tests/src/Core/Config/Cache/ConfigCacheTest.php [deleted file]
tests/src/Core/Config/Cache/PConfigCacheTest.php [deleted file]
tests/src/Core/Config/CacheTest.php [new file with mode: 0644]
tests/src/Core/Config/ConfigTest.php [new file with mode: 0644]
tests/src/Core/Config/ConfigurationTest.php [deleted file]
tests/src/Core/Config/JitConfigTest.php [new file with mode: 0644]
tests/src/Core/Config/JitConfigurationTest.php [deleted file]
tests/src/Core/Config/JitPConfigurationTest.php [deleted file]
tests/src/Core/Config/PConfigurationTest.php [deleted file]
tests/src/Core/Config/PreloadConfigTest.php [new file with mode: 0644]
tests/src/Core/Config/PreloadConfigurationTest.php [deleted file]
tests/src/Core/Config/PreloadPConfigurationTest.php [deleted file]
tests/src/Core/Lock/SemaphoreLockTest.php
tests/src/Core/PConfig/CacheTest.php [new file with mode: 0644]
tests/src/Core/PConfig/JitPConfigTest.php [new file with mode: 0644]
tests/src/Core/PConfig/PConfigTest.php [new file with mode: 0644]
tests/src/Core/PConfig/PreloadPConfigTest.php [new file with mode: 0644]

index 6ae42bb14191d30f372dbe87115f3ef828940f9d..450822cf86fdf530212fc6b40ba65c2393a1b1f9 100644 (file)
@@ -8,7 +8,7 @@ use FastRoute\Dispatcher;
 use FastRoute\RouteCollector;
 use FastRoute\RouteParser\Std;
 use Friendica\Core\Hook;
-use Friendica\DI;
+use Friendica\Core\L10n;
 use Friendica\Network\HTTPException;
 
 /**
@@ -44,12 +44,18 @@ class Router
         */
        private $parameters = [];
 
+       /** @var L10n */
+       private $l10n;
+
        /**
         * @param array $server The $_SERVER variable
+        * @param L10n  $l10n
         * @param RouteCollector|null $routeCollector Optional the loaded Route collector
         */
-       public function __construct(array $server, RouteCollector $routeCollector = null)
+       public function __construct(array $server, L10n $l10n, RouteCollector $routeCollector = null)
        {
+               $this->l10n = $l10n;
+
                $httpMethod = $server['REQUEST_METHOD'] ?? self::GET;
                $this->httpMethod = in_array($httpMethod, self::ALLOWED_METHODS) ? $httpMethod : self::GET;
 
@@ -181,9 +187,9 @@ class Router
                        $moduleClass = $routeInfo[1];
                        $this->parameters = $routeInfo[2];
                } elseif ($routeInfo[0] === Dispatcher::METHOD_NOT_ALLOWED) {
-                       throw new HTTPException\MethodNotAllowedException(DI::l10n()->t('Method not allowed for this module. Allowed method(s): %s', implode(', ', $routeInfo[1])));
+                       throw new HTTPException\MethodNotAllowedException($this->l10n->t('Method not allowed for this module. Allowed method(s): %s', implode(', ', $routeInfo[1])));
                } else {
-                       throw new HTTPException\NotFoundException(DI::l10n()->t('Page not found.'));
+                       throw new HTTPException\NotFoundException($this->l10n->t('Page not found.'));
                }
 
                return $moduleClass;
index f76d51843ca00cf4420cd993ecf614f7974812c6..5b8bdcd3d68b236e6f10611b1c6d2481001af1c2 100644 (file)
@@ -4,6 +4,7 @@ namespace Friendica\Test\src\App;
 
 use Friendica\App;
 use Friendica\Core\Config\IConfig;
+use Friendica\Core\L10n;
 use Friendica\LegacyModule;
 use Friendica\Module\HTTPException\PageNotFound;
 use Friendica\Module\WellKnown\HostMeta;
@@ -152,7 +153,10 @@ class ModuleTest extends DatabaseTest
                $config = \Mockery::mock(IConfig::class);
                $config->shouldReceive('get')->with('config', 'private_addons', false)->andReturn($privAdd)->atMost()->once();
 
-               $router = (new App\Router([]))->loadRoutes(include __DIR__ . '/../../../static/routes.config.php');
+               $l10n = \Mockery::mock(L10n::class);
+               $l10n->shouldReceive('t')->andReturnUsing(function ($args) { return $args; });
+
+               $router = (new App\Router([], $l10n))->loadRoutes(include __DIR__ . '/../../../static/routes.config.php');
 
                $module = (new App\Module($name))->determineClass(new App\Arguments('', $command), $router, $config);
 
index 102808f6ac22e677180df6545807c8600fb54667..fc34df95754fcba85995aad7e34ea8877fc28448 100644 (file)
@@ -3,16 +3,29 @@
 namespace Friendica\Test\src\App;
 
 use Friendica\App\Router;
+use Friendica\Core\L10n;
 use Friendica\Module;
 use Friendica\Network\HTTPException\MethodNotAllowedException;
 use Friendica\Network\HTTPException\NotFoundException;
+use Mockery\MockInterface;
 use PHPUnit\Framework\TestCase;
 
 class RouterTest extends TestCase
 {
+       /** @var L10n|MockInterface */
+       private $l10n;
+
+       protected function setUp()
+       {
+               parent::setUp();
+
+               $this->l10n = \Mockery::mock(L10n::class);
+               $this->l10n->shouldReceive('t')->andReturnUsing(function ($args) { return $args; });
+       }
+
        public function testGetModuleClass()
        {
-               $router = new Router(['REQUEST_METHOD' => Router::GET]);
+               $router = new Router(['REQUEST_METHOD' => Router::GET], $this->l10n);
 
                $routeCollector = $router->getRouteCollector();
                $routeCollector->addRoute([Router::GET], '/', 'IndexModuleClassName');
@@ -36,7 +49,7 @@ class RouterTest extends TestCase
 
        public function testPostModuleClass()
        {
-               $router = new Router(['REQUEST_METHOD' => Router::POST]);
+               $router = new Router(['REQUEST_METHOD' => Router::POST], $this->l10n);
 
                $routeCollector = $router->getRouteCollector();
                $routeCollector->addRoute([Router::POST], '/', 'IndexModuleClassName');
@@ -62,7 +75,7 @@ class RouterTest extends TestCase
        {
                $this->expectException(NotFoundException::class);
 
-               $router = new Router(['REQUEST_METHOD' => Router::GET]);
+               $router = new Router(['REQUEST_METHOD' => Router::GET], $this->l10n);
 
                $router->getModuleClass('/unsupported');
        }
@@ -71,7 +84,7 @@ class RouterTest extends TestCase
        {
                $this->expectException(NotFoundException::class);
 
-               $router = new Router(['REQUEST_METHOD' => Router::GET]);
+               $router = new Router(['REQUEST_METHOD' => Router::GET], $this->l10n);
 
                $routeCollector = $router->getRouteCollector();
                $routeCollector->addRoute([Router::GET], '/test', 'TestModuleClassName');
@@ -83,7 +96,7 @@ class RouterTest extends TestCase
        {
                $this->expectException(NotFoundException::class);
 
-               $router = new Router(['REQUEST_METHOD' => Router::GET]);
+               $router = new Router(['REQUEST_METHOD' => Router::GET], $this->l10n);
 
                $routeCollector = $router->getRouteCollector();
                $routeCollector->addRoute([Router::GET], '/optional[/option]', 'OptionalModuleClassName');
@@ -95,7 +108,7 @@ class RouterTest extends TestCase
        {
                $this->expectException(NotFoundException::class);
 
-               $router = new Router(['REQUEST_METHOD' => Router::GET]);
+               $router = new Router(['REQUEST_METHOD' => Router::GET], $this->l10n);
 
                $routeCollector = $router->getRouteCollector();
                $routeCollector->addRoute([Router::GET], '/variable/{var}', 'VariableModuleClassName');
@@ -107,7 +120,7 @@ class RouterTest extends TestCase
        {
                $this->expectException(MethodNotAllowedException::class);
 
-               $router = new Router(['REQUEST_METHOD' => Router::POST]);
+               $router = new Router(['REQUEST_METHOD' => Router::POST], $this->l10n);
 
                $routeCollector = $router->getRouteCollector();
                $routeCollector->addRoute([Router::GET], '/test', 'TestModuleClassName');
@@ -119,7 +132,7 @@ class RouterTest extends TestCase
        {
                $this->expectException(MethodNotAllowedException::class);
 
-               $router = new Router(['REQUEST_METHOD' => Router::GET]);
+               $router = new Router(['REQUEST_METHOD' => Router::GET], $this->l10n);
 
                $routeCollector = $router->getRouteCollector();
                $routeCollector->addRoute([Router::POST], '/test', 'TestModuleClassName');
@@ -159,7 +172,7 @@ class RouterTest extends TestCase
        {
                $router = (new Router([
                        'REQUEST_METHOD' => Router::GET
-               ]))->loadRoutes($routes);
+               ], $this->l10n))->loadRoutes($routes);
 
                $this->assertEquals(Module\Home::class, $router->getModuleClass('/'));
                $this->assertEquals(Module\Friendica::class, $router->getModuleClass('/group/route'));
@@ -174,7 +187,7 @@ class RouterTest extends TestCase
        {
                $router = (new Router([
                        'REQUEST_METHOD' => Router::POST
-               ]))->loadRoutes($routes);
+               ], $this->l10n))->loadRoutes($routes);
 
                // Don't find GET
                $this->assertEquals(Module\NodeInfo::class, $router->getModuleClass('/post/it'));
diff --git a/tests/src/Core/Config/Cache/ConfigCacheTest.php b/tests/src/Core/Config/Cache/ConfigCacheTest.php
deleted file mode 100644 (file)
index 6d0b045..0000000
+++ /dev/null
@@ -1,288 +0,0 @@
-<?php
-
-namespace Friendica\Test\src\Core\Config\Cache;
-
-use Friendica\Core\Config\Cache;
-use Friendica\Test\MockedTest;
-use ParagonIE\HiddenString\HiddenString;
-
-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, Cache $configCache)
-       {
-               foreach ($data as $cat => $values) {
-                       foreach ($values as $key => $value) {
-                               $this->assertEquals($data[$cat][$key], $configCache->get($cat, $key));
-                       }
-               }
-       }
-
-       /**
-        * Test the loadConfigArray() method without override
-        * @dataProvider dataTests
-        */
-       public function testLoadConfigArray($data)
-       {
-               $configCache = new Cache();
-               $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 Cache();
-               $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 Cache();
-
-               // 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 Cache();
-               $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 Cache();
-
-               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 Cache();
-
-               $this->assertNull($configCache->get('something', 'value'));
-       }
-
-       /**
-        * Test the get() method with a category
-        */
-       public function testGetCat()
-       {
-               $configCache = new Cache([
-                       'system' => [
-                               'key1' => 'value1',
-                               'key2' => 'value2',
-                       ],
-                       'config' => [
-                               'key3' => 'value3',
-                       ],
-               ]);
-
-               $this->assertEquals([
-                       'key1' => 'value1',
-                       'key2' => 'value2',
-               ], $configCache->get('system'));
-
-               // explicit null as key
-               $this->assertEquals([
-                       'key1' => 'value1',
-                       'key2' => 'value2',
-               ], $configCache->get('system', null));
-       }
-
-       /**
-        * Test the delete() method
-        * @dataProvider dataTests
-        */
-       public function testDelete($data)
-       {
-               $configCache = new Cache($data);
-
-               foreach ($data as $cat => $values) {
-                       foreach ($values as $key => $value) {
-                               $configCache->delete($cat, $key);
-                       }
-               }
-
-               $this->assertEmpty($configCache->getAll());
-       }
-
-       /**
-        * Test the keyDiff() method with result
-        * @dataProvider dataTests
-        */
-       public function testKeyDiffWithResult($data)
-       {
-               $configCache = new Cache($data);
-
-               $diffConfig = [
-                       'fakeCat' => [
-                               'fakeKey' => 'value',
-                       ]
-               ];
-
-               $this->assertEquals($diffConfig, $configCache->keyDiff($diffConfig));
-       }
-
-       /**
-        * Test the keyDiff() method without result
-        * @dataProvider dataTests
-        */
-       public function testKeyDiffWithoutResult($data)
-       {
-               $configCache = new Cache($data);
-
-               $diffConfig = $configCache->getAll();
-
-               $this->assertEmpty($configCache->keyDiff($diffConfig));
-       }
-
-       /**
-        * Test the default hiding of passwords inside the cache
-        */
-       public function testPasswordHide()
-       {
-               $configCache = new Cache([
-                       'database' => [
-                               'password' => 'supersecure',
-                               'username' => 'notsecured',
-                       ],
-               ]);
-
-               $this->assertEquals('supersecure', $configCache->get('database', 'password'));
-               $this->assertNotEquals('supersecure', print_r($configCache->get('database', 'password'), true));
-               $this->assertEquals('notsecured', print_r($configCache->get('database', 'username'), true));
-       }
-
-       /**
-        * Test disabling the hiding of passwords inside the cache
-        */
-       public function testPasswordShow()
-       {
-               $configCache = new Cache([
-                       'database' => [
-                               'password' => 'supersecure',
-                               'username' => 'notsecured',
-                       ],
-               ], false);
-
-               $this->assertEquals('supersecure', $configCache->get('database', 'password'));
-               $this->assertEquals('supersecure', print_r($configCache->get('database', 'password'), true));
-               $this->assertEquals('notsecured', print_r($configCache->get('database', 'username'), true));
-       }
-
-       /**
-        * Test a empty password
-        */
-       public function testEmptyPassword()
-       {
-               $configCache = new Cache([
-                       'database' => [
-                               'password' => '',
-                               'username' => '',
-                       ]
-               ]);
-
-               $this->assertNotEmpty($configCache->get('database', 'password'));
-               $this->assertInstanceOf(HiddenString::class, $configCache->get('database', 'password'));
-               $this->assertEmpty($configCache->get('database', 'username'));
-       }
-
-       public function testWrongTypePassword()
-       {
-               $configCache = new Cache([
-                       'database' => [
-                               'password' => new \stdClass(),
-                               'username' => '',
-                       ]
-               ]);
-
-               $this->assertNotEmpty($configCache->get('database', 'password'));
-               $this->assertEmpty($configCache->get('database', 'username'));
-
-               $configCache = new Cache([
-                       'database' => [
-                               'password' => 23,
-                               'username' => '',
-                       ]
-               ]);
-
-               $this->assertEquals(23, $configCache->get('database', 'password'));
-               $this->assertEmpty($configCache->get('database', 'username'));
-       }
-}
diff --git a/tests/src/Core/Config/Cache/PConfigCacheTest.php b/tests/src/Core/Config/Cache/PConfigCacheTest.php
deleted file mode 100644 (file)
index 1d5a96f..0000000
+++ /dev/null
@@ -1,275 +0,0 @@
-<?php
-
-namespace Friendica\Test\src\Core\Config\Cache;
-
-use Friendica\Core\PConfig\Cache;
-use Friendica\Test\MockedTest;
-
-class PConfigCacheTest 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, Cache $configCache, $uid)
-       {
-               foreach ($data as $cat => $values) {
-                       foreach ($values as $key => $value) {
-                               $this->assertEquals($data[$cat][$key], $configCache->get($uid, $cat, $key));
-                       }
-               }
-       }
-
-       /**
-        * Test the setP() and getP() methods
-        *
-        * @dataProvider dataTests
-        */
-       public function testSetGet($data)
-       {
-               $configCache = new Cache();
-               $uid         = 345;
-
-               foreach ($data as $cat => $values) {
-                       foreach ($values as $key => $value) {
-                               $configCache->set($uid, $cat, $key, $value);
-                       }
-               }
-
-               $this->assertConfigValues($data, $configCache, $uid);
-       }
-
-
-       /**
-        * Test the getP() method with a category
-        */
-       public function testGetCat()
-       {
-               $configCache = new Cache();
-               $uid         = 345;
-
-               $configCache->load($uid, [
-                       'system' => [
-                               'key1' => 'value1',
-                               'key2' => 'value2',
-                       ],
-                       'config' => [
-                               'key3' => 'value3',
-                       ],
-               ]);
-
-               $this->assertEquals([
-                       'key1' => 'value1',
-                       'key2' => 'value2',
-               ], $configCache->get($uid, 'system'));
-
-               // test explicit cat with null as key
-               $this->assertEquals([
-                       'key1' => 'value1',
-                       'key2' => 'value2',
-               ], $configCache->get($uid, 'system', null));
-       }
-
-       /**
-        * Test the deleteP() method
-        *
-        * @dataProvider dataTests
-        */
-       public function testDelete($data)
-       {
-               $configCache = new Cache();
-               $uid         = 345;
-
-               foreach ($data as $cat => $values) {
-                       foreach ($values as $key => $value) {
-                               $configCache->set($uid, $cat, $key, $value);
-                       }
-               }
-
-               foreach ($data as $cat => $values) {
-                       foreach ($values as $key => $value) {
-                               $configCache->delete($uid, $cat, $key);
-                       }
-               }
-
-               $this->assertEmpty($configCache->getAll());
-       }
-
-       /**
-        * Test the keyDiff() method with result
-        *
-        * @dataProvider dataTests
-        */
-       public function testKeyDiffWithResult($data)
-       {
-               $configCache = new Cache();
-
-               $diffConfig = [
-                       'fakeCat' => [
-                               'fakeKey' => 'value',
-                       ]
-               ];
-
-               $this->assertEquals($diffConfig, $configCache->keyDiff($diffConfig));
-       }
-
-       /**
-        * Test the keyDiff() method without result
-        *
-        * @dataProvider dataTests
-        */
-       public function testKeyDiffWithoutResult($data)
-       {
-               $configCache = new Cache();
-
-               $configCache->load(1, $data);
-
-               $diffConfig = $configCache->getAll();
-
-               $this->assertEmpty($configCache->keyDiff($diffConfig));
-       }
-
-       /**
-        * Test the default hiding of passwords inside the cache
-        */
-       public function testPasswordHide()
-       {
-               $configCache = new Cache();
-
-               $configCache->load(1, [
-                       'database' => [
-                               'password' => 'supersecure',
-                               'username' => 'notsecured',
-                       ]
-               ]);
-
-               $this->assertEquals('supersecure', $configCache->get(1, 'database', 'password'));
-               $this->assertNotEquals('supersecure', print_r($configCache->get(1, 'database', 'password'), true));
-               $this->assertEquals('notsecured', print_r($configCache->get(1, 'database', 'username'), true));
-       }
-
-       /**
-        * Test disabling the hiding of passwords inside the cache
-        */
-       public function testPasswordShow()
-       {
-               $configCache = new Cache(false);
-
-               $configCache->load(1, [
-                       'database' => [
-                               'password' => 'supersecure',
-                               'username' => 'notsecured',
-                       ]
-               ]);
-
-               $this->assertEquals('supersecure', $configCache->get(1, 'database', 'password'));
-               $this->assertEquals('supersecure', print_r($configCache->get(1, 'database', 'password'), true));
-               $this->assertEquals('notsecured', print_r($configCache->get(1, 'database', 'username'), true));
-       }
-
-       /**
-        * Test a empty password
-        */
-       public function testEmptyPassword()
-       {
-               $configCache = new Cache();
-
-               $configCache->load(1, [
-                       'database' => [
-                               'password' => '',
-                               'username' => '',
-                       ]
-               ]);
-
-               $this->assertEmpty($configCache->get(1, 'database', 'password'));
-               $this->assertEmpty($configCache->get(1, 'database', 'username'));
-       }
-
-       public function testWrongTypePassword()
-       {
-               $configCache = new Cache();
-
-               $configCache->load(1, [
-                       'database' => [
-                               'password' => new \stdClass(),
-                               'username' => '',
-                       ]
-               ]);
-
-               $this->assertNotEmpty($configCache->get(1, 'database', 'password'));
-               $this->assertEmpty($configCache->get(1, 'database', 'username'));
-
-               $configCache = new Cache();
-
-               $configCache->load(1, [
-                       'database' => [
-                               'password' => 23,
-                               'username' => '',
-                       ],
-               ]);
-
-               $this->assertEquals(23, $configCache->get(1, 'database', 'password'));
-               $this->assertEmpty($configCache->get(1, 'database', 'username'));
-       }
-
-       /**
-        * Test two different UID configs and make sure that there is no overlapping possible
-        */
-       public function testTwoUid()
-       {
-               $configCache = new Cache();
-
-               $configCache->load(1, [
-                       'cat1' => [
-                               'key1' => 'value1',
-                       ],
-               ]);
-
-
-               $configCache->load(2, [
-                       'cat2' => [
-                               'key2' => 'value2',
-                       ],
-               ]);
-
-               $this->assertEquals('value1', $configCache->get(1, 'cat1', 'key1'));
-               $this->assertEquals('value2', $configCache->get(2, 'cat2', 'key2'));
-
-               $this->assertNull($configCache->get(1, 'cat2', 'key2'));
-               $this->assertNull($configCache->get(2, 'cat1', 'key1'));
-       }
-
-       /**
-        * Test when using an invalid UID
-        * @todo check it the clean way before using the config class
-        */
-       public function testInvalidUid()
-       {
-               // bad UID!
-               $uid = null;
-
-               $configCache = new Cache();
-
-               $this->assertNull($configCache->get($uid, 'cat1', 'cat2'));
-
-               $this->assertFalse($configCache->set($uid, 'cat1', 'key1', 'doesn\'t matter!'));
-               $this->assertFalse($configCache->delete($uid, 'cat1', 'key1'));
-       }
-}
diff --git a/tests/src/Core/Config/CacheTest.php b/tests/src/Core/Config/CacheTest.php
new file mode 100644 (file)
index 0000000..9a398f5
--- /dev/null
@@ -0,0 +1,288 @@
+<?php
+
+namespace Friendica\Test\src\Core\Config;
+
+use Friendica\Core\Config\Cache;
+use Friendica\Test\MockedTest;
+use ParagonIE\HiddenString\HiddenString;
+
+class CacheTest 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, Cache $configCache)
+       {
+               foreach ($data as $cat => $values) {
+                       foreach ($values as $key => $value) {
+                               $this->assertEquals($data[$cat][$key], $configCache->get($cat, $key));
+                       }
+               }
+       }
+
+       /**
+        * Test the loadConfigArray() method without override
+        * @dataProvider dataTests
+        */
+       public function testLoadConfigArray($data)
+       {
+               $configCache = new Cache();
+               $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 Cache();
+               $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 Cache();
+
+               // 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 Cache();
+               $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 Cache();
+
+               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 Cache();
+
+               $this->assertNull($configCache->get('something', 'value'));
+       }
+
+       /**
+        * Test the get() method with a category
+        */
+       public function testGetCat()
+       {
+               $configCache = new Cache([
+                       'system' => [
+                               'key1' => 'value1',
+                               'key2' => 'value2',
+                       ],
+                       'config' => [
+                               'key3' => 'value3',
+                       ],
+               ]);
+
+               $this->assertEquals([
+                       'key1' => 'value1',
+                       'key2' => 'value2',
+               ], $configCache->get('system'));
+
+               // explicit null as key
+               $this->assertEquals([
+                       'key1' => 'value1',
+                       'key2' => 'value2',
+               ], $configCache->get('system', null));
+       }
+
+       /**
+        * Test the delete() method
+        * @dataProvider dataTests
+        */
+       public function testDelete($data)
+       {
+               $configCache = new Cache($data);
+
+               foreach ($data as $cat => $values) {
+                       foreach ($values as $key => $value) {
+                               $configCache->delete($cat, $key);
+                       }
+               }
+
+               $this->assertEmpty($configCache->getAll());
+       }
+
+       /**
+        * Test the keyDiff() method with result
+        * @dataProvider dataTests
+        */
+       public function testKeyDiffWithResult($data)
+       {
+               $configCache = new Cache($data);
+
+               $diffConfig = [
+                       'fakeCat' => [
+                               'fakeKey' => 'value',
+                       ]
+               ];
+
+               $this->assertEquals($diffConfig, $configCache->keyDiff($diffConfig));
+       }
+
+       /**
+        * Test the keyDiff() method without result
+        * @dataProvider dataTests
+        */
+       public function testKeyDiffWithoutResult($data)
+       {
+               $configCache = new Cache($data);
+
+               $diffConfig = $configCache->getAll();
+
+               $this->assertEmpty($configCache->keyDiff($diffConfig));
+       }
+
+       /**
+        * Test the default hiding of passwords inside the cache
+        */
+       public function testPasswordHide()
+       {
+               $configCache = new Cache([
+                       'database' => [
+                               'password' => 'supersecure',
+                               'username' => 'notsecured',
+                       ],
+               ]);
+
+               $this->assertEquals('supersecure', $configCache->get('database', 'password'));
+               $this->assertNotEquals('supersecure', print_r($configCache->get('database', 'password'), true));
+               $this->assertEquals('notsecured', print_r($configCache->get('database', 'username'), true));
+       }
+
+       /**
+        * Test disabling the hiding of passwords inside the cache
+        */
+       public function testPasswordShow()
+       {
+               $configCache = new Cache([
+                       'database' => [
+                               'password' => 'supersecure',
+                               'username' => 'notsecured',
+                       ],
+               ], false);
+
+               $this->assertEquals('supersecure', $configCache->get('database', 'password'));
+               $this->assertEquals('supersecure', print_r($configCache->get('database', 'password'), true));
+               $this->assertEquals('notsecured', print_r($configCache->get('database', 'username'), true));
+       }
+
+       /**
+        * Test a empty password
+        */
+       public function testEmptyPassword()
+       {
+               $configCache = new Cache([
+                       'database' => [
+                               'password' => '',
+                               'username' => '',
+                       ]
+               ]);
+
+               $this->assertNotEmpty($configCache->get('database', 'password'));
+               $this->assertInstanceOf(HiddenString::class, $configCache->get('database', 'password'));
+               $this->assertEmpty($configCache->get('database', 'username'));
+       }
+
+       public function testWrongTypePassword()
+       {
+               $configCache = new Cache([
+                       'database' => [
+                               'password' => new \stdClass(),
+                               'username' => '',
+                       ]
+               ]);
+
+               $this->assertNotEmpty($configCache->get('database', 'password'));
+               $this->assertEmpty($configCache->get('database', 'username'));
+
+               $configCache = new Cache([
+                       'database' => [
+                               'password' => 23,
+                               'username' => '',
+                       ]
+               ]);
+
+               $this->assertEquals(23, $configCache->get('database', 'password'));
+               $this->assertEmpty($configCache->get('database', 'username'));
+       }
+}
diff --git a/tests/src/Core/Config/ConfigTest.php b/tests/src/Core/Config/ConfigTest.php
new file mode 100644 (file)
index 0000000..c67f930
--- /dev/null
@@ -0,0 +1,418 @@
+<?php
+
+namespace Friendica\Test\src\Core\Config;
+
+use Friendica\Core\Config\Cache;
+use Friendica\Core\Config\IConfig;
+use Friendica\Model\Config\Config as ConfigModel;
+use Friendica\Test\MockedTest;
+use Mockery\MockInterface;
+use Mockery;
+
+abstract class ConfigTest extends MockedTest
+{
+       /** @var ConfigModel|MockInterface */
+       protected $configModel;
+
+       /** @var Cache */
+       protected $configCache;
+
+       /** @var IConfig */
+       protected $testedConfig;
+
+       /**
+        * Assert a config tree
+        *
+        * @param string $cat  The category to assert
+        * @param array  $data The result data array
+        */
+       protected function assertConfig(string $cat, array $data)
+       {
+               $result = $this->testedConfig->getCache()->getAll();
+
+               $this->assertNotEmpty($result);
+               $this->assertArrayHasKey($cat, $result);
+               $this->assertArraySubset($data, $result[$cat]);
+       }
+
+
+       protected function setUp()
+       {
+               parent::setUp();
+
+               // Create the config model
+               $this->configModel = Mockery::mock(ConfigModel::class);
+               $this->configCache = new Cache();
+       }
+
+       /**
+        * @return IConfig
+        */
+       public abstract function getInstance();
+
+       public function dataTests()
+       {
+               return [
+                       'string'       => ['data' => 'it'],
+                       'boolTrue'     => ['data' => true],
+                       'boolFalse'    => ['data' => false],
+                       'integer'      => ['data' => 235],
+                       'decimal'      => ['data' => 2.456],
+                       'array'        => ['data' => ['1', 2, '3', true, false]],
+                       'boolIntTrue'  => ['data' => 1],
+                       'boolIntFalse' => ['Data' => 0],
+               ];
+       }
+
+       public function dataConfigLoad()
+       {
+               $data = [
+                       'system' => [
+                               'key1' => 'value1',
+                               'key2' => 'value2',
+                               'key3' => 'value3',
+                       ],
+                       'config' => [
+                               'key1' => 'value1a',
+                               'key4' => 'value4',
+                       ],
+                       'other'  => [
+                               'key5' => 'value5',
+                               'key6' => 'value6',
+                       ],
+               ];
+
+               return [
+                       'system' => [
+                               'data'         => $data,
+                               'possibleCats' => [
+                                       'system',
+                                       'config',
+                                       'other'
+                               ],
+                               'load'         => [
+                                       'system',
+                               ],
+                       ],
+                       'other'  => [
+                               'data'         => $data,
+                               'possibleCats' => [
+                                       'system',
+                                       'config',
+                                       'other'
+                               ],
+                               'load'         => [
+                                       'other',
+                               ],
+                       ],
+                       'config' => [
+                               'data'         => $data,
+                               'possibleCats' => [
+                                       'system',
+                                       'config',
+                                       'other'
+                               ],
+                               'load'         => [
+                                       'config',
+                               ],
+                       ],
+                       'all'    => [
+                               'data'         => $data,
+                               'possibleCats' => [
+                                       'system',
+                                       'config',
+                                       'other'
+                               ],
+                               'load'         => [
+                                       'system',
+                                       'config',
+                                       'other'
+                               ],
+                       ],
+               ];
+       }
+
+       /**
+        * Test the configuration initialization
+        */
+       public function testSetUp(array $data)
+       {
+               $this->configModel->shouldReceive('isConnected')
+                                 ->andReturn(true)
+                                 ->once();
+
+               $this->testedConfig = $this->getInstance();
+               $this->assertInstanceOf(Cache::class, $this->testedConfig->getCache());
+
+               // assert config is loaded everytime
+               $this->assertConfig('config', $data['config']);
+       }
+
+       /**
+        * Test the configuration load() method
+        */
+       public function testLoad(array $data, array $possibleCats, array $load)
+       {
+               $this->testedConfig = $this->getInstance();
+               $this->assertInstanceOf(Cache::class, $this->testedConfig->getCache());
+
+               foreach ($load as $loadedCats) {
+                       $this->testedConfig->load($loadedCats);
+               }
+
+               // Assert at least loaded cats are loaded
+               foreach ($load as $loadedCats) {
+                       $this->assertConfig($loadedCats, $data[$loadedCats]);
+               }
+       }
+
+       public function dataDoubleLoad()
+       {
+               return [
+                       'config' => [
+                               'data1'  => [
+                                       'config' => [
+                                               'key1' => 'value1',
+                                               'key2' => 'value2',
+                                       ],
+                               ],
+                               'data2'  => [
+                                       'config' => [
+                                               'key1' => 'overwritten!',
+                                               'key3' => 'value3',
+                                       ],
+                               ],
+                               'expect' => [
+                                       'config' => [
+                                               // load should overwrite values everytime!
+                                               'key1' => 'overwritten!',
+                                               'key2' => 'value2',
+                                               'key3' => 'value3',
+                                       ],
+                               ],
+                       ],
+                       'other'  => [
+                               'data1'  => [
+                                       'config' => [
+                                               'key12' => 'data4',
+                                               'key45' => 7,
+                                       ],
+                                       'other'  => [
+                                               'key1' => 'value1',
+                                               'key2' => 'value2',
+                                       ],
+                               ],
+                               'data2'  => [
+                                       'other'  => [
+                                               'key1' => 'overwritten!',
+                                               'key3' => 'value3',
+                                       ],
+                                       'config' => [
+                                               'key45' => 45,
+                                               'key52' => true,
+                                       ]
+                               ],
+                               'expect' => [
+                                       'other'  => [
+                                               // load should overwrite values everytime!
+                                               'key1' => 'overwritten!',
+                                               'key2' => 'value2',
+                                               'key3' => 'value3',
+                                       ],
+                                       'config' => [
+                                               'key12' => 'data4',
+                                               'key45' => 45,
+                                               'key52' => true,
+                                       ],
+                               ],
+                       ],
+               ];
+       }
+
+       /**
+        * Test the configuration load() method with overwrite
+        */
+       public function testCacheLoadDouble(array $data1, array $data2, array $expect)
+       {
+               $this->testedConfig = $this->getInstance();
+               $this->assertInstanceOf(Cache::class, $this->testedConfig->getCache());
+
+               foreach ($data1 as $cat => $data) {
+                       $this->testedConfig->load($cat);
+               }
+
+               // Assert at least loaded cats are loaded
+               foreach ($data1 as $cat => $data) {
+                       $this->assertConfig($cat, $data);
+               }
+
+               foreach ($data2 as $cat => $data) {
+                       $this->testedConfig->load($cat);
+               }
+       }
+
+       /**
+        * Test the configuration load without result
+        */
+       public function testLoadWrong()
+       {
+               $this->configModel->shouldReceive('isConnected')->andReturn(true)->once();
+               $this->configModel->shouldReceive('load')->withAnyArgs()->andReturn([])->once();
+
+               $this->testedConfig = $this->getInstance();
+               $this->assertInstanceOf(Cache::class, $this->testedConfig->getCache());
+
+               $this->assertEmpty($this->testedConfig->getCache()->getAll());
+       }
+
+       /**
+        * Test the configuration get() and set() methods without adapter
+        *
+        * @dataProvider dataTests
+        */
+       public function testSetGetWithoutDB($data)
+       {
+               $this->configModel->shouldReceive('isConnected')
+                                 ->andReturn(false)
+                                 ->times(3);
+
+               $this->testedConfig = $this->getInstance();
+               $this->assertInstanceOf(Cache::class, $this->testedConfig->getCache());
+
+               $this->assertTrue($this->testedConfig->set('test', 'it', $data));
+
+               $this->assertEquals($data, $this->testedConfig->get('test', 'it'));
+               $this->assertEquals($data, $this->testedConfig->getCache()->get('test', 'it'));
+       }
+
+       /**
+        * Test the configuration get() and set() methods with a model/db
+        *
+        * @dataProvider dataTests
+        */
+       public function testSetGetWithDB($data)
+       {
+               $this->configModel->shouldReceive('set')->with('test', 'it', $data)->andReturn(true)->once();
+
+               $this->testedConfig = $this->getInstance();
+               $this->assertInstanceOf(Cache::class, $this->testedConfig->getCache());
+
+               $this->assertTrue($this->testedConfig->set('test', 'it', $data));
+
+               $this->assertEquals($data, $this->testedConfig->get('test', 'it'));
+               $this->assertEquals($data, $this->testedConfig->getCache()->get('test', 'it'));
+       }
+
+       /**
+        * Test the configuration get() method with wrong value and no db
+        */
+       public function testGetWrongWithoutDB()
+       {
+               $this->testedConfig = $this->getInstance();
+               $this->assertInstanceOf(Cache::class, $this->testedConfig->getCache());
+
+               // without refresh
+               $this->assertNull($this->testedConfig->get('test', 'it'));
+
+               /// beware that the cache returns '!<unset>!' and not null for a non existing value
+               $this->assertNull($this->testedConfig->getCache()->get('test', 'it'));
+
+               // with default value
+               $this->assertEquals('default', $this->testedConfig->get('test', 'it', 'default'));
+
+               // with default value and refresh
+               $this->assertEquals('default', $this->testedConfig->get('test', 'it', 'default', true));
+       }
+
+       /**
+        * Test the configuration get() method with refresh
+        *
+        * @dataProvider dataTests
+        */
+       public function testGetWithRefresh($data)
+       {
+               $this->configCache->load(['test' => ['it' => 'now']]);
+
+               $this->testedConfig = $this->getInstance();
+               $this->assertInstanceOf(Cache::class, $this->testedConfig->getCache());
+
+               // without refresh
+               $this->assertEquals('now', $this->testedConfig->get('test', 'it'));
+               $this->assertEquals('now', $this->testedConfig->getCache()->get('test', 'it'));
+
+               // with refresh
+               $this->assertEquals($data, $this->testedConfig->get('test', 'it', null, true));
+               $this->assertEquals($data, $this->testedConfig->getCache()->get('test', 'it'));
+
+               // without refresh and wrong value and default
+               $this->assertEquals('default', $this->testedConfig->get('test', 'not', 'default'));
+               $this->assertNull($this->testedConfig->getCache()->get('test', 'not'));
+       }
+
+       /**
+        * Test the configuration delete() method without a model/db
+        *
+        * @dataProvider dataTests
+        */
+       public function testDeleteWithoutDB($data)
+       {
+               $this->configCache->load(['test' => ['it' => $data]]);
+
+               $this->testedConfig = $this->getInstance();
+               $this->assertInstanceOf(Cache::class, $this->testedConfig->getCache());
+
+               $this->assertEquals($data, $this->testedConfig->get('test', 'it'));
+               $this->assertEquals($data, $this->testedConfig->getCache()->get('test', 'it'));
+
+               $this->assertTrue($this->testedConfig->delete('test', 'it'));
+               $this->assertNull($this->testedConfig->get('test', 'it'));
+               $this->assertNull($this->testedConfig->getCache()->get('test', 'it'));
+
+               $this->assertEmpty($this->testedConfig->getCache()->getAll());
+       }
+
+       /**
+        * Test the configuration delete() method with a model/db
+        */
+       public function testDeleteWithDB()
+       {
+               $this->configCache->load(['test' => ['it' => 'now', 'quarter' => 'true']]);
+
+               $this->configModel->shouldReceive('delete')
+                                 ->with('test', 'it')
+                                 ->andReturn(false)
+                                 ->once();
+               $this->configModel->shouldReceive('delete')
+                                 ->with('test', 'second')
+                                 ->andReturn(true)
+                                 ->once();
+               $this->configModel->shouldReceive('delete')
+                                 ->with('test', 'third')
+                                 ->andReturn(false)
+                                 ->once();
+               $this->configModel->shouldReceive('delete')
+                                 ->with('test', 'quarter')
+                                 ->andReturn(true)
+                                 ->once();
+
+               $this->testedConfig = $this->getInstance();
+               $this->assertInstanceOf(Cache::class, $this->testedConfig->getCache());
+
+               // directly set the value to the cache
+               $this->testedConfig->getCache()->set('test', 'it', 'now');
+
+               $this->assertEquals('now', $this->testedConfig->get('test', 'it'));
+               $this->assertEquals('now', $this->testedConfig->getCache()->get('test', 'it'));
+
+               // delete from cache only
+               $this->assertTrue($this->testedConfig->delete('test', 'it'));
+               // delete from db only
+               $this->assertTrue($this->testedConfig->delete('test', 'second'));
+               // no delete
+               $this->assertFalse($this->testedConfig->delete('test', 'third'));
+               // delete both
+               $this->assertTrue($this->testedConfig->delete('test', 'quarter'));
+
+               $this->assertEmpty($this->testedConfig->getCache()->getAll());
+       }
+}
diff --git a/tests/src/Core/Config/ConfigurationTest.php b/tests/src/Core/Config/ConfigurationTest.php
deleted file mode 100644 (file)
index b36d0ac..0000000
+++ /dev/null
@@ -1,418 +0,0 @@
-<?php
-
-namespace Friendica\Test\src\Core\Config;
-
-use Friendica\Core\Config\Cache;
-use Friendica\Core\Config\IConfig;
-use Friendica\Model\Config\Config as ConfigModel;
-use Friendica\Test\MockedTest;
-use Mockery\MockInterface;
-use Mockery;
-
-abstract class ConfigurationTest extends MockedTest
-{
-       /** @var ConfigModel|MockInterface */
-       protected $configModel;
-
-       /** @var Cache */
-       protected $configCache;
-
-       /** @var IConfig */
-       protected $testedConfig;
-
-       /**
-        * Assert a config tree
-        *
-        * @param string $cat  The category to assert
-        * @param array  $data The result data array
-        */
-       protected function assertConfig(string $cat, array $data)
-       {
-               $result = $this->testedConfig->getCache()->getAll();
-
-               $this->assertNotEmpty($result);
-               $this->assertArrayHasKey($cat, $result);
-               $this->assertArraySubset($data, $result[$cat]);
-       }
-
-
-       protected function setUp()
-       {
-               parent::setUp();
-
-               // Create the config model
-               $this->configModel = Mockery::mock(ConfigModel::class);
-               $this->configCache = new Cache();
-       }
-
-       /**
-        * @return IConfig
-        */
-       public abstract function getInstance();
-
-       public function dataTests()
-       {
-               return [
-                       'string'       => ['data' => 'it'],
-                       'boolTrue'     => ['data' => true],
-                       'boolFalse'    => ['data' => false],
-                       'integer'      => ['data' => 235],
-                       'decimal'      => ['data' => 2.456],
-                       'array'        => ['data' => ['1', 2, '3', true, false]],
-                       'boolIntTrue'  => ['data' => 1],
-                       'boolIntFalse' => ['Data' => 0],
-               ];
-       }
-
-       public function dataConfigLoad()
-       {
-               $data = [
-                       'system' => [
-                               'key1' => 'value1',
-                               'key2' => 'value2',
-                               'key3' => 'value3',
-                       ],
-                       'config' => [
-                               'key1' => 'value1a',
-                               'key4' => 'value4',
-                       ],
-                       'other'  => [
-                               'key5' => 'value5',
-                               'key6' => 'value6',
-                       ],
-               ];
-
-               return [
-                       'system' => [
-                               'data'         => $data,
-                               'possibleCats' => [
-                                       'system',
-                                       'config',
-                                       'other'
-                               ],
-                               'load'         => [
-                                       'system',
-                               ],
-                       ],
-                       'other'  => [
-                               'data'         => $data,
-                               'possibleCats' => [
-                                       'system',
-                                       'config',
-                                       'other'
-                               ],
-                               'load'         => [
-                                       'other',
-                               ],
-                       ],
-                       'config' => [
-                               'data'         => $data,
-                               'possibleCats' => [
-                                       'system',
-                                       'config',
-                                       'other'
-                               ],
-                               'load'         => [
-                                       'config',
-                               ],
-                       ],
-                       'all'    => [
-                               'data'         => $data,
-                               'possibleCats' => [
-                                       'system',
-                                       'config',
-                                       'other'
-                               ],
-                               'load'         => [
-                                       'system',
-                                       'config',
-                                       'other'
-                               ],
-                       ],
-               ];
-       }
-
-       /**
-        * Test the configuration initialization
-        */
-       public function testSetUp(array $data)
-       {
-               $this->configModel->shouldReceive('isConnected')
-                                 ->andReturn(true)
-                                 ->once();
-
-               $this->testedConfig = $this->getInstance();
-               $this->assertInstanceOf(Cache::class, $this->testedConfig->getCache());
-
-               // assert config is loaded everytime
-               $this->assertConfig('config', $data['config']);
-       }
-
-       /**
-        * Test the configuration load() method
-        */
-       public function testLoad(array $data, array $possibleCats, array $load)
-       {
-               $this->testedConfig = $this->getInstance();
-               $this->assertInstanceOf(Cache::class, $this->testedConfig->getCache());
-
-               foreach ($load as $loadedCats) {
-                       $this->testedConfig->load($loadedCats);
-               }
-
-               // Assert at least loaded cats are loaded
-               foreach ($load as $loadedCats) {
-                       $this->assertConfig($loadedCats, $data[$loadedCats]);
-               }
-       }
-
-       public function dataDoubleLoad()
-       {
-               return [
-                       'config' => [
-                               'data1'  => [
-                                       'config' => [
-                                               'key1' => 'value1',
-                                               'key2' => 'value2',
-                                       ],
-                               ],
-                               'data2'  => [
-                                       'config' => [
-                                               'key1' => 'overwritten!',
-                                               'key3' => 'value3',
-                                       ],
-                               ],
-                               'expect' => [
-                                       'config' => [
-                                               // load should overwrite values everytime!
-                                               'key1' => 'overwritten!',
-                                               'key2' => 'value2',
-                                               'key3' => 'value3',
-                                       ],
-                               ],
-                       ],
-                       'other'  => [
-                               'data1'  => [
-                                       'config' => [
-                                               'key12' => 'data4',
-                                               'key45' => 7,
-                                       ],
-                                       'other'  => [
-                                               'key1' => 'value1',
-                                               'key2' => 'value2',
-                                       ],
-                               ],
-                               'data2'  => [
-                                       'other'  => [
-                                               'key1' => 'overwritten!',
-                                               'key3' => 'value3',
-                                       ],
-                                       'config' => [
-                                               'key45' => 45,
-                                               'key52' => true,
-                                       ]
-                               ],
-                               'expect' => [
-                                       'other'  => [
-                                               // load should overwrite values everytime!
-                                               'key1' => 'overwritten!',
-                                               'key2' => 'value2',
-                                               'key3' => 'value3',
-                                       ],
-                                       'config' => [
-                                               'key12' => 'data4',
-                                               'key45' => 45,
-                                               'key52' => true,
-                                       ],
-                               ],
-                       ],
-               ];
-       }
-
-       /**
-        * Test the configuration load() method with overwrite
-        */
-       public function testCacheLoadDouble(array $data1, array $data2, array $expect)
-       {
-               $this->testedConfig = $this->getInstance();
-               $this->assertInstanceOf(Cache::class, $this->testedConfig->getCache());
-
-               foreach ($data1 as $cat => $data) {
-                       $this->testedConfig->load($cat);
-               }
-
-               // Assert at least loaded cats are loaded
-               foreach ($data1 as $cat => $data) {
-                       $this->assertConfig($cat, $data);
-               }
-
-               foreach ($data2 as $cat => $data) {
-                       $this->testedConfig->load($cat);
-               }
-       }
-
-       /**
-        * Test the configuration load without result
-        */
-       public function testLoadWrong()
-       {
-               $this->configModel->shouldReceive('isConnected')->andReturn(true)->once();
-               $this->configModel->shouldReceive('load')->withAnyArgs()->andReturn([])->once();
-
-               $this->testedConfig = $this->getInstance();
-               $this->assertInstanceOf(Cache::class, $this->testedConfig->getCache());
-
-               $this->assertEmpty($this->testedConfig->getCache()->getAll());
-       }
-
-       /**
-        * Test the configuration get() and set() methods without adapter
-        *
-        * @dataProvider dataTests
-        */
-       public function testSetGetWithoutDB($data)
-       {
-               $this->configModel->shouldReceive('isConnected')
-                                 ->andReturn(false)
-                                 ->times(3);
-
-               $this->testedConfig = $this->getInstance();
-               $this->assertInstanceOf(Cache::class, $this->testedConfig->getCache());
-
-               $this->assertTrue($this->testedConfig->set('test', 'it', $data));
-
-               $this->assertEquals($data, $this->testedConfig->get('test', 'it'));
-               $this->assertEquals($data, $this->testedConfig->getCache()->get('test', 'it'));
-       }
-
-       /**
-        * Test the configuration get() and set() methods with a model/db
-        *
-        * @dataProvider dataTests
-        */
-       public function testSetGetWithDB($data)
-       {
-               $this->configModel->shouldReceive('set')->with('test', 'it', $data)->andReturn(true)->once();
-
-               $this->testedConfig = $this->getInstance();
-               $this->assertInstanceOf(Cache::class, $this->testedConfig->getCache());
-
-               $this->assertTrue($this->testedConfig->set('test', 'it', $data));
-
-               $this->assertEquals($data, $this->testedConfig->get('test', 'it'));
-               $this->assertEquals($data, $this->testedConfig->getCache()->get('test', 'it'));
-       }
-
-       /**
-        * Test the configuration get() method with wrong value and no db
-        */
-       public function testGetWrongWithoutDB()
-       {
-               $this->testedConfig = $this->getInstance();
-               $this->assertInstanceOf(Cache::class, $this->testedConfig->getCache());
-
-               // without refresh
-               $this->assertNull($this->testedConfig->get('test', 'it'));
-
-               /// beware that the cache returns '!<unset>!' and not null for a non existing value
-               $this->assertNull($this->testedConfig->getCache()->get('test', 'it'));
-
-               // with default value
-               $this->assertEquals('default', $this->testedConfig->get('test', 'it', 'default'));
-
-               // with default value and refresh
-               $this->assertEquals('default', $this->testedConfig->get('test', 'it', 'default', true));
-       }
-
-       /**
-        * Test the configuration get() method with refresh
-        *
-        * @dataProvider dataTests
-        */
-       public function testGetWithRefresh($data)
-       {
-               $this->configCache->load(['test' => ['it' => 'now']]);
-
-               $this->testedConfig = $this->getInstance();
-               $this->assertInstanceOf(Cache::class, $this->testedConfig->getCache());
-
-               // without refresh
-               $this->assertEquals('now', $this->testedConfig->get('test', 'it'));
-               $this->assertEquals('now', $this->testedConfig->getCache()->get('test', 'it'));
-
-               // with refresh
-               $this->assertEquals($data, $this->testedConfig->get('test', 'it', null, true));
-               $this->assertEquals($data, $this->testedConfig->getCache()->get('test', 'it'));
-
-               // without refresh and wrong value and default
-               $this->assertEquals('default', $this->testedConfig->get('test', 'not', 'default'));
-               $this->assertNull($this->testedConfig->getCache()->get('test', 'not'));
-       }
-
-       /**
-        * Test the configuration delete() method without a model/db
-        *
-        * @dataProvider dataTests
-        */
-       public function testDeleteWithoutDB($data)
-       {
-               $this->configCache->load(['test' => ['it' => $data]]);
-
-               $this->testedConfig = $this->getInstance();
-               $this->assertInstanceOf(Cache::class, $this->testedConfig->getCache());
-
-               $this->assertEquals($data, $this->testedConfig->get('test', 'it'));
-               $this->assertEquals($data, $this->testedConfig->getCache()->get('test', 'it'));
-
-               $this->assertTrue($this->testedConfig->delete('test', 'it'));
-               $this->assertNull($this->testedConfig->get('test', 'it'));
-               $this->assertNull($this->testedConfig->getCache()->get('test', 'it'));
-
-               $this->assertEmpty($this->testedConfig->getCache()->getAll());
-       }
-
-       /**
-        * Test the configuration delete() method with a model/db
-        */
-       public function testDeleteWithDB()
-       {
-               $this->configCache->load(['test' => ['it' => 'now', 'quarter' => 'true']]);
-
-               $this->configModel->shouldReceive('delete')
-                                 ->with('test', 'it')
-                                 ->andReturn(false)
-                                 ->once();
-               $this->configModel->shouldReceive('delete')
-                                 ->with('test', 'second')
-                                 ->andReturn(true)
-                                 ->once();
-               $this->configModel->shouldReceive('delete')
-                                 ->with('test', 'third')
-                                 ->andReturn(false)
-                                 ->once();
-               $this->configModel->shouldReceive('delete')
-                                 ->with('test', 'quarter')
-                                 ->andReturn(true)
-                                 ->once();
-
-               $this->testedConfig = $this->getInstance();
-               $this->assertInstanceOf(Cache::class, $this->testedConfig->getCache());
-
-               // directly set the value to the cache
-               $this->testedConfig->getCache()->set('test', 'it', 'now');
-
-               $this->assertEquals('now', $this->testedConfig->get('test', 'it'));
-               $this->assertEquals('now', $this->testedConfig->getCache()->get('test', 'it'));
-
-               // delete from cache only
-               $this->assertTrue($this->testedConfig->delete('test', 'it'));
-               // delete from db only
-               $this->assertTrue($this->testedConfig->delete('test', 'second'));
-               // no delete
-               $this->assertFalse($this->testedConfig->delete('test', 'third'));
-               // delete both
-               $this->assertTrue($this->testedConfig->delete('test', 'quarter'));
-
-               $this->assertEmpty($this->testedConfig->getCache()->getAll());
-       }
-}
diff --git a/tests/src/Core/Config/JitConfigTest.php b/tests/src/Core/Config/JitConfigTest.php
new file mode 100644 (file)
index 0000000..28aee30
--- /dev/null
@@ -0,0 +1,179 @@
+<?php
+
+namespace Friendica\Test\src\Core\Config;
+
+use Friendica\Core\Config\JitConfig;
+
+class JitConfigTest extends ConfigTest
+{
+       public function getInstance()
+       {
+               return new JitConfig($this->configCache, $this->configModel);
+       }
+
+       /**
+        * @dataProvider dataConfigLoad
+        */
+       public function testSetUp(array $data)
+       {
+               $this->configModel->shouldReceive('load')
+                                 ->with('config')
+                                 ->andReturn(['config' => $data['config']])
+                                 ->once();
+
+               parent::testSetUp($data);
+       }
+
+       /**
+        * @dataProvider dataConfigLoad
+        */
+       public function testLoad(array $data, array $possibleCats, array $load)
+       {
+               $this->configModel->shouldReceive('isConnected')
+                                 ->andReturn(true)
+                                 ->times(count($load) + 1);
+
+               $this->configModel->shouldReceive('load')
+                                 ->with('config')
+                                 ->andReturn(['config' => $data['config']])
+                                 ->once();
+
+               foreach ($load as $loadCat) {
+                       $this->configModel->shouldReceive('load')
+                                         ->with($loadCat)
+                                         ->andReturn([$loadCat => $data[$loadCat]])
+                                         ->once();
+               }
+
+               parent::testLoad($data, $possibleCats, $load);
+       }
+
+       /**
+        * @dataProvider dataDoubleLoad
+        */
+       public function testCacheLoadDouble(array $data1, array $data2, array $expect)
+       {
+               $this->configModel->shouldReceive('isConnected')
+                                 ->andReturn(true)
+                                 ->times(count($data1) + count($data2) + 1);
+
+               $this->configModel->shouldReceive('load')
+                                 ->with('config')
+                                 ->andReturn(['config' => $data1['config']])
+                                 ->once();
+
+               foreach ($data1 as $cat => $data) {
+                       $this->configModel->shouldReceive('load')
+                                         ->with($cat)
+                                         ->andReturn([$cat => $data])
+                                         ->once();
+               }
+
+
+               foreach ($data2 as $cat => $data) {
+                       $this->configModel->shouldReceive('load')
+                                         ->with($cat)
+                                         ->andReturn([$cat => $data])
+                                         ->once();
+               }
+
+               parent::testCacheLoadDouble($data1, $data2, $expect);
+
+               // Assert the expected categories
+               foreach ($data2 as $cat => $data) {
+                       $this->assertConfig($cat, $expect[$cat]);
+               }
+       }
+
+       /**
+        * @dataProvider dataTests
+        */
+       public function testSetGetWithDB($data)
+       {
+               $this->configModel->shouldReceive('isConnected')
+                                 ->andReturn(true)
+                                 ->times(3);
+
+               $this->configModel->shouldReceive('load')->with('config')->andReturn(['config' => []])->once();
+
+               parent::testSetGetWithDB($data);
+       }
+
+       /**
+        * @dataProvider dataTests
+        */
+       public function testGetWithRefresh($data)
+       {
+               $this->configModel->shouldReceive('isConnected')
+                                 ->andReturn(true)
+                                 ->times(4);
+
+               // constructor loading
+               $this->configModel->shouldReceive('load')
+                                 ->with('config')
+                                 ->andReturn(['config' => []])
+                                 ->once();
+
+               // mocking one get without result
+               $this->configModel->shouldReceive('get')
+                                 ->with('test', 'it')
+                                 ->andReturn(null)
+                                 ->once();
+
+               // mocking the data get
+               $this->configModel->shouldReceive('get')
+                                 ->with('test', 'it')
+                                 ->andReturn($data)
+                                 ->once();
+
+               // mocking second get
+               $this->configModel->shouldReceive('get')
+                                 ->with('test', 'not')
+                                 ->andReturn(null)
+                                 ->once();
+
+               parent::testGetWithRefresh($data);
+       }
+
+       public function testGetWrongWithoutDB()
+       {
+               $this->configModel->shouldReceive('isConnected')
+                                 ->andReturn(false)
+                                 ->times(4);
+
+               parent::testGetWrongWithoutDB();
+       }
+
+       /**
+        * @dataProvider dataTests
+        */
+       public function testDeleteWithoutDB($data)
+       {
+               $this->configModel->shouldReceive('isConnected')
+                                 ->andReturn(false)
+                                 ->times(4);
+
+               parent::testDeleteWithoutDB($data);
+       }
+
+       public function testDeleteWithDB()
+       {
+               $this->configModel->shouldReceive('isConnected')
+                                 ->andReturn(true)
+                                 ->times(6);
+
+               // constructor loading
+               $this->configModel->shouldReceive('load')
+                                 ->with('config')
+                                 ->andReturn(['config' => []])
+                                 ->once();
+
+               // mocking one get without result
+               $this->configModel->shouldReceive('get')
+                                 ->with('test', 'it')
+                                 ->andReturn(null)
+                                 ->once();
+
+               parent::testDeleteWithDB();
+       }
+}
diff --git a/tests/src/Core/Config/JitConfigurationTest.php b/tests/src/Core/Config/JitConfigurationTest.php
deleted file mode 100644 (file)
index 520dcc2..0000000
+++ /dev/null
@@ -1,179 +0,0 @@
-<?php
-
-namespace Friendica\Test\src\Core\Config;
-
-use Friendica\Core\Config\JitConfig;
-
-class JitConfigurationTest extends ConfigurationTest
-{
-       public function getInstance()
-       {
-               return new JitConfig($this->configCache, $this->configModel);
-       }
-
-       /**
-        * @dataProvider dataConfigLoad
-        */
-       public function testSetUp(array $data)
-       {
-               $this->configModel->shouldReceive('load')
-                                 ->with('config')
-                                 ->andReturn(['config' => $data['config']])
-                                 ->once();
-
-               parent::testSetUp($data);
-       }
-
-       /**
-        * @dataProvider dataConfigLoad
-        */
-       public function testLoad(array $data, array $possibleCats, array $load)
-       {
-               $this->configModel->shouldReceive('isConnected')
-                                 ->andReturn(true)
-                                 ->times(count($load) + 1);
-
-               $this->configModel->shouldReceive('load')
-                                 ->with('config')
-                                 ->andReturn(['config' => $data['config']])
-                                 ->once();
-
-               foreach ($load as $loadCat) {
-                       $this->configModel->shouldReceive('load')
-                                         ->with($loadCat)
-                                         ->andReturn([$loadCat => $data[$loadCat]])
-                                         ->once();
-               }
-
-               parent::testLoad($data, $possibleCats, $load);
-       }
-
-       /**
-        * @dataProvider dataDoubleLoad
-        */
-       public function testCacheLoadDouble(array $data1, array $data2, array $expect)
-       {
-               $this->configModel->shouldReceive('isConnected')
-                                 ->andReturn(true)
-                                 ->times(count($data1) + count($data2) + 1);
-
-               $this->configModel->shouldReceive('load')
-                                 ->with('config')
-                                 ->andReturn(['config' => $data1['config']])
-                                 ->once();
-
-               foreach ($data1 as $cat => $data) {
-                       $this->configModel->shouldReceive('load')
-                                         ->with($cat)
-                                         ->andReturn([$cat => $data])
-                                         ->once();
-               }
-
-
-               foreach ($data2 as $cat => $data) {
-                       $this->configModel->shouldReceive('load')
-                                         ->with($cat)
-                                         ->andReturn([$cat => $data])
-                                         ->once();
-               }
-
-               parent::testCacheLoadDouble($data1, $data2, $expect);
-
-               // Assert the expected categories
-               foreach ($data2 as $cat => $data) {
-                       $this->assertConfig($cat, $expect[$cat]);
-               }
-       }
-
-       /**
-        * @dataProvider dataTests
-        */
-       public function testSetGetWithDB($data)
-       {
-               $this->configModel->shouldReceive('isConnected')
-                                 ->andReturn(true)
-                                 ->times(3);
-
-               $this->configModel->shouldReceive('load')->with('config')->andReturn(['config' => []])->once();
-
-               parent::testSetGetWithDB($data);
-       }
-
-       /**
-        * @dataProvider dataTests
-        */
-       public function testGetWithRefresh($data)
-       {
-               $this->configModel->shouldReceive('isConnected')
-                                 ->andReturn(true)
-                                 ->times(4);
-
-               // constructor loading
-               $this->configModel->shouldReceive('load')
-                                 ->with('config')
-                                 ->andReturn(['config' => []])
-                                 ->once();
-
-               // mocking one get without result
-               $this->configModel->shouldReceive('get')
-                                 ->with('test', 'it')
-                                 ->andReturn(null)
-                                 ->once();
-
-               // mocking the data get
-               $this->configModel->shouldReceive('get')
-                                 ->with('test', 'it')
-                                 ->andReturn($data)
-                                 ->once();
-
-               // mocking second get
-               $this->configModel->shouldReceive('get')
-                                 ->with('test', 'not')
-                                 ->andReturn(null)
-                                 ->once();
-
-               parent::testGetWithRefresh($data);
-       }
-
-       public function testGetWrongWithoutDB()
-       {
-               $this->configModel->shouldReceive('isConnected')
-                                 ->andReturn(false)
-                                 ->times(4);
-
-               parent::testGetWrongWithoutDB();
-       }
-
-       /**
-        * @dataProvider dataTests
-        */
-       public function testDeleteWithoutDB($data)
-       {
-               $this->configModel->shouldReceive('isConnected')
-                                 ->andReturn(false)
-                                 ->times(4);
-
-               parent::testDeleteWithoutDB($data);
-       }
-
-       public function testDeleteWithDB()
-       {
-               $this->configModel->shouldReceive('isConnected')
-                                 ->andReturn(true)
-                                 ->times(6);
-
-               // constructor loading
-               $this->configModel->shouldReceive('load')
-                                 ->with('config')
-                                 ->andReturn(['config' => []])
-                                 ->once();
-
-               // mocking one get without result
-               $this->configModel->shouldReceive('get')
-                                 ->with('test', 'it')
-                                 ->andReturn(null)
-                                 ->once();
-
-               parent::testDeleteWithDB();
-       }
-}
diff --git a/tests/src/Core/Config/JitPConfigurationTest.php b/tests/src/Core/Config/JitPConfigurationTest.php
deleted file mode 100644 (file)
index c45584f..0000000
+++ /dev/null
@@ -1,145 +0,0 @@
-<?php
-
-namespace Friendica\Test\src\Core\Config;
-
-use Friendica\Core\PConfig\JitPConfig;
-
-class JitPConfigurationTest extends PConfigurationTest
-{
-       public function getInstance()
-       {
-               return new JitPConfig($this->configCache, $this->configModel);
-       }
-
-       /**
-        * @dataProvider dataConfigLoad
-        */
-       public function testLoad(int $uid, array $data, array $possibleCats, array $load)
-       {
-               $this->configModel->shouldReceive('isConnected')
-                                 ->andReturn(true)
-                                 ->times(count($load));
-
-               foreach ($load as $loadCat) {
-                       $this->configModel->shouldReceive('load')
-                                         ->with($uid, $loadCat)
-                                         ->andReturn([$loadCat => $data[$loadCat]])
-                                         ->once();
-               }
-
-               parent::testLoad($uid, $data, $possibleCats, $load);
-       }
-
-       /**
-        * @dataProvider dataDoubleLoad
-        */
-       public function testCacheLoadDouble(int $uid, array $data1, array $data2, array $expect)
-       {
-               $this->configModel->shouldReceive('isConnected')
-                                 ->andReturn(true)
-                                 ->times(count($data1) + count($data2));
-
-               foreach ($data1 as $cat => $data) {
-                       $this->configModel->shouldReceive('load')
-                                         ->with($uid, $cat)
-                                         ->andReturn([$cat => $data])
-                                         ->once();
-               }
-
-
-               foreach ($data2 as $cat => $data) {
-                       $this->configModel->shouldReceive('load')
-                                         ->with($uid, $cat)
-                                         ->andReturn([$cat => $data])
-                                         ->once();
-               }
-
-               parent::testCacheLoadDouble($uid, $data1, $data2, $expect);
-
-               // Assert the expected categories
-               foreach ($data2 as $cat => $data) {
-                       $this->assertConfig($uid, $cat, $expect[$cat]);
-               }
-       }
-
-       /**
-        * @dataProvider dataTests
-        */
-       public function testSetGetWithoutDB(int $uid, $data)
-       {
-               $this->configModel->shouldReceive('isConnected')
-                                 ->andReturn(false)
-                                 ->times(2);
-
-               parent::testSetGetWithoutDB($uid, $data);
-       }
-
-       /**
-        * @dataProvider dataTests
-        */
-       public function testSetGetWithDB(int $uid, $data)
-       {
-               $this->configModel->shouldReceive('isConnected')
-                                 ->andReturn(true)
-                                 ->times(2);
-
-               parent::testSetGetWithDB($uid, $data);
-       }
-
-       /**
-        * @dataProvider dataTests
-        */
-       public function testGetWithRefresh(int $uid, $data)
-       {
-               $this->configModel->shouldReceive('isConnected')
-                                 ->andReturn(true)
-                                 ->times(3);
-
-               // mocking one get without result
-               $this->configModel->shouldReceive('get')
-                                 ->with($uid, 'test', 'it')
-                                 ->andReturn(null)
-                                 ->once();
-
-               // mocking the data get
-               $this->configModel->shouldReceive('get')
-                                 ->with($uid, 'test', 'it')
-                                 ->andReturn($data)
-                                 ->once();
-
-               // mocking second get
-               $this->configModel->shouldReceive('get')
-                                 ->with($uid, 'test', 'not')
-                                 ->andReturn(null)
-                                 ->once();
-
-               parent::testGetWithRefresh($uid, $data);
-       }
-
-       /**
-        * @dataProvider dataTests
-        */
-       public function testDeleteWithoutDB(int $uid, $data)
-       {
-               $this->configModel->shouldReceive('isConnected')
-                                 ->andReturn(false)
-                                 ->times(3);
-
-               parent::testDeleteWithoutDB($uid, $data);
-       }
-
-       public function testDeleteWithDB()
-       {
-               $this->configModel->shouldReceive('isConnected')
-                                 ->andReturn(true)
-                                 ->times(5);
-
-               // mocking one get without result
-               $this->configModel->shouldReceive('get')
-                                 ->with(42, 'test', 'it')
-                                 ->andReturn(null)
-                                 ->once();
-
-               parent::testDeleteWithDB();
-       }
-}
diff --git a/tests/src/Core/Config/PConfigurationTest.php b/tests/src/Core/Config/PConfigurationTest.php
deleted file mode 100644 (file)
index c8429b2..0000000
+++ /dev/null
@@ -1,475 +0,0 @@
-<?php
-
-namespace Friendica\Test\src\Core\Config;
-
-use Friendica\Core\PConfig\Cache;
-use Friendica\Core\BasePConfig;
-use Friendica\Model\Config\PConfig as PConfigModel;
-use Friendica\Test\MockedTest;
-use Mockery;
-use Mockery\MockInterface;
-
-abstract class PConfigurationTest extends MockedTest
-{
-       /** @var PConfigModel|MockInterface */
-       protected $configModel;
-
-       /** @var Cache */
-       protected $configCache;
-
-       /** @var BasePConfig */
-       protected $testedConfig;
-
-       /**
-        * Assert a config tree
-        *
-        * @param int    $uid  The uid to assert
-        * @param string $cat  The category to assert
-        * @param array  $data The result data array
-        */
-       protected function assertConfig(int $uid, string $cat, array $data)
-       {
-               $result = $this->testedConfig->getCache()->getAll();
-
-               $this->assertNotEmpty($result);
-               $this->assertArrayHasKey($uid, $result);
-               $this->assertArrayHasKey($cat, $result[$uid]);
-               $this->assertArraySubset($data, $result[$uid][$cat]);
-       }
-
-
-       protected function setUp()
-       {
-               parent::setUp();
-
-               // Create the config model
-               $this->configModel = Mockery::mock(PConfigModel::class);
-               $this->configCache = new Cache();
-       }
-
-       /**
-        * @return BasePConfig
-        */
-       public abstract function getInstance();
-
-       public function dataTests()
-       {
-               return [
-                       'string'       => ['uid' => 1, 'data' => 'it'],
-                       'boolTrue'     => ['uid' => 2, 'data' => true],
-                       'boolFalse'    => ['uid' => 3, 'data' => false],
-                       'integer'      => ['uid' => 4, 'data' => 235],
-                       'decimal'      => ['uid' => 5, 'data' => 2.456],
-                       'array'        => ['uid' => 6, 'data' => ['1', 2, '3', true, false]],
-                       'boolIntTrue'  => ['uid' => 7, 'data' => 1],
-                       'boolIntFalse' => ['uid' => 8, 'data' => 0],
-               ];
-       }
-
-       public function dataConfigLoad()
-       {
-               $data = [
-                       'system' => [
-                               'key1' => 'value1',
-                               'key2' => 'value2',
-                               'key3' => 'value3',
-                       ],
-                       'config' => [
-                               'key1' => 'value1a',
-                               'key4' => 'value4',
-                       ],
-                       'other'  => [
-                               'key5' => 'value5',
-                               'key6' => 'value6',
-                       ],
-               ];
-
-               return [
-                       'system' => [
-                               'uid' => 1,
-                               'data'         => $data,
-                               'possibleCats' => [
-                                       'system',
-                                       'config',
-                                       'other'
-                               ],
-                               'load'         => [
-                                       'system',
-                               ],
-                       ],
-                       'other'  => [
-                               'uid' => 2,
-                               'data'         => $data,
-                               'possibleCats' => [
-                                       'system',
-                                       'config',
-                                       'other'
-                               ],
-                               'load'         => [
-                                       'other',
-                               ],
-                       ],
-                       'config' => [
-                               'uid' => 3,
-                               'data'         => $data,
-                               'possibleCats' => [
-                                       'system',
-                                       'config',
-                                       'other'
-                               ],
-                               'load'         => [
-                                       'config',
-                               ],
-                       ],
-                       'all'    => [
-                               'uid' => 4,
-                               'data'         => $data,
-                               'possibleCats' => [
-                                       'system',
-                                       'config',
-                                       'other'
-                               ],
-                               'load'         => [
-                                       'system',
-                                       'config',
-                                       'other'
-                               ],
-                       ],
-               ];
-       }
-
-       /**
-        * Test the configuration initialization
-        * @dataProvider dataConfigLoad
-        */
-       public function testSetUp(int $uid, array $data)
-       {
-               $this->testedConfig = $this->getInstance();
-               $this->assertInstanceOf(Cache::class, $this->testedConfig->getCache());
-
-               $this->assertEmpty($this->testedConfig->getCache()->getAll());
-       }
-
-       /**
-        * Test the configuration load() method
-        */
-       public function testLoad(int $uid, array $data, array $possibleCats, array $load)
-       {
-               $this->testedConfig = $this->getInstance();
-               $this->assertInstanceOf(Cache::class, $this->testedConfig->getCache());
-
-               foreach ($load as $loadedCats) {
-                       $this->testedConfig->load($uid, $loadedCats);
-               }
-
-               // Assert at least loaded cats are loaded
-               foreach ($load as $loadedCats) {
-                       $this->assertConfig($uid, $loadedCats, $data[$loadedCats]);
-               }
-       }
-
-       public function dataDoubleLoad()
-       {
-               return [
-                       'config' => [
-                               'uid' => 1,
-                               'data1'  => [
-                                       'config' => [
-                                               'key1' => 'value1',
-                                               'key2' => 'value2',
-                                       ],
-                               ],
-                               'data2'  => [
-                                       'config' => [
-                                               'key1' => 'overwritten!',
-                                               'key3' => 'value3',
-                                       ],
-                               ],
-                               'expect' => [
-                                       'config' => [
-                                               // load should overwrite values everytime!
-                                               'key1' => 'overwritten!',
-                                               'key2' => 'value2',
-                                               'key3' => 'value3',
-                                       ],
-                               ],
-                       ],
-                       'other'  => [
-                               'uid' => 1,
-                               'data1'  => [
-                                       'config' => [
-                                               'key12' => 'data4',
-                                               'key45' => 7,
-                                       ],
-                                       'other'  => [
-                                               'key1' => 'value1',
-                                               'key2' => 'value2',
-                                       ],
-                               ],
-                               'data2'  => [
-                                       'other'  => [
-                                               'key1' => 'overwritten!',
-                                               'key3' => 'value3',
-                                       ],
-                                       'config' => [
-                                               'key45' => 45,
-                                               'key52' => true,
-                                       ]
-                               ],
-                               'expect' => [
-                                       'other'  => [
-                                               // load should overwrite values everytime!
-                                               'key1' => 'overwritten!',
-                                               'key2' => 'value2',
-                                               'key3' => 'value3',
-                                       ],
-                                       'config' => [
-                                               'key12' => 'data4',
-                                               'key45' => 45,
-                                               'key52' => true,
-                                       ],
-                               ],
-                       ],
-               ];
-       }
-
-       /**
-        * Test the configuration load() method with overwrite
-        */
-       public function testCacheLoadDouble(int $uid, array $data1, array $data2, array $expect)
-       {
-               $this->testedConfig = $this->getInstance();
-               $this->assertInstanceOf(Cache::class, $this->testedConfig->getCache());
-
-               foreach ($data1 as $cat => $data) {
-                       $this->testedConfig->load($uid, $cat);
-               }
-
-               // Assert at least loaded cats are loaded
-               foreach ($data1 as $cat => $data) {
-                       $this->assertConfig($uid, $cat, $data);
-               }
-
-               foreach ($data2 as $cat => $data) {
-                       $this->testedConfig->load($uid, $cat);
-               }
-       }
-
-       /**
-        * Test the configuration get() and set() methods without adapter
-        *
-        * @dataProvider dataTests
-        */
-       public function testSetGetWithoutDB(int $uid, $data)
-       {
-               $this->testedConfig = $this->getInstance();
-               $this->assertInstanceOf(Cache::class, $this->testedConfig->getCache());
-
-               $this->assertTrue($this->testedConfig->set($uid, 'test', 'it', $data));
-
-               $this->assertEquals($data, $this->testedConfig->get($uid, 'test', 'it'));
-               $this->assertEquals($data, $this->testedConfig->getCache()->get($uid, 'test', 'it'));
-       }
-
-       /**
-        * Test the configuration get() and set() methods with a model/db
-        *
-        * @dataProvider dataTests
-        */
-       public function testSetGetWithDB(int $uid, $data)
-       {
-               $this->configModel->shouldReceive('set')
-                                 ->with($uid, 'test', 'it', $data)
-                                 ->andReturn(true)
-                                 ->once();
-
-               $this->testedConfig = $this->getInstance();
-               $this->assertInstanceOf(Cache::class, $this->testedConfig->getCache());
-
-               $this->assertTrue($this->testedConfig->set($uid, 'test', 'it', $data));
-
-               $this->assertEquals($data, $this->testedConfig->get($uid, 'test', 'it'));
-               $this->assertEquals($data, $this->testedConfig->getCache()->get($uid, 'test', 'it'));
-       }
-
-       /**
-        * Test the configuration get() method with wrong value and no db
-        */
-       public function testGetWrongWithoutDB()
-       {
-               $this->testedConfig = $this->getInstance();
-               $this->assertInstanceOf(Cache::class, $this->testedConfig->getCache());
-
-               // without refresh
-               $this->assertNull($this->testedConfig->get(0, 'test', 'it'));
-
-               /// beware that the cache returns '!<unset>!' and not null for a non existing value
-               $this->assertNull($this->testedConfig->getCache()->get(0, 'test', 'it'));
-
-               // with default value
-               $this->assertEquals('default', $this->testedConfig->get(0, 'test', 'it', 'default'));
-
-               // with default value and refresh
-               $this->assertEquals('default', $this->testedConfig->get(0, 'test', 'it', 'default', true));
-       }
-
-       /**
-        * Test the configuration get() method with refresh
-        *
-        * @dataProvider dataTests
-        */
-       public function testGetWithRefresh(int $uid, $data)
-       {
-               $this->configCache->load($uid, ['test' => ['it' => 'now']]);
-
-               $this->testedConfig = $this->getInstance();
-               $this->assertInstanceOf(Cache::class, $this->testedConfig->getCache());
-
-               // without refresh
-               $this->assertEquals('now', $this->testedConfig->get($uid, 'test', 'it'));
-               $this->assertEquals('now', $this->testedConfig->getCache()->get($uid, 'test', 'it'));
-
-               // with refresh
-               $this->assertEquals($data, $this->testedConfig->get($uid, 'test', 'it', null, true));
-               $this->assertEquals($data, $this->testedConfig->getCache()->get($uid, 'test', 'it'));
-
-               // without refresh and wrong value and default
-               $this->assertEquals('default', $this->testedConfig->get($uid, 'test', 'not', 'default'));
-               $this->assertNull($this->testedConfig->getCache()->get($uid, 'test', 'not'));
-       }
-
-       /**
-        * Test the configuration delete() method without a model/db
-        *
-        * @dataProvider dataTests
-        */
-       public function testDeleteWithoutDB(int $uid, $data)
-       {
-               $this->configCache->load($uid, ['test' => ['it' => $data]]);
-
-               $this->testedConfig = $this->getInstance();
-               $this->assertInstanceOf(Cache::class, $this->testedConfig->getCache());
-
-               $this->assertEquals($data, $this->testedConfig->get($uid, 'test', 'it'));
-               $this->assertEquals($data, $this->testedConfig->getCache()->get($uid, 'test', 'it'));
-
-               $this->assertTrue($this->testedConfig->delete($uid, 'test', 'it'));
-               $this->assertNull($this->testedConfig->get($uid, 'test', 'it'));
-               $this->assertNull($this->testedConfig->getCache()->get($uid, 'test', 'it'));
-
-               $this->assertEmpty($this->testedConfig->getCache()->getAll());
-       }
-
-       /**
-        * Test the configuration delete() method with a model/db
-        */
-       public function testDeleteWithDB()
-       {
-               $uid = 42;
-
-               $this->configCache->load($uid, ['test' => ['it' => 'now', 'quarter' => 'true']]);
-
-               $this->configModel->shouldReceive('delete')
-                                 ->with($uid, 'test', 'it')
-                                 ->andReturn(false)
-                                 ->once();
-               $this->configModel->shouldReceive('delete')
-                                 ->with($uid, 'test', 'second')
-                                 ->andReturn(true)
-                                 ->once();
-               $this->configModel->shouldReceive('delete')
-                                 ->with($uid, 'test', 'third')
-                                 ->andReturn(false)
-                                 ->once();
-               $this->configModel->shouldReceive('delete')
-                                 ->with($uid, 'test', 'quarter')
-                                 ->andReturn(true)
-                                 ->once();
-
-               $this->testedConfig = $this->getInstance();
-               $this->assertInstanceOf(Cache::class, $this->testedConfig->getCache());
-
-               // directly set the value to the cache
-               $this->testedConfig->getCache()->set($uid, 'test', 'it', 'now');
-
-               $this->assertEquals('now', $this->testedConfig->get($uid, 'test', 'it'));
-               $this->assertEquals('now', $this->testedConfig->getCache()->get($uid, 'test', 'it'));
-
-               // delete from cache only
-               $this->assertTrue($this->testedConfig->delete($uid, 'test', 'it'));
-               // delete from db only
-               $this->assertTrue($this->testedConfig->delete($uid, 'test', 'second'));
-               // no delete
-               $this->assertFalse($this->testedConfig->delete($uid, 'test', 'third'));
-               // delete both
-               $this->assertTrue($this->testedConfig->delete($uid, 'test', 'quarter'));
-
-               $this->assertEmpty($this->testedConfig->getCache()->getAll());
-       }
-
-       public function dataMultiUid()
-       {
-               return [
-                       'normal' => [
-                               'data1' => [
-                                       'uid'  => 1,
-                                       'data' => [
-                                               'cat1' => [
-                                                       'key1' => 'value1',
-                                               ],
-                                               'cat2' => [
-                                                       'key2' => 'value2',
-                                               ]
-                                       ],
-                               ],
-                               'data2' => [
-                                       'uid' => 2,
-                                       'data' => [
-                                               'cat1' => [
-                                                       'key1' => 'value1a',
-                                               ],
-                                               'cat2' => [
-                                                       'key2' => 'value2',
-                                               ],
-                                       ],
-                               ],
-                       ],
-               ];
-       }
-
-       /**
-        * Test if multiple uids for caching are usable without errors
-        * @dataProvider dataMultiUid
-        */
-       public function testMultipleUidsWithCache(array $data1, array $data2)
-       {
-               $this->configCache->load($data1['uid'], $data1['data']);
-               $this->configCache->load($data2['uid'], $data2['data']);
-
-               $this->testedConfig = $this->getInstance();
-               $this->assertInstanceOf(Cache::class, $this->testedConfig->getCache());
-
-               $this->assertConfig($data1['uid'], 'cat1', $data1['data']['cat1']);
-               $this->assertConfig($data1['uid'], 'cat2', $data1['data']['cat2']);
-               $this->assertConfig($data2['uid'], 'cat1', $data2['data']['cat1']);
-               $this->assertConfig($data2['uid'], 'cat2', $data2['data']['cat2']);
-       }
-
-       /**
-        * Test when using an invalid UID
-        * @todo check it the clean way before using the config class
-        */
-       public function testInvalidUid()
-       {
-               // bad UID!
-               $uid = 0;
-
-               $this->testedConfig = $this->getInstance();
-
-               $this->assertNull($this->testedConfig->get($uid, 'cat1', 'cat2'));
-               $this->assertEquals('fallback!', $this->testedConfig->get($uid, 'cat1', 'cat2', 'fallback!'));
-
-               $this->assertFalse($this->testedConfig->set($uid, 'cat1', 'key1', 'doesn\'t matter!'));
-               $this->assertFalse($this->testedConfig->delete($uid, 'cat1', 'key1'));
-       }
-}
diff --git a/tests/src/Core/Config/PreloadConfigTest.php b/tests/src/Core/Config/PreloadConfigTest.php
new file mode 100644 (file)
index 0000000..68db7c6
--- /dev/null
@@ -0,0 +1,140 @@
+<?php
+
+namespace Friendica\Test\src\Core\Config;
+
+use Friendica\Core\Config\PreloadConfig;
+
+class PreloadConfigTest extends ConfigTest
+{
+       public function getInstance()
+       {
+               return new PreloadConfig($this->configCache, $this->configModel);
+       }
+
+       /**
+        * @dataProvider dataConfigLoad
+        */
+       public function testSetUp(array $data)
+       {
+               $this->configModel->shouldReceive('load')
+                                 ->andReturn($data)
+                                 ->once();
+
+               parent::testSetUp($data);
+       }
+
+       /**
+        * @dataProvider dataConfigLoad
+        */
+       public function testLoad(array $data, array $possibleCats, array $load)
+       {
+               $this->configModel->shouldReceive('isConnected')
+                                 ->andReturn(true)
+                                 ->once();
+
+               $this->configModel->shouldReceive('load')
+                                 ->andReturn($data)
+                                 ->once();
+
+               parent::testLoad($data, $possibleCats, $load);
+
+               // Assert that every category is loaded everytime
+               foreach ($data as $cat => $values) {
+                       $this->assertConfig($cat, $values);
+               }
+       }
+
+       /**
+        * @dataProvider dataDoubleLoad
+        */
+       public function testCacheLoadDouble(array $data1, array $data2, array $expect)
+       {
+               $this->configModel->shouldReceive('isConnected')
+                                 ->andReturn(true)
+                                 ->once();
+
+               $this->configModel->shouldReceive('load')
+                                 ->andReturn($data1)
+                                 ->once();
+
+               parent::testCacheLoadDouble($data1, $data2, $expect);
+
+               // Assert that every category is loaded everytime and is NOT overwritten
+               foreach ($data1 as $cat => $values) {
+                       $this->assertConfig($cat, $values);
+               }
+       }
+
+       /**
+        * @dataProvider dataTests
+        */
+       public function testSetGetWithDB($data)
+       {
+               $this->configModel->shouldReceive('isConnected')
+                                 ->andReturn(true)
+                                 ->times(2);
+
+               $this->configModel->shouldReceive('load')->andReturn(['config' => []])->once();
+
+               parent::testSetGetWithDB($data);
+       }
+
+       /**
+        * @dataProvider dataTests
+        */
+       public function testGetWithRefresh($data)
+       {
+               $this->configModel->shouldReceive('isConnected')
+                                 ->andReturn(true)
+                                 ->times(2);
+
+               // constructor loading
+               $this->configModel->shouldReceive('load')
+                                 ->andReturn(['config' => []])
+                                 ->once();
+
+               // mocking one get
+               $this->configModel->shouldReceive('get')
+                                 ->with('test', 'it')
+                                 ->andReturn($data)
+                                 ->once();
+
+               parent::testGetWithRefresh($data);
+       }
+
+
+       public function testGetWrongWithoutDB()
+       {
+               $this->configModel->shouldReceive('isConnected')
+                                 ->andReturn(false)
+                                 ->times(2);
+
+               parent::testGetWrongWithoutDB();
+       }
+
+       /**
+        * @dataProvider dataTests
+        */
+       public function testDeleteWithoutDB($data)
+       {
+               $this->configModel->shouldReceive('isConnected')
+                                 ->andReturn(false)
+                                 ->times(2);
+
+               parent::testDeleteWithoutDB($data);
+       }
+
+       public function testDeleteWithDB()
+       {
+               $this->configModel->shouldReceive('isConnected')
+                                 ->andReturn(true)
+                                 ->times(5);
+
+               // constructor loading
+               $this->configModel->shouldReceive('load')
+                                 ->andReturn(['config' => []])
+                                 ->once();
+
+               parent::testDeleteWithDB();
+       }
+}
diff --git a/tests/src/Core/Config/PreloadConfigurationTest.php b/tests/src/Core/Config/PreloadConfigurationTest.php
deleted file mode 100644 (file)
index 1325afe..0000000
+++ /dev/null
@@ -1,140 +0,0 @@
-<?php
-
-namespace Friendica\Test\src\Core\Config;
-
-use Friendica\Core\Config\PreloadConfig;
-
-class PreloadConfigurationTest extends ConfigurationTest
-{
-       public function getInstance()
-       {
-               return new PreloadConfig($this->configCache, $this->configModel);
-       }
-
-       /**
-        * @dataProvider dataConfigLoad
-        */
-       public function testSetUp(array $data)
-       {
-               $this->configModel->shouldReceive('load')
-                                 ->andReturn($data)
-                                 ->once();
-
-               parent::testSetUp($data);
-       }
-
-       /**
-        * @dataProvider dataConfigLoad
-        */
-       public function testLoad(array $data, array $possibleCats, array $load)
-       {
-               $this->configModel->shouldReceive('isConnected')
-                                 ->andReturn(true)
-                                 ->once();
-
-               $this->configModel->shouldReceive('load')
-                                 ->andReturn($data)
-                                 ->once();
-
-               parent::testLoad($data, $possibleCats, $load);
-
-               // Assert that every category is loaded everytime
-               foreach ($data as $cat => $values) {
-                       $this->assertConfig($cat, $values);
-               }
-       }
-
-       /**
-        * @dataProvider dataDoubleLoad
-        */
-       public function testCacheLoadDouble(array $data1, array $data2, array $expect)
-       {
-               $this->configModel->shouldReceive('isConnected')
-                                 ->andReturn(true)
-                                 ->once();
-
-               $this->configModel->shouldReceive('load')
-                                 ->andReturn($data1)
-                                 ->once();
-
-               parent::testCacheLoadDouble($data1, $data2, $expect);
-
-               // Assert that every category is loaded everytime and is NOT overwritten
-               foreach ($data1 as $cat => $values) {
-                       $this->assertConfig($cat, $values);
-               }
-       }
-
-       /**
-        * @dataProvider dataTests
-        */
-       public function testSetGetWithDB($data)
-       {
-               $this->configModel->shouldReceive('isConnected')
-                                 ->andReturn(true)
-                                 ->times(2);
-
-               $this->configModel->shouldReceive('load')->andReturn(['config' => []])->once();
-
-               parent::testSetGetWithDB($data);
-       }
-
-       /**
-        * @dataProvider dataTests
-        */
-       public function testGetWithRefresh($data)
-       {
-               $this->configModel->shouldReceive('isConnected')
-                                 ->andReturn(true)
-                                 ->times(2);
-
-               // constructor loading
-               $this->configModel->shouldReceive('load')
-                                 ->andReturn(['config' => []])
-                                 ->once();
-
-               // mocking one get
-               $this->configModel->shouldReceive('get')
-                                 ->with('test', 'it')
-                                 ->andReturn($data)
-                                 ->once();
-
-               parent::testGetWithRefresh($data);
-       }
-
-
-       public function testGetWrongWithoutDB()
-       {
-               $this->configModel->shouldReceive('isConnected')
-                                 ->andReturn(false)
-                                 ->times(2);
-
-               parent::testGetWrongWithoutDB();
-       }
-
-       /**
-        * @dataProvider dataTests
-        */
-       public function testDeleteWithoutDB($data)
-       {
-               $this->configModel->shouldReceive('isConnected')
-                                 ->andReturn(false)
-                                 ->times(2);
-
-               parent::testDeleteWithoutDB($data);
-       }
-
-       public function testDeleteWithDB()
-       {
-               $this->configModel->shouldReceive('isConnected')
-                                 ->andReturn(true)
-                                 ->times(5);
-
-               // constructor loading
-               $this->configModel->shouldReceive('load')
-                                 ->andReturn(['config' => []])
-                                 ->once();
-
-               parent::testDeleteWithDB();
-       }
-}
diff --git a/tests/src/Core/Config/PreloadPConfigurationTest.php b/tests/src/Core/Config/PreloadPConfigurationTest.php
deleted file mode 100644 (file)
index 79d0d49..0000000
+++ /dev/null
@@ -1,137 +0,0 @@
-<?php
-
-namespace Friendica\Test\src\Core\Config;
-
-use Friendica\Core\PConfig\PreloadPConfig;
-
-class PreloadPConfigurationTest extends PConfigurationTest
-{
-       public function getInstance()
-       {
-               return new PreloadPConfig($this->configCache, $this->configModel);
-       }
-
-       /**
-        * @dataProvider dataConfigLoad
-        */
-       public function testLoad(int $uid, array $data, array $possibleCats, array $load)
-       {
-               $this->configModel->shouldReceive('isConnected')
-                                 ->andReturn(true)
-                                 ->once();
-
-               $this->configModel->shouldReceive('load')
-                                 ->with($uid)
-                                 ->andReturn($data)
-                                 ->once();
-
-               parent::testLoad($uid, $data, $possibleCats, $load);
-
-               // Assert that every category is loaded everytime
-               foreach ($data as $cat => $values) {
-                       $this->assertConfig($uid, $cat, $values);
-               }
-       }
-
-       /**
-        * @dataProvider dataDoubleLoad
-        */
-       public function testCacheLoadDouble(int $uid, array $data1, array $data2, array $expect)
-       {
-               $this->configModel->shouldReceive('isConnected')
-                                 ->andReturn(true)
-                                 ->once();
-
-               $this->configModel->shouldReceive('load')
-                                 ->with($uid)
-                                 ->andReturn($data1)
-                                 ->once();
-
-               parent::testCacheLoadDouble($uid, $data1, $data2, $expect);
-
-               // Assert that every category is loaded everytime and is NOT overwritten
-               foreach ($data1 as $cat => $values) {
-                       $this->assertConfig($uid, $cat, $values);
-               }
-       }
-
-       /**
-        * @dataProvider dataTests
-        */
-       public function testSetGetWithoutDB(int $uid, $data)
-       {
-               $this->configModel->shouldReceive('isConnected')
-                                 ->andReturn(false)
-                                 ->times(3);
-
-               parent::testSetGetWithoutDB($uid, $data);
-       }
-
-       /**
-        * @dataProvider dataTests
-        */
-       public function testSetGetWithDB(int $uid, $data)
-       {
-               $this->configModel->shouldReceive('isConnected')
-                                 ->andReturn(true)
-                                 ->twice();
-
-               $this->configModel->shouldReceive('load')
-                                 ->with($uid)
-                                 ->andReturn(['config' => []])
-                                 ->once();
-
-               parent::testSetGetWithDB($uid, $data);
-       }
-
-       /**
-        * @dataProvider dataTests
-        */
-       public function testGetWithRefresh(int $uid, $data)
-       {
-               $this->configModel->shouldReceive('isConnected')
-                                 ->andReturn(true)
-                                 ->times(2);
-
-               // constructor loading
-               $this->configModel->shouldReceive('load')
-                                 ->with($uid)
-                                 ->andReturn(['config' => []])
-                                 ->once();
-
-               // mocking one get
-               $this->configModel->shouldReceive('get')
-                                 ->with($uid, 'test', 'it')
-                                 ->andReturn($data)
-                                 ->once();
-
-               parent::testGetWithRefresh($uid, $data);
-       }
-
-       /**
-        * @dataProvider dataTests
-        */
-       public function testDeleteWithoutDB(int $uid, $data)
-       {
-               $this->configModel->shouldReceive('isConnected')
-                                 ->andReturn(false)
-                                 ->times(4);
-
-               parent::testDeleteWithoutDB($uid, $data);
-       }
-
-       public function testDeleteWithDB()
-       {
-               $this->configModel->shouldReceive('isConnected')
-                                 ->andReturn(true)
-                                 ->times(5);
-
-               // constructor loading
-               $this->configModel->shouldReceive('load')
-                                 ->with(42)
-                                 ->andReturn(['config' => []])
-                                 ->once();
-
-               parent::testDeleteWithDB();
-       }
-}
index ab4f98c63e75b793e5de9039d8e764a31345439a..aec4d0fd618ed8e4a9882934b094620499ff070a 100644 (file)
@@ -24,7 +24,7 @@ class SemaphoreLockTest extends LockTest
                $configMock = \Mockery::mock(JitConfig::class);
                $configMock
                        ->shouldReceive('get')
-                       ->with('system', 'temppath', NULL, false)
+                       ->with('system', 'temppath')
                        ->andReturn('/tmp/');
                $dice->shouldReceive('create')->with(IConfig::class)->andReturn($configMock);
 
diff --git a/tests/src/Core/PConfig/CacheTest.php b/tests/src/Core/PConfig/CacheTest.php
new file mode 100644 (file)
index 0000000..62f6d22
--- /dev/null
@@ -0,0 +1,275 @@
+<?php
+
+namespace Friendica\Test\src\Core\PConfig;
+
+use Friendica\Core\PConfig\Cache;
+use Friendica\Test\MockedTest;
+
+class CacheTest 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, Cache $configCache, $uid)
+       {
+               foreach ($data as $cat => $values) {
+                       foreach ($values as $key => $value) {
+                               $this->assertEquals($data[$cat][$key], $configCache->get($uid, $cat, $key));
+                       }
+               }
+       }
+
+       /**
+        * Test the setP() and getP() methods
+        *
+        * @dataProvider dataTests
+        */
+       public function testSetGet($data)
+       {
+               $configCache = new Cache();
+               $uid         = 345;
+
+               foreach ($data as $cat => $values) {
+                       foreach ($values as $key => $value) {
+                               $configCache->set($uid, $cat, $key, $value);
+                       }
+               }
+
+               $this->assertConfigValues($data, $configCache, $uid);
+       }
+
+
+       /**
+        * Test the getP() method with a category
+        */
+       public function testGetCat()
+       {
+               $configCache = new Cache();
+               $uid         = 345;
+
+               $configCache->load($uid, [
+                       'system' => [
+                               'key1' => 'value1',
+                               'key2' => 'value2',
+                       ],
+                       'config' => [
+                               'key3' => 'value3',
+                       ],
+               ]);
+
+               $this->assertEquals([
+                       'key1' => 'value1',
+                       'key2' => 'value2',
+               ], $configCache->get($uid, 'system'));
+
+               // test explicit cat with null as key
+               $this->assertEquals([
+                       'key1' => 'value1',
+                       'key2' => 'value2',
+               ], $configCache->get($uid, 'system', null));
+       }
+
+       /**
+        * Test the deleteP() method
+        *
+        * @dataProvider dataTests
+        */
+       public function testDelete($data)
+       {
+               $configCache = new Cache();
+               $uid         = 345;
+
+               foreach ($data as $cat => $values) {
+                       foreach ($values as $key => $value) {
+                               $configCache->set($uid, $cat, $key, $value);
+                       }
+               }
+
+               foreach ($data as $cat => $values) {
+                       foreach ($values as $key => $value) {
+                               $configCache->delete($uid, $cat, $key);
+                       }
+               }
+
+               $this->assertEmpty($configCache->getAll());
+       }
+
+       /**
+        * Test the keyDiff() method with result
+        *
+        * @dataProvider dataTests
+        */
+       public function testKeyDiffWithResult($data)
+       {
+               $configCache = new Cache();
+
+               $diffConfig = [
+                       'fakeCat' => [
+                               'fakeKey' => 'value',
+                       ]
+               ];
+
+               $this->assertEquals($diffConfig, $configCache->keyDiff($diffConfig));
+       }
+
+       /**
+        * Test the keyDiff() method without result
+        *
+        * @dataProvider dataTests
+        */
+       public function testKeyDiffWithoutResult($data)
+       {
+               $configCache = new Cache();
+
+               $configCache->load(1, $data);
+
+               $diffConfig = $configCache->getAll();
+
+               $this->assertEmpty($configCache->keyDiff($diffConfig));
+       }
+
+       /**
+        * Test the default hiding of passwords inside the cache
+        */
+       public function testPasswordHide()
+       {
+               $configCache = new Cache();
+
+               $configCache->load(1, [
+                       'database' => [
+                               'password' => 'supersecure',
+                               'username' => 'notsecured',
+                       ]
+               ]);
+
+               $this->assertEquals('supersecure', $configCache->get(1, 'database', 'password'));
+               $this->assertNotEquals('supersecure', print_r($configCache->get(1, 'database', 'password'), true));
+               $this->assertEquals('notsecured', print_r($configCache->get(1, 'database', 'username'), true));
+       }
+
+       /**
+        * Test disabling the hiding of passwords inside the cache
+        */
+       public function testPasswordShow()
+       {
+               $configCache = new Cache(false);
+
+               $configCache->load(1, [
+                       'database' => [
+                               'password' => 'supersecure',
+                               'username' => 'notsecured',
+                       ]
+               ]);
+
+               $this->assertEquals('supersecure', $configCache->get(1, 'database', 'password'));
+               $this->assertEquals('supersecure', print_r($configCache->get(1, 'database', 'password'), true));
+               $this->assertEquals('notsecured', print_r($configCache->get(1, 'database', 'username'), true));
+       }
+
+       /**
+        * Test a empty password
+        */
+       public function testEmptyPassword()
+       {
+               $configCache = new Cache();
+
+               $configCache->load(1, [
+                       'database' => [
+                               'password' => '',
+                               'username' => '',
+                       ]
+               ]);
+
+               $this->assertEmpty($configCache->get(1, 'database', 'password'));
+               $this->assertEmpty($configCache->get(1, 'database', 'username'));
+       }
+
+       public function testWrongTypePassword()
+       {
+               $configCache = new Cache();
+
+               $configCache->load(1, [
+                       'database' => [
+                               'password' => new \stdClass(),
+                               'username' => '',
+                       ]
+               ]);
+
+               $this->assertNotEmpty($configCache->get(1, 'database', 'password'));
+               $this->assertEmpty($configCache->get(1, 'database', 'username'));
+
+               $configCache = new Cache();
+
+               $configCache->load(1, [
+                       'database' => [
+                               'password' => 23,
+                               'username' => '',
+                       ],
+               ]);
+
+               $this->assertEquals(23, $configCache->get(1, 'database', 'password'));
+               $this->assertEmpty($configCache->get(1, 'database', 'username'));
+       }
+
+       /**
+        * Test two different UID configs and make sure that there is no overlapping possible
+        */
+       public function testTwoUid()
+       {
+               $configCache = new Cache();
+
+               $configCache->load(1, [
+                       'cat1' => [
+                               'key1' => 'value1',
+                       ],
+               ]);
+
+
+               $configCache->load(2, [
+                       'cat2' => [
+                               'key2' => 'value2',
+                       ],
+               ]);
+
+               $this->assertEquals('value1', $configCache->get(1, 'cat1', 'key1'));
+               $this->assertEquals('value2', $configCache->get(2, 'cat2', 'key2'));
+
+               $this->assertNull($configCache->get(1, 'cat2', 'key2'));
+               $this->assertNull($configCache->get(2, 'cat1', 'key1'));
+       }
+
+       /**
+        * Test when using an invalid UID
+        * @todo check it the clean way before using the config class
+        */
+       public function testInvalidUid()
+       {
+               // bad UID!
+               $uid = null;
+
+               $configCache = new Cache();
+
+               $this->assertNull($configCache->get($uid, 'cat1', 'cat2'));
+
+               $this->assertFalse($configCache->set($uid, 'cat1', 'key1', 'doesn\'t matter!'));
+               $this->assertFalse($configCache->delete($uid, 'cat1', 'key1'));
+       }
+}
diff --git a/tests/src/Core/PConfig/JitPConfigTest.php b/tests/src/Core/PConfig/JitPConfigTest.php
new file mode 100644 (file)
index 0000000..b193171
--- /dev/null
@@ -0,0 +1,146 @@
+<?php
+
+namespace Friendica\Test\src\Core\PConfig;
+
+use Friendica\Core\PConfig\JitPConfig;
+use Friendica\Test\src\Core\PConfig\PConfigTest;
+
+class JitPConfigTest extends PConfigTest
+{
+       public function getInstance()
+       {
+               return new JitPConfig($this->configCache, $this->configModel);
+       }
+
+       /**
+        * @dataProvider dataConfigLoad
+        */
+       public function testLoad(int $uid, array $data, array $possibleCats, array $load)
+       {
+               $this->configModel->shouldReceive('isConnected')
+                                 ->andReturn(true)
+                                 ->times(count($load));
+
+               foreach ($load as $loadCat) {
+                       $this->configModel->shouldReceive('load')
+                                         ->with($uid, $loadCat)
+                                         ->andReturn([$loadCat => $data[$loadCat]])
+                                         ->once();
+               }
+
+               parent::testLoad($uid, $data, $possibleCats, $load);
+       }
+
+       /**
+        * @dataProvider dataDoubleLoad
+        */
+       public function testCacheLoadDouble(int $uid, array $data1, array $data2, array $expect)
+       {
+               $this->configModel->shouldReceive('isConnected')
+                                 ->andReturn(true)
+                                 ->times(count($data1) + count($data2));
+
+               foreach ($data1 as $cat => $data) {
+                       $this->configModel->shouldReceive('load')
+                                         ->with($uid, $cat)
+                                         ->andReturn([$cat => $data])
+                                         ->once();
+               }
+
+
+               foreach ($data2 as $cat => $data) {
+                       $this->configModel->shouldReceive('load')
+                                         ->with($uid, $cat)
+                                         ->andReturn([$cat => $data])
+                                         ->once();
+               }
+
+               parent::testCacheLoadDouble($uid, $data1, $data2, $expect);
+
+               // Assert the expected categories
+               foreach ($data2 as $cat => $data) {
+                       $this->assertConfig($uid, $cat, $expect[$cat]);
+               }
+       }
+
+       /**
+        * @dataProvider dataTests
+        */
+       public function testSetGetWithoutDB(int $uid, $data)
+       {
+               $this->configModel->shouldReceive('isConnected')
+                                 ->andReturn(false)
+                                 ->times(2);
+
+               parent::testSetGetWithoutDB($uid, $data);
+       }
+
+       /**
+        * @dataProvider dataTests
+        */
+       public function testSetGetWithDB(int $uid, $data)
+       {
+               $this->configModel->shouldReceive('isConnected')
+                                 ->andReturn(true)
+                                 ->times(2);
+
+               parent::testSetGetWithDB($uid, $data);
+       }
+
+       /**
+        * @dataProvider dataTests
+        */
+       public function testGetWithRefresh(int $uid, $data)
+       {
+               $this->configModel->shouldReceive('isConnected')
+                                 ->andReturn(true)
+                                 ->times(3);
+
+               // mocking one get without result
+               $this->configModel->shouldReceive('get')
+                                 ->with($uid, 'test', 'it')
+                                 ->andReturn(null)
+                                 ->once();
+
+               // mocking the data get
+               $this->configModel->shouldReceive('get')
+                                 ->with($uid, 'test', 'it')
+                                 ->andReturn($data)
+                                 ->once();
+
+               // mocking second get
+               $this->configModel->shouldReceive('get')
+                                 ->with($uid, 'test', 'not')
+                                 ->andReturn(null)
+                                 ->once();
+
+               parent::testGetWithRefresh($uid, $data);
+       }
+
+       /**
+        * @dataProvider dataTests
+        */
+       public function testDeleteWithoutDB(int $uid, $data)
+       {
+               $this->configModel->shouldReceive('isConnected')
+                                 ->andReturn(false)
+                                 ->times(3);
+
+               parent::testDeleteWithoutDB($uid, $data);
+       }
+
+       public function testDeleteWithDB()
+       {
+               $this->configModel->shouldReceive('isConnected')
+                                 ->andReturn(true)
+                                 ->times(5);
+
+               // mocking one get without result
+               $this->configModel->shouldReceive('get')
+                                 ->with(42, 'test', 'it')
+                                 ->andReturn(null)
+                                 ->once();
+
+               parent::testDeleteWithDB();
+       }
+}
diff --git a/tests/src/Core/PConfig/PConfigTest.php b/tests/src/Core/PConfig/PConfigTest.php
new file mode 100644 (file)
index 0000000..e6f0326
--- /dev/null
@@ -0,0 +1,475 @@
+<?php
+
+namespace Friendica\Test\src\Core\PConfig;
+
+use Friendica\Core\PConfig\Cache;
+use Friendica\Core\BasePConfig;
+use Friendica\Model\Config\PConfig as PConfigModel;
+use Friendica\Test\MockedTest;
+use Mockery;
+use Mockery\MockInterface;
+
+abstract class PConfigTest extends MockedTest
+{
+       /** @var PConfigModel|MockInterface */
+       protected $configModel;
+
+       /** @var Cache */
+       protected $configCache;
+
+       /** @var BasePConfig */
+       protected $testedConfig;
+
+       /**
+        * Assert a config tree
+        *
+        * @param int    $uid  The uid to assert
+        * @param string $cat  The category to assert
+        * @param array  $data The result data array
+        */
+       protected function assertConfig(int $uid, string $cat, array $data)
+       {
+               $result = $this->testedConfig->getCache()->getAll();
+
+               $this->assertNotEmpty($result);
+               $this->assertArrayHasKey($uid, $result);
+               $this->assertArrayHasKey($cat, $result[$uid]);
+               $this->assertArraySubset($data, $result[$uid][$cat]);
+       }
+
+
+       protected function setUp()
+       {
+               parent::setUp();
+
+               // Create the config model
+               $this->configModel = Mockery::mock(PConfigModel::class);
+               $this->configCache = new Cache();
+       }
+
+       /**
+        * @return BasePConfig
+        */
+       public abstract function getInstance();
+
+       public function dataTests()
+       {
+               return [
+                       'string'       => ['uid' => 1, 'data' => 'it'],
+                       'boolTrue'     => ['uid' => 2, 'data' => true],
+                       'boolFalse'    => ['uid' => 3, 'data' => false],
+                       'integer'      => ['uid' => 4, 'data' => 235],
+                       'decimal'      => ['uid' => 5, 'data' => 2.456],
+                       'array'        => ['uid' => 6, 'data' => ['1', 2, '3', true, false]],
+                       'boolIntTrue'  => ['uid' => 7, 'data' => 1],
+                       'boolIntFalse' => ['uid' => 8, 'data' => 0],
+               ];
+       }
+
+       public function dataConfigLoad()
+       {
+               $data = [
+                       'system' => [
+                               'key1' => 'value1',
+                               'key2' => 'value2',
+                               'key3' => 'value3',
+                       ],
+                       'config' => [
+                               'key1' => 'value1a',
+                               'key4' => 'value4',
+                       ],
+                       'other'  => [
+                               'key5' => 'value5',
+                               'key6' => 'value6',
+                       ],
+               ];
+
+               return [
+                       'system' => [
+                               'uid' => 1,
+                               'data'         => $data,
+                               'possibleCats' => [
+                                       'system',
+                                       'config',
+                                       'other'
+                               ],
+                               'load'         => [
+                                       'system',
+                               ],
+                       ],
+                       'other'  => [
+                               'uid' => 2,
+                               'data'         => $data,
+                               'possibleCats' => [
+                                       'system',
+                                       'config',
+                                       'other'
+                               ],
+                               'load'         => [
+                                       'other',
+                               ],
+                       ],
+                       'config' => [
+                               'uid' => 3,
+                               'data'         => $data,
+                               'possibleCats' => [
+                                       'system',
+                                       'config',
+                                       'other'
+                               ],
+                               'load'         => [
+                                       'config',
+                               ],
+                       ],
+                       'all'    => [
+                               'uid' => 4,
+                               'data'         => $data,
+                               'possibleCats' => [
+                                       'system',
+                                       'config',
+                                       'other'
+                               ],
+                               'load'         => [
+                                       'system',
+                                       'config',
+                                       'other'
+                               ],
+                       ],
+               ];
+       }
+
+       /**
+        * Test the configuration initialization
+        * @dataProvider dataConfigLoad
+        */
+       public function testSetUp(int $uid, array $data)
+       {
+               $this->testedConfig = $this->getInstance();
+               $this->assertInstanceOf(Cache::class, $this->testedConfig->getCache());
+
+               $this->assertEmpty($this->testedConfig->getCache()->getAll());
+       }
+
+       /**
+        * Test the configuration load() method
+        */
+       public function testLoad(int $uid, array $data, array $possibleCats, array $load)
+       {
+               $this->testedConfig = $this->getInstance();
+               $this->assertInstanceOf(Cache::class, $this->testedConfig->getCache());
+
+               foreach ($load as $loadedCats) {
+                       $this->testedConfig->load($uid, $loadedCats);
+               }
+
+               // Assert at least loaded cats are loaded
+               foreach ($load as $loadedCats) {
+                       $this->assertConfig($uid, $loadedCats, $data[$loadedCats]);
+               }
+       }
+
+       public function dataDoubleLoad()
+       {
+               return [
+                       'config' => [
+                               'uid' => 1,
+                               'data1'  => [
+                                       'config' => [
+                                               'key1' => 'value1',
+                                               'key2' => 'value2',
+                                       ],
+                               ],
+                               'data2'  => [
+                                       'config' => [
+                                               'key1' => 'overwritten!',
+                                               'key3' => 'value3',
+                                       ],
+                               ],
+                               'expect' => [
+                                       'config' => [
+                                               // load should overwrite values everytime!
+                                               'key1' => 'overwritten!',
+                                               'key2' => 'value2',
+                                               'key3' => 'value3',
+                                       ],
+                               ],
+                       ],
+                       'other'  => [
+                               'uid' => 1,
+                               'data1'  => [
+                                       'config' => [
+                                               'key12' => 'data4',
+                                               'key45' => 7,
+                                       ],
+                                       'other'  => [
+                                               'key1' => 'value1',
+                                               'key2' => 'value2',
+                                       ],
+                               ],
+                               'data2'  => [
+                                       'other'  => [
+                                               'key1' => 'overwritten!',
+                                               'key3' => 'value3',
+                                       ],
+                                       'config' => [
+                                               'key45' => 45,
+                                               'key52' => true,
+                                       ]
+                               ],
+                               'expect' => [
+                                       'other'  => [
+                                               // load should overwrite values everytime!
+                                               'key1' => 'overwritten!',
+                                               'key2' => 'value2',
+                                               'key3' => 'value3',
+                                       ],
+                                       'config' => [
+                                               'key12' => 'data4',
+                                               'key45' => 45,
+                                               'key52' => true,
+                                       ],
+                               ],
+                       ],
+               ];
+       }
+
+       /**
+        * Test the configuration load() method with overwrite
+        */
+       public function testCacheLoadDouble(int $uid, array $data1, array $data2, array $expect)
+       {
+               $this->testedConfig = $this->getInstance();
+               $this->assertInstanceOf(Cache::class, $this->testedConfig->getCache());
+
+               foreach ($data1 as $cat => $data) {
+                       $this->testedConfig->load($uid, $cat);
+               }
+
+               // Assert at least loaded cats are loaded
+               foreach ($data1 as $cat => $data) {
+                       $this->assertConfig($uid, $cat, $data);
+               }
+
+               foreach ($data2 as $cat => $data) {
+                       $this->testedConfig->load($uid, $cat);
+               }
+       }
+
+       /**
+        * Test the configuration get() and set() methods without adapter
+        *
+        * @dataProvider dataTests
+        */
+       public function testSetGetWithoutDB(int $uid, $data)
+       {
+               $this->testedConfig = $this->getInstance();
+               $this->assertInstanceOf(Cache::class, $this->testedConfig->getCache());
+
+               $this->assertTrue($this->testedConfig->set($uid, 'test', 'it', $data));
+
+               $this->assertEquals($data, $this->testedConfig->get($uid, 'test', 'it'));
+               $this->assertEquals($data, $this->testedConfig->getCache()->get($uid, 'test', 'it'));
+       }
+
+       /**
+        * Test the configuration get() and set() methods with a model/db
+        *
+        * @dataProvider dataTests
+        */
+       public function testSetGetWithDB(int $uid, $data)
+       {
+               $this->configModel->shouldReceive('set')
+                                 ->with($uid, 'test', 'it', $data)
+                                 ->andReturn(true)
+                                 ->once();
+
+               $this->testedConfig = $this->getInstance();
+               $this->assertInstanceOf(Cache::class, $this->testedConfig->getCache());
+
+               $this->assertTrue($this->testedConfig->set($uid, 'test', 'it', $data));
+
+               $this->assertEquals($data, $this->testedConfig->get($uid, 'test', 'it'));
+               $this->assertEquals($data, $this->testedConfig->getCache()->get($uid, 'test', 'it'));
+       }
+
+       /**
+        * Test the configuration get() method with wrong value and no db
+        */
+       public function testGetWrongWithoutDB()
+       {
+               $this->testedConfig = $this->getInstance();
+               $this->assertInstanceOf(Cache::class, $this->testedConfig->getCache());
+
+               // without refresh
+               $this->assertNull($this->testedConfig->get(0, 'test', 'it'));
+
+               /// beware that the cache returns '!<unset>!' and not null for a non existing value
+               $this->assertNull($this->testedConfig->getCache()->get(0, 'test', 'it'));
+
+               // with default value
+               $this->assertEquals('default', $this->testedConfig->get(0, 'test', 'it', 'default'));
+
+               // with default value and refresh
+               $this->assertEquals('default', $this->testedConfig->get(0, 'test', 'it', 'default', true));
+       }
+
+       /**
+        * Test the configuration get() method with refresh
+        *
+        * @dataProvider dataTests
+        */
+       public function testGetWithRefresh(int $uid, $data)
+       {
+               $this->configCache->load($uid, ['test' => ['it' => 'now']]);
+
+               $this->testedConfig = $this->getInstance();
+               $this->assertInstanceOf(Cache::class, $this->testedConfig->getCache());
+
+               // without refresh
+               $this->assertEquals('now', $this->testedConfig->get($uid, 'test', 'it'));
+               $this->assertEquals('now', $this->testedConfig->getCache()->get($uid, 'test', 'it'));
+
+               // with refresh
+               $this->assertEquals($data, $this->testedConfig->get($uid, 'test', 'it', null, true));
+               $this->assertEquals($data, $this->testedConfig->getCache()->get($uid, 'test', 'it'));
+
+               // without refresh and wrong value and default
+               $this->assertEquals('default', $this->testedConfig->get($uid, 'test', 'not', 'default'));
+               $this->assertNull($this->testedConfig->getCache()->get($uid, 'test', 'not'));
+       }
+
+       /**
+        * Test the configuration delete() method without a model/db
+        *
+        * @dataProvider dataTests
+        */
+       public function testDeleteWithoutDB(int $uid, $data)
+       {
+               $this->configCache->load($uid, ['test' => ['it' => $data]]);
+
+               $this->testedConfig = $this->getInstance();
+               $this->assertInstanceOf(Cache::class, $this->testedConfig->getCache());
+
+               $this->assertEquals($data, $this->testedConfig->get($uid, 'test', 'it'));
+               $this->assertEquals($data, $this->testedConfig->getCache()->get($uid, 'test', 'it'));
+
+               $this->assertTrue($this->testedConfig->delete($uid, 'test', 'it'));
+               $this->assertNull($this->testedConfig->get($uid, 'test', 'it'));
+               $this->assertNull($this->testedConfig->getCache()->get($uid, 'test', 'it'));
+
+               $this->assertEmpty($this->testedConfig->getCache()->getAll());
+       }
+
+       /**
+        * Test the configuration delete() method with a model/db
+        */
+       public function testDeleteWithDB()
+       {
+               $uid = 42;
+
+               $this->configCache->load($uid, ['test' => ['it' => 'now', 'quarter' => 'true']]);
+
+               $this->configModel->shouldReceive('delete')
+                                 ->with($uid, 'test', 'it')
+                                 ->andReturn(false)
+                                 ->once();
+               $this->configModel->shouldReceive('delete')
+                                 ->with($uid, 'test', 'second')
+                                 ->andReturn(true)
+                                 ->once();
+               $this->configModel->shouldReceive('delete')
+                                 ->with($uid, 'test', 'third')
+                                 ->andReturn(false)
+                                 ->once();
+               $this->configModel->shouldReceive('delete')
+                                 ->with($uid, 'test', 'quarter')
+                                 ->andReturn(true)
+                                 ->once();
+
+               $this->testedConfig = $this->getInstance();
+               $this->assertInstanceOf(Cache::class, $this->testedConfig->getCache());
+
+               // directly set the value to the cache
+               $this->testedConfig->getCache()->set($uid, 'test', 'it', 'now');
+
+               $this->assertEquals('now', $this->testedConfig->get($uid, 'test', 'it'));
+               $this->assertEquals('now', $this->testedConfig->getCache()->get($uid, 'test', 'it'));
+
+               // delete from cache only
+               $this->assertTrue($this->testedConfig->delete($uid, 'test', 'it'));
+               // delete from db only
+               $this->assertTrue($this->testedConfig->delete($uid, 'test', 'second'));
+               // no delete
+               $this->assertFalse($this->testedConfig->delete($uid, 'test', 'third'));
+               // delete both
+               $this->assertTrue($this->testedConfig->delete($uid, 'test', 'quarter'));
+
+               $this->assertEmpty($this->testedConfig->getCache()->getAll());
+       }
+
+       public function dataMultiUid()
+       {
+               return [
+                       'normal' => [
+                               'data1' => [
+                                       'uid'  => 1,
+                                       'data' => [
+                                               'cat1' => [
+                                                       'key1' => 'value1',
+                                               ],
+                                               'cat2' => [
+                                                       'key2' => 'value2',
+                                               ]
+                                       ],
+                               ],
+                               'data2' => [
+                                       'uid' => 2,
+                                       'data' => [
+                                               'cat1' => [
+                                                       'key1' => 'value1a',
+                                               ],
+                                               'cat2' => [
+                                                       'key2' => 'value2',
+                                               ],
+                                       ],
+                               ],
+                       ],
+               ];
+       }
+
+       /**
+        * Test if multiple uids for caching are usable without errors
+        * @dataProvider dataMultiUid
+        */
+       public function testMultipleUidsWithCache(array $data1, array $data2)
+       {
+               $this->configCache->load($data1['uid'], $data1['data']);
+               $this->configCache->load($data2['uid'], $data2['data']);
+
+               $this->testedConfig = $this->getInstance();
+               $this->assertInstanceOf(Cache::class, $this->testedConfig->getCache());
+
+               $this->assertConfig($data1['uid'], 'cat1', $data1['data']['cat1']);
+               $this->assertConfig($data1['uid'], 'cat2', $data1['data']['cat2']);
+               $this->assertConfig($data2['uid'], 'cat1', $data2['data']['cat1']);
+               $this->assertConfig($data2['uid'], 'cat2', $data2['data']['cat2']);
+       }
+
+       /**
+        * Test when using an invalid UID
+        * @todo check it the clean way before using the config class
+        */
+       public function testInvalidUid()
+       {
+               // bad UID!
+               $uid = 0;
+
+               $this->testedConfig = $this->getInstance();
+
+               $this->assertNull($this->testedConfig->get($uid, 'cat1', 'cat2'));
+               $this->assertEquals('fallback!', $this->testedConfig->get($uid, 'cat1', 'cat2', 'fallback!'));
+
+               $this->assertFalse($this->testedConfig->set($uid, 'cat1', 'key1', 'doesn\'t matter!'));
+               $this->assertFalse($this->testedConfig->delete($uid, 'cat1', 'key1'));
+       }
+}
diff --git a/tests/src/Core/PConfig/PreloadPConfigTest.php b/tests/src/Core/PConfig/PreloadPConfigTest.php
new file mode 100644 (file)
index 0000000..60d6293
--- /dev/null
@@ -0,0 +1,138 @@
+<?php
+
+namespace Friendica\Test\src\Core\PConfig;
+
+use Friendica\Core\PConfig\PreloadPConfig;
+use Friendica\Test\src\Core\PConfig\PConfigTest;
+
+class PreloadPConfigTest extends PConfigTest
+{
+       public function getInstance()
+       {
+               return new PreloadPConfig($this->configCache, $this->configModel);
+       }
+
+       /**
+        * @dataProvider dataConfigLoad
+        */
+       public function testLoad(int $uid, array $data, array $possibleCats, array $load)
+       {
+               $this->configModel->shouldReceive('isConnected')
+                                 ->andReturn(true)
+                                 ->once();
+
+               $this->configModel->shouldReceive('load')
+                                 ->with($uid)
+                                 ->andReturn($data)
+                                 ->once();
+
+               parent::testLoad($uid, $data, $possibleCats, $load);
+
+               // Assert that every category is loaded everytime
+               foreach ($data as $cat => $values) {
+                       $this->assertConfig($uid, $cat, $values);
+               }
+       }
+
+       /**
+        * @dataProvider dataDoubleLoad
+        */
+       public function testCacheLoadDouble(int $uid, array $data1, array $data2, array $expect)
+       {
+               $this->configModel->shouldReceive('isConnected')
+                                 ->andReturn(true)
+                                 ->once();
+
+               $this->configModel->shouldReceive('load')
+                                 ->with($uid)
+                                 ->andReturn($data1)
+                                 ->once();
+
+               parent::testCacheLoadDouble($uid, $data1, $data2, $expect);
+
+               // Assert that every category is loaded everytime and is NOT overwritten
+               foreach ($data1 as $cat => $values) {
+                       $this->assertConfig($uid, $cat, $values);
+               }
+       }
+
+       /**
+        * @dataProvider dataTests
+        */
+       public function testSetGetWithoutDB(int $uid, $data)
+       {
+               $this->configModel->shouldReceive('isConnected')
+                                 ->andReturn(false)
+                                 ->times(3);
+
+               parent::testSetGetWithoutDB($uid, $data);
+       }
+
+       /**
+        * @dataProvider dataTests
+        */
+       public function testSetGetWithDB(int $uid, $data)
+       {
+               $this->configModel->shouldReceive('isConnected')
+                                 ->andReturn(true)
+                                 ->twice();
+
+               $this->configModel->shouldReceive('load')
+                                 ->with($uid)
+                                 ->andReturn(['config' => []])
+                                 ->once();
+
+               parent::testSetGetWithDB($uid, $data);
+       }
+
+       /**
+        * @dataProvider dataTests
+        */
+       public function testGetWithRefresh(int $uid, $data)
+       {
+               $this->configModel->shouldReceive('isConnected')
+                                 ->andReturn(true)
+                                 ->times(2);
+
+               // constructor loading
+               $this->configModel->shouldReceive('load')
+                                 ->with($uid)
+                                 ->andReturn(['config' => []])
+                                 ->once();
+
+               // mocking one get
+               $this->configModel->shouldReceive('get')
+                                 ->with($uid, 'test', 'it')
+                                 ->andReturn($data)
+                                 ->once();
+
+               parent::testGetWithRefresh($uid, $data);
+       }
+
+       /**
+        * @dataProvider dataTests
+        */
+       public function testDeleteWithoutDB(int $uid, $data)
+       {
+               $this->configModel->shouldReceive('isConnected')
+                                 ->andReturn(false)
+                                 ->times(4);
+
+               parent::testDeleteWithoutDB($uid, $data);
+       }
+
+       public function testDeleteWithDB()
+       {
+               $this->configModel->shouldReceive('isConnected')
+                                 ->andReturn(true)
+                                 ->times(5);
+
+               // constructor loading
+               $this->configModel->shouldReceive('load')
+                                 ->with(42)
+                                 ->andReturn(['config' => []])
+                                 ->once();
+
+               parent::testDeleteWithDB();
+       }
+}