1
0
Fork 0

Revert node.config.php into Config table

This commit is contained in:
Philipp Holzer 2023-02-05 00:15:01 +01:00
commit 513ef03421
Signed by: nupplaPhil
GPG key ID: 24A7501396EB5432
27 changed files with 425 additions and 829 deletions

View file

@ -57,12 +57,12 @@ class DatabaseCacheTest extends CacheTest
$configFactory = new Config();
$configFileManager = (new Config())->createConfigFileManager($this->root->url(), []);
$configCache = $configFactory->createCache($configFileManager);
$config = new \Friendica\Core\Config\Model\Config($configFileManager, $configCache);
$config = new \Friendica\Core\Config\Model\ReadOnlyFileConfig($configCache);
$dbaDefinition = (new DbaDefinition($configCache->get('system', 'basepath')))->load();
$viewDefinition = (new ViewDefinition($configCache->get('system', 'basepath')))->load();
$dba = new StaticDatabase($config, $profiler, $dbaDefinition, $viewDefinition, new NullLogger());
$dba = new StaticDatabase($config, $dbaDefinition, $viewDefinition);
$this->cache = new Cache\Type\DatabaseCache('database', $dba);
return $this->cache;

View file

@ -392,91 +392,6 @@ class ConfigFileManagerTest 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'));
$configFileManager = (new Config())->createConfigFileManager($this->root->url(),
[
'FRIENDICA_CONFIG_DIR' => $this->root->getChild('config2')->url(),
]);
$configCache = new Cache();
$configFileManager->setupCache($configCache);
$specialChars = '!"§$%&/()(/&%$\'><?$a,;:[]}{}\\?¿¿ß';
// overwrite some data and save it back to the config file
$configCache->set('system', 'test', 'it', Cache::SOURCE_DATA);
$configCache->set('config', 'test', 'it', Cache::SOURCE_DATA);
$configCache->set('system', 'test_2', 2, Cache::SOURCE_DATA);
$configCache->set('special_chars', 'special', $specialChars, Cache::SOURCE_DATA);
$configFileManager->saveData($configCache);
// Reload the configCache with the new values
$configCache2 = new Cache();
$configFileManager->setupCache($configCache2);
self::assertEquals($configCache, $configCache2);
self::assertEquals([
'system' => [
'test' => 'it',
'test_2' => 2
],
'config' => [
'test' => 'it',
],
'special_chars' => [
'special' => $specialChars,
]], $configCache2->getDataBySource(Cache::SOURCE_DATA));
}
/**
* If we delete something with the Cache::delete() functionality, be sure to probably reset it to the underlying key
*/
public function testDeleteKeyOverwrite()
{
$this->delConfigFile('node.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('config'))
->setContent(file_get_contents($fileDir . 'B.config.php'));
$configFileManager = (new Config())->createConfigFileManager($this->root->url());
$configCache = new Cache();
$configFileManager->setupCache($configCache);
$configCache->delete('system', 'default_timezone');
$configFileManager->saveData($configCache);
// assert that system.default_timezone is now the restored 'UTC' from the defaults
$configCache = new Cache();
$configFileManager->setupCache($configCache);
self::assertEquals('UTC', $configCache->get('system', 'default_timezone'));
}
/**
* Test for empty node.config.php
*/

View file

@ -23,18 +23,21 @@ namespace Friendica\Test\src\Core\Config;
use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\Config\Model\Config;
use Friendica\Core\Config\Model\DatabaseConfig;
use Friendica\Core\Config\Model\ReadOnlyFileConfig;
use Friendica\Core\Config\Util\ConfigFileManager;
use Friendica\Core\Config\Util\ConfigFileTransformer;
use Friendica\Core\Config\ValueObject\Cache;
use Friendica\Test\MockedTest;
use Friendica\Test\DatabaseTest;
use Friendica\Test\Util\CreateDatabaseTrait;
use Friendica\Test\Util\VFSTrait;
use org\bovigo\vfs\vfsStream;
class ConfigTest extends MockedTest
class ConfigTest extends DatabaseTest
{
use ArraySubsetAsserts;
use VFSTrait;
use CreateDatabaseTrait;
/** @var Cache */
protected $configCache;
@ -77,7 +80,7 @@ class ConfigTest extends MockedTest
public function getInstance()
{
$this->configFileManager->setupCache($this->configCache);
return new Config($this->configFileManager, $this->configCache);
return new DatabaseConfig($this->getDbInstance(), $this->configCache);
}
public function dataTests()
@ -170,7 +173,7 @@ class ConfigTest extends MockedTest
{
vfsStream::newFile(ConfigFileManager::CONFIG_DATA_FILE)
->at($this->root->getChild('config'))
->setContent(ConfigFileTransformer::encode($data));
->setContent(print_r($data, true));
$this->testedConfig = $this->getInstance();
self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
@ -191,7 +194,7 @@ class ConfigTest extends MockedTest
{
vfsStream::newFile(ConfigFileManager::CONFIG_DATA_FILE)
->at($this->root->getChild('config'))
->setContent(ConfigFileTransformer::encode($data));
->setContent(print_r($data, true));
$this->testedConfig = $this->getInstance();
self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
@ -276,7 +279,7 @@ class ConfigTest extends MockedTest
{
vfsStream::newFile(ConfigFileManager::CONFIG_DATA_FILE)
->at($this->root->getChild('config'))
->setContent(ConfigFileTransformer::encode($data1));
->setContent(print_r($data1, true));
$this->testedConfig = $this->getInstance();
self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
@ -288,7 +291,7 @@ class ConfigTest extends MockedTest
vfsStream::newFile(ConfigFileManager::CONFIG_DATA_FILE)
->at($this->root->getChild('config'))
->setContent(ConfigFileTransformer::encode($data2));
->setContent(print_r($data2, true));
$this->testedConfig->reload();
@ -302,7 +305,7 @@ class ConfigTest extends MockedTest
*/
public function testLoadWrong()
{
$this->testedConfig = new Config($this->configFileManager, new Cache());
$this->testedConfig = new ReadOnlyFileConfig(new Cache());
self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
self::assertEmpty($this->testedConfig->getCache()->getAll());
@ -354,7 +357,7 @@ class ConfigTest extends MockedTest
{
$this->configCache->load(['test' => ['it' => $data]], Cache::SOURCE_FILE);
$this->testedConfig = new Config($this->configFileManager, $this->configCache);
$this->testedConfig = new DatabaseConfig($this->getDbInstance(), $this->configCache);
self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
self::assertEquals($data, $this->testedConfig->get('test', 'it'));
@ -388,9 +391,9 @@ class ConfigTest extends MockedTest
{
vfsStream::newFile(ConfigFileManager::CONFIG_DATA_FILE)
->at($this->root->getChild('config'))
->setContent(ConfigFileTransformer::encode([
->setContent(print_r([
'config' => ['test' => 'it'],
]));
], true));
$this->testedConfig = $this->getInstance();
self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
@ -526,7 +529,7 @@ class ConfigTest extends MockedTest
public function testGetCategory(array $data, string $category, array $assertion)
{
$this->configCache = new Cache($data);
$config = new Config($this->configFileManager, $this->configCache);
$config = new ReadOnlyFileConfig($this->configCache);
self::assertEquals($assertion, $config->get($category));
}
@ -538,9 +541,9 @@ class ConfigTest extends MockedTest
{
vfsStream::newFile(ConfigFileManager::CONFIG_DATA_FILE)
->at($this->root->getChild('config'))
->setContent(ConfigFileTransformer::encode([
->setContent(print_r([
'config' => ['sitename' => 'overritten'],
]));
], true));
$config = $this->getInstance();
self::assertEquals('overritten', $config->get('config', 'sitename'));

View file

@ -22,18 +22,21 @@
namespace Friendica\Test\src\Core\Config;
use Friendica\Core\Config\Capability\ISetConfigValuesTransactionally;
use Friendica\Core\Config\Model\Config;
use Friendica\Core\Config\Model\DatabaseConfig;
use Friendica\Core\Config\Model\ReadOnlyFileConfig;
use Friendica\Core\Config\Model\ConfigTransaction;
use Friendica\Core\Config\Util\ConfigFileManager;
use Friendica\Core\Config\ValueObject\Cache;
use Friendica\Database\Database;
use Friendica\Test\DatabaseTest;
use Friendica\Test\FixtureTest;
use Friendica\Test\MockedTest;
use Friendica\Test\Util\Database\StaticDatabase;
use Friendica\Test\Util\VFSTrait;
use Mockery\Exception\InvalidCountException;
class ConfigTransactionTest extends MockedTest
class ConfigTransactionTest extends FixtureTest
{
use VFSTrait;
/** @var ConfigFileManager */
protected $configFileManager;
@ -41,8 +44,6 @@ class ConfigTransactionTest extends MockedTest
{
parent::setUp();
$this->setUpVfsDir();
$this->configFileManager = new ConfigFileManager($this->root->url(), $this->root->url() . '/config/', $this->root->url() . '/static/');
}
@ -57,7 +58,7 @@ class ConfigTransactionTest extends MockedTest
public function testInstance()
{
$config = new Config($this->configFileManager, new Cache());
$config = new DatabaseConfig($this->dice->create(Database::class), new Cache());
$configTransaction = new ConfigTransaction($config);
self::assertInstanceOf(ISetConfigValuesTransactionally::class, $configTransaction);
@ -66,17 +67,13 @@ class ConfigTransactionTest extends MockedTest
public function testConfigTransaction()
{
$config = new Config($this->configFileManager, new Cache());
$config = new DatabaseConfig($this->dice->create(Database::class), new Cache());
$config->set('config', 'key1', 'value1');
$config->set('system', 'key2', 'value2');
$config->set('system', 'keyDel', 'valueDel');
$config->set('delete', 'keyDel', 'catDel');
$configTransaction = new ConfigTransaction($config);
// the config file knows it as well immediately
$tempData = include $this->root->url() . '/config/' . ConfigFileManager::CONFIG_DATA_FILE;
self::assertEquals('value1', $tempData['config']['key1'] ?? null);
self::assertEquals('value2', $tempData['system']['key2'] ?? null);
// new key-value
$configTransaction->set('transaction', 'key3', 'value3');
@ -93,11 +90,6 @@ class ConfigTransactionTest extends MockedTest
self::assertEquals('valueDel', $config->get('system', 'keyDel'));
self::assertEquals('catDel', $config->get('delete', 'keyDel'));
// The config file still doesn't know it either
$tempData = include $this->root->url() . '/config/' . ConfigFileManager::CONFIG_DATA_FILE;
self::assertEquals('value1', $tempData['config']['key1'] ?? null);
self::assertEquals('value2', $tempData['system']['key2'] ?? null);
self::assertEquals('catDel', $tempData['delete']['keyDel'] ?? null);
self::assertNull($tempData['transaction']['key3'] ?? null);
// save it back!
$configTransaction->commit();
@ -107,12 +99,6 @@ class ConfigTransactionTest extends MockedTest
self::assertEquals('value3', $config->get('transaction', 'key3'));
self::assertNull($config->get('system', 'keyDel'));
self::assertNull($config->get('delete', 'keyDel'));
$tempData = include $this->root->url() . '/config/' . ConfigFileManager::CONFIG_DATA_FILE;
self::assertEquals('changedValue1', $tempData['config']['key1'] ?? null);
self::assertEquals('value2', $tempData['system']['key2'] ?? null);
self::assertEquals('value3', $tempData['transaction']['key3'] ?? null);
self::assertNull($tempData['system']['keyDel'] ?? null);
self::assertNull($tempData['delete']['keyDel'] ?? null);
// the whole category should be gone
self::assertNull($tempData['delete'] ?? null);
}
@ -124,7 +110,7 @@ class ConfigTransactionTest extends MockedTest
{
$this->configFileManager = \Mockery::spy(ConfigFileManager::class);
$config = new Config($this->configFileManager, new Cache());
$config = new DatabaseConfig($this->dice->create(Database::class), new Cache());
$configTransaction = new ConfigTransaction($config);
// commit empty transaction

View file

@ -1,110 +0,0 @@
<?php
/**
* @copyright Copyright (C) 2010-2023, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
namespace Friendica\Test\src\Core\Config\Util;
use Friendica\Core\Config\Util\ConfigFileTransformer;
use Friendica\Test\MockedTest;
use Friendica\Test\Util\SerializableObjectDouble;
use ParagonIE\HiddenString\HiddenString;
use function PHPUnit\Framework\assertEquals;
class ConfigFileTransformerTest extends MockedTest
{
public function dataTests()
{
return [
'default' => [
'configFile' => (dirname(__DIR__, 4) . '/datasets/config/A.node.config.php'),
],
'extended' => [
'configFile' => (dirname(__DIR__, 4) . '/datasets/config/B.node.config.php'),
],
'friendica.local' => [
'configFile' => (dirname(__DIR__, 4) . '/datasets/config/transformer/C.node.config.php'),
],
'friendica.local.2' => [
'configFile' => (dirname(__DIR__, 4) . '/datasets/config/transformer/D.node.config.php'),
],
'object_invalid' => [
'configFile' => (dirname(__DIR__, 4) . '/datasets/config/transformer/object.node.config.php'),
'assertException' => true,
],
'resource' => [
'configFile' => (dirname(__DIR__, 4) . '/datasets/config/transformer/ressource.node.config.php'),
'assertException' => false,
'assertion' => <<<EOF
<?php
return [
'ressource' => [
'ressources_not_allowed' => '',
],
];
EOF,
],
'object_valid' => [
'configFile' => (dirname(__DIR__, 4) . '/datasets/config/transformer/object_valid.node.config.php'),
'assertException' => false,
'assertion' => <<<EOF
<?php
return [
'object' => [
'toString' => 'test',
'serializable' => 'serialized',
],
];
EOF,
],
'test_types' => [
'configFile' => (dirname(__DIR__, 4) . '/datasets/config/transformer/types.node.config.php'),
],
'small_types' => [
'configFile' => (dirname(__DIR__, 4) . '/datasets/config/transformer/small_types.node.config.php'),
]
];
}
/**
* Tests if the given config will be decoded into an array and encoded into the same string again
*
* @dataProvider dataTests
*/
public function testConfigFile(string $configFile, bool $assertException = false, $assertion = null)
{
$dataArray = include $configFile;
if ($assertException) {
self::expectException(\InvalidArgumentException::class);
}
$newConfig = ConfigFileTransformer::encode($dataArray);
if (empty($assertion)) {
self::assertEquals(file_get_contents($configFile), $newConfig);
} else {
self::assertEquals($assertion, $newConfig);
}
}
}

View file

@ -63,7 +63,7 @@ class InstallerTest extends MockedTest
->with(L10n::class)
->andReturn($this->l10nMock);
DI::init($this->dice);
DI::init($this->dice, true);
}
public static function tearDownAfterClass(): void
@ -361,7 +361,7 @@ class InstallerTest extends MockedTest
->with(ICanSendHttpRequests::class)
->andReturn($networkMock);
DI::init($this->dice);
DI::init($this->dice, true);
// Mocking that we can use CURL
$this->setFunctions(['curl_init' => true]);
@ -408,7 +408,7 @@ class InstallerTest extends MockedTest
->with(ICanSendHttpRequests::class)
->andReturn($networkMock);
DI::init($this->dice);
DI::init($this->dice, true);
// Mocking that we can use CURL
$this->setFunctions(['curl_init' => true]);

View file

@ -24,11 +24,8 @@ namespace Friendica\Test\src\Core\Lock;
use Dice\Dice;
use Friendica\App;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\Config\Model\Config;
use Friendica\Core\Config\Type\JitConfig;
use Friendica\Core\Config\Util\ConfigFileManager;
use Friendica\Core\Config\Model\ReadOnlyFileConfig;
use Friendica\Core\Config\ValueObject\Cache;
use Friendica\Core\Lock\Type\SemaphoreLock;
use Friendica\Core\System;
use Friendica\DI;
use Mockery;
@ -46,11 +43,11 @@ class SemaphoreLockTest extends LockTest
$dice->shouldReceive('create')->with(App::class)->andReturn($app);
$configCache = new Cache(['system' => ['temppath' => '/tmp']]);
$configMock = new Config(Mockery::mock(ConfigFileManager::class), $configCache);
$configMock = new ReadOnlyFileConfig($configCache);
$dice->shouldReceive('create')->with(IManageConfigValues::class)->andReturn($configMock);
// @todo Because "get_temppath()" is using static methods, we have to initialize the BaseObject
DI::init($dice);
DI::init($dice, true);
parent::setUp();
}

View file

@ -75,19 +75,19 @@ class StorageManagerTest extends DatabaseTest
vfsStream::newDirectory(Type\FilesystemConfig::DEFAULT_BASE_FOLDER, 0777)->at($this->root);
$this->logger = new NullLogger();
$this->database = $this->getDbInstance();
$configFactory = new Config();
$configFileManager = $configFactory->createConfigFileManager($this->root->url());
$configCache = $configFactory->createCache($configFileManager);
$this->config = new \Friendica\Core\Config\Model\Config($configFileManager, $configCache);
$this->config = new \Friendica\Core\Config\Model\DatabaseConfig($this->database, $configCache);
$this->config->set('storage', 'name', 'Database');
$this->config->set('storage', 'filesystem_path', $this->root->getChild(Type\FilesystemConfig::DEFAULT_BASE_FOLDER)
->url());
$this->l10n = \Mockery::mock(L10n::class);
$this->database = $this->getDbInstance();
}
protected function tearDown(): void

View file

@ -36,7 +36,7 @@ class SystemTest extends TestCase
$dice = \Mockery::mock(Dice::class);
$dice->shouldReceive('create')->with(BaseURL::class)->andReturn($baseUrl);
DI::init($dice);
DI::init($dice, true);
}
private function assertGuid($guid, $length, $prefix = '')

View file

@ -47,7 +47,7 @@ class UserTest extends MockedTest
/** @var Dice|MockInterface $diceMock */
$diceMock = $diceMock->addRules(include __DIR__ . '/../../../static/dependencies.config.php');
$diceMock->shouldReceive('create')->withArgs([Database::class])->andReturn($this->dbMock);
DI::init($diceMock);
DI::init($diceMock, true);
$this->parent = [
'uid' => 1,

View file

@ -23,15 +23,18 @@ namespace Friendica\Test\src\Util;
use Friendica\App\BaseURL;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\Config\Model\Config;
use Friendica\Core\Config\Model\DatabaseConfig;
use Friendica\Core\Config\Model\ReadOnlyFileConfig;
use Friendica\Core\Config\Util\ConfigFileManager;
use Friendica\Core\Config\ValueObject\Cache;
use Friendica\Test\MockedTest;
use Friendica\Test\DatabaseTest;
use Friendica\Test\Util\CreateDatabaseTrait;
use Friendica\Test\Util\VFSTrait;
class BaseURLTest extends MockedTest
class BaseURLTest extends DatabaseTest
{
use VFSTrait;
use CreateDatabaseTrait;
protected function setUp(): void
{
@ -302,8 +305,7 @@ class BaseURLTest extends MockedTest
*/
public function testSave($input, $save, $url)
{
$configFileManager = new ConfigFileManager($this->root->url(), $this->root->url() . '/config/', $this->root->url() . '/static/');
$config = new Config($configFileManager, new Cache([
$config = new DatabaseConfig($this->getDbInstance(), new Cache([
'config' => [
'hostname' => $input['hostname'] ?? null,
],
@ -332,8 +334,7 @@ class BaseURLTest extends MockedTest
*/
public function testSaveByUrl($input, $save, $url)
{
$configFileManager = new ConfigFileManager($this->root->url(), $this->root->url() . '/config/', $this->root->url() . '/static/');
$config = new Config($configFileManager, new Cache([
$config = new DatabaseConfig($this->getDbInstance(), new Cache([
'config' => [
'hostname' => $input['hostname'] ?? null,
],