mirror of
https://github.com/friendica/friendica
synced 2025-04-27 13:10:10 +00:00
adapt tests
This commit is contained in:
parent
d272e8c3c7
commit
326566638f
16 changed files with 254 additions and 712 deletions
|
@ -21,7 +21,7 @@
|
|||
|
||||
namespace Friendica\Test\src\Core\Config\Cache;
|
||||
|
||||
use Friendica\Core\Config\Cache;
|
||||
use Friendica\Core\Config\ValueObject\Cache;
|
||||
use Friendica\Test\MockedTest;
|
||||
use ParagonIE\HiddenString\HiddenString;
|
||||
use stdClass;
|
||||
|
@ -49,7 +49,7 @@ class CacheTest extends MockedTest
|
|||
];
|
||||
}
|
||||
|
||||
private function assertConfigValues($data, \Friendica\Core\Config\ValueObject\Cache $configCache)
|
||||
private function assertConfigValues($data, Cache $configCache)
|
||||
{
|
||||
foreach ($data as $cat => $values) {
|
||||
foreach ($values as $key => $value) {
|
||||
|
@ -64,7 +64,7 @@ class CacheTest extends MockedTest
|
|||
*/
|
||||
public function testLoadConfigArray($data)
|
||||
{
|
||||
$configCache = new \Friendica\Core\Config\ValueObject\Cache();
|
||||
$configCache = new Cache();
|
||||
$configCache->load($data);
|
||||
|
||||
self::assertConfigValues($data, $configCache);
|
||||
|
@ -83,27 +83,27 @@ class CacheTest extends MockedTest
|
|||
]
|
||||
];
|
||||
|
||||
$configCache = new \Friendica\Core\Config\ValueObject\Cache();
|
||||
$configCache->load($data, \Friendica\Core\Config\ValueObject\Cache::SOURCE_DB);
|
||||
$configCache = new Cache();
|
||||
$configCache->load($data, Cache::SOURCE_DATA);
|
||||
// doesn't override - Low Priority due Config file
|
||||
$configCache->load($override, \Friendica\Core\Config\ValueObject\Cache::SOURCE_FILE);
|
||||
$configCache->load($override, Cache::SOURCE_FILE);
|
||||
|
||||
self::assertConfigValues($data, $configCache);
|
||||
|
||||
// override the value - High Prio due Server Env
|
||||
$configCache->load($override, \Friendica\Core\Config\ValueObject\Cache::SOURCE_ENV);
|
||||
$configCache->load($override, Cache::SOURCE_ENV);
|
||||
|
||||
self::assertEquals($override['system']['test'], $configCache->get('system', 'test'));
|
||||
self::assertEquals($override['system']['boolTrue'], $configCache->get('system', 'boolTrue'));
|
||||
|
||||
// Don't overwrite server ENV variables - even in load mode
|
||||
$configCache->load($data, \Friendica\Core\Config\ValueObject\Cache::SOURCE_DB);
|
||||
$configCache->load($data, Cache::SOURCE_DATA);
|
||||
|
||||
self::assertEquals($override['system']['test'], $configCache->get('system', 'test'));
|
||||
self::assertEquals($override['system']['boolTrue'], $configCache->get('system', 'boolTrue'));
|
||||
|
||||
// Overwrite ENV variables with ENV variables
|
||||
$configCache->load($data, \Friendica\Core\Config\ValueObject\Cache::SOURCE_ENV);
|
||||
$configCache->load($data, Cache::SOURCE_ENV);
|
||||
|
||||
self::assertConfigValues($data, $configCache);
|
||||
self::assertNotEquals($override['system']['test'], $configCache->get('system', 'test'));
|
||||
|
@ -115,7 +115,7 @@ class CacheTest extends MockedTest
|
|||
*/
|
||||
public function testLoadConfigArrayWrong()
|
||||
{
|
||||
$configCache = new \Friendica\Core\Config\ValueObject\Cache();
|
||||
$configCache = new Cache();
|
||||
|
||||
// empty dataset
|
||||
$configCache->load([]);
|
||||
|
@ -136,7 +136,7 @@ class CacheTest extends MockedTest
|
|||
*/
|
||||
public function testGetAll($data)
|
||||
{
|
||||
$configCache = new \Friendica\Core\Config\ValueObject\Cache();
|
||||
$configCache = new Cache();
|
||||
$configCache->load($data);
|
||||
|
||||
$all = $configCache->getAll();
|
||||
|
@ -151,7 +151,7 @@ class CacheTest extends MockedTest
|
|||
*/
|
||||
public function testSetGet($data)
|
||||
{
|
||||
$configCache = new \Friendica\Core\Config\ValueObject\Cache();
|
||||
$configCache = new Cache();
|
||||
|
||||
foreach ($data as $cat => $values) {
|
||||
foreach ($values as $key => $value) {
|
||||
|
@ -167,7 +167,7 @@ class CacheTest extends MockedTest
|
|||
*/
|
||||
public function testGetEmpty()
|
||||
{
|
||||
$configCache = new \Friendica\Core\Config\ValueObject\Cache();
|
||||
$configCache = new Cache();
|
||||
|
||||
self::assertNull($configCache->get('something', 'value'));
|
||||
}
|
||||
|
@ -177,7 +177,7 @@ class CacheTest extends MockedTest
|
|||
*/
|
||||
public function testGetCat()
|
||||
{
|
||||
$configCache = new \Friendica\Core\Config\ValueObject\Cache([
|
||||
$configCache = new Cache([
|
||||
'system' => [
|
||||
'key1' => 'value1',
|
||||
'key2' => 'value2',
|
||||
|
@ -205,7 +205,7 @@ class CacheTest extends MockedTest
|
|||
*/
|
||||
public function testDelete($data)
|
||||
{
|
||||
$configCache = new \Friendica\Core\Config\ValueObject\Cache($data);
|
||||
$configCache = new Cache($data);
|
||||
|
||||
foreach ($data as $cat => $values) {
|
||||
foreach ($values as $key => $value) {
|
||||
|
@ -222,7 +222,7 @@ class CacheTest extends MockedTest
|
|||
*/
|
||||
public function testKeyDiffWithResult($data)
|
||||
{
|
||||
$configCache = new \Friendica\Core\Config\ValueObject\Cache($data);
|
||||
$configCache = new Cache($data);
|
||||
|
||||
$diffConfig = [
|
||||
'fakeCat' => [
|
||||
|
@ -239,7 +239,7 @@ class CacheTest extends MockedTest
|
|||
*/
|
||||
public function testKeyDiffWithoutResult($data)
|
||||
{
|
||||
$configCache = new \Friendica\Core\Config\ValueObject\Cache($data);
|
||||
$configCache = new Cache($data);
|
||||
|
||||
$diffConfig = $configCache->getAll();
|
||||
|
||||
|
@ -251,7 +251,7 @@ class CacheTest extends MockedTest
|
|||
*/
|
||||
public function testPasswordHide()
|
||||
{
|
||||
$configCache = new \Friendica\Core\Config\ValueObject\Cache([
|
||||
$configCache = new Cache([
|
||||
'database' => [
|
||||
'password' => 'supersecure',
|
||||
'username' => 'notsecured',
|
||||
|
@ -268,7 +268,7 @@ class CacheTest extends MockedTest
|
|||
*/
|
||||
public function testPasswordShow()
|
||||
{
|
||||
$configCache = new \Friendica\Core\Config\ValueObject\Cache([
|
||||
$configCache = new Cache([
|
||||
'database' => [
|
||||
'password' => 'supersecure',
|
||||
'username' => 'notsecured',
|
||||
|
@ -285,7 +285,7 @@ class CacheTest extends MockedTest
|
|||
*/
|
||||
public function testEmptyPassword()
|
||||
{
|
||||
$configCache = new \Friendica\Core\Config\ValueObject\Cache([
|
||||
$configCache = new Cache([
|
||||
'database' => [
|
||||
'password' => '',
|
||||
'username' => '',
|
||||
|
@ -299,7 +299,7 @@ class CacheTest extends MockedTest
|
|||
|
||||
public function testWrongTypePassword()
|
||||
{
|
||||
$configCache = new \Friendica\Core\Config\ValueObject\Cache([
|
||||
$configCache = new Cache([
|
||||
'database' => [
|
||||
'password' => new stdClass(),
|
||||
'username' => '',
|
||||
|
@ -309,7 +309,7 @@ class CacheTest extends MockedTest
|
|||
self::assertNotEmpty($configCache->get('database', 'password'));
|
||||
self::assertEmpty($configCache->get('database', 'username'));
|
||||
|
||||
$configCache = new \Friendica\Core\Config\ValueObject\Cache([
|
||||
$configCache = new Cache([
|
||||
'database' => [
|
||||
'password' => 23,
|
||||
'username' => '',
|
||||
|
@ -327,19 +327,35 @@ class CacheTest extends MockedTest
|
|||
public function testSetOverrides($data)
|
||||
{
|
||||
|
||||
$configCache = new \Friendica\Core\Config\ValueObject\Cache();
|
||||
$configCache->load($data, \Friendica\Core\Config\ValueObject\Cache::SOURCE_DB);
|
||||
$configCache = new Cache();
|
||||
$configCache->load($data, Cache::SOURCE_DATA);
|
||||
|
||||
// test with wrong override
|
||||
self::assertFalse($configCache->set('system', 'test', '1234567', \Friendica\Core\Config\ValueObject\Cache::SOURCE_FILE));
|
||||
self::assertFalse($configCache->set('system', 'test', '1234567', Cache::SOURCE_FILE));
|
||||
self::assertEquals($data['system']['test'], $configCache->get('system', 'test'));
|
||||
|
||||
// test with override (equal)
|
||||
self::assertTrue($configCache->set('system', 'test', '8910', \Friendica\Core\Config\ValueObject\Cache::SOURCE_DB));
|
||||
self::assertTrue($configCache->set('system', 'test', '8910', Cache::SOURCE_DATA));
|
||||
self::assertEquals('8910', $configCache->get('system', 'test'));
|
||||
|
||||
// test with override (over)
|
||||
self::assertTrue($configCache->set('system', 'test', '111213', \Friendica\Core\Config\ValueObject\Cache::SOURCE_ENV));
|
||||
self::assertTrue($configCache->set('system', 'test', '111213', Cache::SOURCE_ENV));
|
||||
self::assertEquals('111213', $configCache->get('system', 'test'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataTests
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSetData($data)
|
||||
{
|
||||
$configCache = new Cache();
|
||||
$configCache->load($data, Cache::SOURCE_FILE);
|
||||
|
||||
$configCache->set('system', 'test_2','with_data', Cache::SOURCE_DATA);
|
||||
|
||||
$this->assertEquals(['system' => ['test_2' => 'with_data']], $configCache->getDataBySource(Cache::SOURCE_DATA));
|
||||
$this->assertEquals($data, $configCache->getDataBySource(Cache::SOURCE_FILE));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ use Friendica\Core\Config\Cache;
|
|||
use Friendica\Core\Config\Factory\Config;
|
||||
use Friendica\Test\MockedTest;
|
||||
use Friendica\Test\Util\VFSTrait;
|
||||
use Friendica\Core\Config\Util\ConfigFileLoader;
|
||||
use Friendica\Core\Config\Util\ConfigFileManager;
|
||||
use org\bovigo\vfs\vfsStream;
|
||||
|
||||
class ConfigFileLoaderTest extends MockedTest
|
||||
|
@ -46,7 +46,7 @@ class ConfigFileLoaderTest extends MockedTest
|
|||
{
|
||||
$this->delConfigFile('local.config.php');
|
||||
|
||||
$configFileLoader = new ConfigFileLoader(
|
||||
$configFileLoader = new ConfigFileManager(
|
||||
$this->root->url(),
|
||||
$this->root->url() . DIRECTORY_SEPARATOR . Config::CONFIG_DIR,
|
||||
$this->root->url() . DIRECTORY_SEPARATOR . Config::STATIC_DIR
|
||||
|
@ -72,7 +72,7 @@ class ConfigFileLoaderTest extends MockedTest
|
|||
->at($this->root->getChild('config'))
|
||||
->setContent('<?php return true;');
|
||||
|
||||
$configFileLoader = new ConfigFileLoader(
|
||||
$configFileLoader = new ConfigFileManager(
|
||||
$this->root->url(),
|
||||
$this->root->url() . DIRECTORY_SEPARATOR . Config::CONFIG_DIR,
|
||||
$this->root->url() . DIRECTORY_SEPARATOR . Config::STATIC_DIR
|
||||
|
@ -101,7 +101,7 @@ class ConfigFileLoaderTest extends MockedTest
|
|||
->at($this->root->getChild('config'))
|
||||
->setContent(file_get_contents($file));
|
||||
|
||||
$configFileLoader = new ConfigFileLoader(
|
||||
$configFileLoader = new ConfigFileManager(
|
||||
$this->root->url(),
|
||||
$this->root->url() . DIRECTORY_SEPARATOR . Config::CONFIG_DIR,
|
||||
$this->root->url() . DIRECTORY_SEPARATOR . Config::STATIC_DIR
|
||||
|
@ -138,7 +138,7 @@ class ConfigFileLoaderTest extends MockedTest
|
|||
->at($this->root->getChild('config'))
|
||||
->setContent(file_get_contents($file));
|
||||
|
||||
$configFileLoader = new ConfigFileLoader(
|
||||
$configFileLoader = new ConfigFileManager(
|
||||
$this->root->url(),
|
||||
$this->root->url() . DIRECTORY_SEPARATOR . Config::CONFIG_DIR,
|
||||
$this->root->url() . DIRECTORY_SEPARATOR . Config::STATIC_DIR
|
||||
|
@ -174,7 +174,7 @@ class ConfigFileLoaderTest extends MockedTest
|
|||
->at($this->root)
|
||||
->setContent(file_get_contents($file));
|
||||
|
||||
$configFileLoader = new ConfigFileLoader(
|
||||
$configFileLoader = new ConfigFileManager(
|
||||
$this->root->url(),
|
||||
$this->root->url() . DIRECTORY_SEPARATOR . Config::CONFIG_DIR,
|
||||
$this->root->url() . DIRECTORY_SEPARATOR . Config::STATIC_DIR
|
||||
|
@ -228,7 +228,7 @@ class ConfigFileLoaderTest extends MockedTest
|
|||
->at($this->root->getChild('addon')->getChild('test')->getChild('config'))
|
||||
->setContent(file_get_contents($file));
|
||||
|
||||
$configFileLoader = new ConfigFileLoader(
|
||||
$configFileLoader = new ConfigFileManager(
|
||||
$this->root->url(),
|
||||
$this->root->url() . DIRECTORY_SEPARATOR . Config::CONFIG_DIR,
|
||||
$this->root->url() . DIRECTORY_SEPARATOR . Config::STATIC_DIR
|
||||
|
@ -265,7 +265,7 @@ class ConfigFileLoaderTest extends MockedTest
|
|||
->at($this->root->getChild('config'))
|
||||
->setContent(file_get_contents($fileDir . 'B.config.php'));
|
||||
|
||||
$configFileLoader = new ConfigFileLoader(
|
||||
$configFileLoader = new ConfigFileManager(
|
||||
$this->root->url(),
|
||||
$this->root->url() . DIRECTORY_SEPARATOR . Config::CONFIG_DIR,
|
||||
$this->root->url() . DIRECTORY_SEPARATOR . Config::STATIC_DIR
|
||||
|
@ -299,7 +299,7 @@ class ConfigFileLoaderTest extends MockedTest
|
|||
->at($this->root->getChild('config'))
|
||||
->setContent(file_get_contents($fileDir . 'B.ini.php'));
|
||||
|
||||
$configFileLoader = new ConfigFileLoader(
|
||||
$configFileLoader = new ConfigFileManager(
|
||||
$this->root->url(),
|
||||
$this->root->url() . DIRECTORY_SEPARATOR . Config::CONFIG_DIR,
|
||||
$this->root->url() . DIRECTORY_SEPARATOR . Config::STATIC_DIR
|
||||
|
@ -333,7 +333,7 @@ class ConfigFileLoaderTest extends MockedTest
|
|||
->at($this->root->getChild('config'))
|
||||
->setContent(file_get_contents($fileDir . 'B.ini.php'));
|
||||
|
||||
$configFileLoader = new ConfigFileLoader(
|
||||
$configFileLoader = new ConfigFileManager(
|
||||
$this->root->url(),
|
||||
$this->root->url() . DIRECTORY_SEPARATOR . Config::CONFIG_DIR,
|
||||
$this->root->url() . DIRECTORY_SEPARATOR . Config::STATIC_DIR
|
||||
|
@ -386,4 +386,45 @@ class ConfigFileLoaderTest extends MockedTest
|
|||
|
||||
self::assertEquals('newValue', $configCache->get('system', 'newKey'));
|
||||
}
|
||||
|
||||
public function testSaveData()
|
||||
{
|
||||
$this->delConfigFile('local.config.php');
|
||||
|
||||
$fileDir = dirname(__DIR__) . DIRECTORY_SEPARATOR .
|
||||
'..' . DIRECTORY_SEPARATOR .
|
||||
'..' . DIRECTORY_SEPARATOR .
|
||||
'..' . DIRECTORY_SEPARATOR .
|
||||
'datasets' . DIRECTORY_SEPARATOR .
|
||||
'config' . DIRECTORY_SEPARATOR;
|
||||
|
||||
vfsStream::newFile('B.config.php')
|
||||
->at($this->root->getChild('config2'))
|
||||
->setContent(file_get_contents($fileDir . 'B.config.php'));
|
||||
|
||||
$configFileLoader = (new Config())->createConfigFileLoader($this->root->url(), ['FRIENDICA_CONFIG_DIR' => $this->root->getChild('config2')->url()]);
|
||||
$configCache = new \Friendica\Core\Config\ValueObject\Cache();
|
||||
|
||||
$configFileLoader->setupCache($configCache);
|
||||
|
||||
// overwrite some data and save it back to the config file
|
||||
$configCache->set('system', 'test', 'it', \Friendica\Core\Config\ValueObject\Cache::SOURCE_DATA);
|
||||
$configCache->set('config', 'test', 'it', \Friendica\Core\Config\ValueObject\Cache::SOURCE_DATA);
|
||||
$configCache->set('system', 'test_2', 2, \Friendica\Core\Config\ValueObject\Cache::SOURCE_DATA);
|
||||
$configFileLoader->saveData($configCache);
|
||||
|
||||
// Reload the configCache with the new values
|
||||
$configCache2 = new \Friendica\Core\Config\ValueObject\Cache();
|
||||
$configFileLoader->setupCache($configCache2);
|
||||
|
||||
self::assertEquals($configCache, $configCache2);
|
||||
self::assertEquals([
|
||||
'system' => [
|
||||
'test' => 'it',
|
||||
'test_2' => 2
|
||||
],
|
||||
'config' => [
|
||||
'test' => 'it'
|
||||
]], $configCache2->getDataBySource(\Friendica\Core\Config\ValueObject\Cache::SOURCE_DATA));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue