From e072c9985e7a644e712c6259974cd7ba587adf4c Mon Sep 17 00:00:00 2001 From: Philipp Date: Sun, 26 Mar 2023 22:27:24 +0200 Subject: [PATCH] Fixup and adding tests --- src/Core/Config/Model/DatabaseConfig.php | 2 +- tests/Util/VFSTrait.php | 2 +- tests/src/Core/Config/ConfigTest.php | 70 ++++++++++++++++++++++++ 3 files changed, 72 insertions(+), 2 deletions(-) diff --git a/src/Core/Config/Model/DatabaseConfig.php b/src/Core/Config/Model/DatabaseConfig.php index 75ce1b149..058c90359 100644 --- a/src/Core/Config/Model/DatabaseConfig.php +++ b/src/Core/Config/Model/DatabaseConfig.php @@ -83,7 +83,7 @@ class DatabaseConfig implements IManageConfigValues /** {@inheritDoc} */ public function isSetDisabled(string $cat, string $key): bool { - return $this->cache->getSource($cat, $key) >= 0; + return $this->cache->getSource($cat, $key) >= Cache::SOURCE_ENV; } /** {@inheritDoc} */ diff --git a/tests/Util/VFSTrait.php b/tests/Util/VFSTrait.php index 86b7c167c..4c31a5e64 100644 --- a/tests/Util/VFSTrait.php +++ b/tests/Util/VFSTrait.php @@ -65,7 +65,7 @@ trait VFSTrait * @param string $sourceFilePath The filename of the config file * @param bool $static True, if the folder `static` instead of `config` should be used */ - protected function setConfigFile(string $sourceFilePath, bool $static = false, string $targetFileName = null) + public function setConfigFile(string $sourceFilePath, bool $static = false, string $targetFileName = null) { $file = dirname(__DIR__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . diff --git a/tests/src/Core/Config/ConfigTest.php b/tests/src/Core/Config/ConfigTest.php index b526fc13b..0c9d671ea 100644 --- a/tests/src/Core/Config/ConfigTest.php +++ b/tests/src/Core/Config/ConfigTest.php @@ -566,4 +566,74 @@ class ConfigTest extends DatabaseTest $config->set('test', 'it', $value); self:self::assertEquals($assertion, $config->get('test', 'it')); } + + public function dataEnv(): array + { + $data = [ + 'config' => [ + 'admin_email' => 'value1', + 'timezone' => 'value2', + 'language' => 'value3', + 'sitename' => 'value', + ], + 'system' => [ + 'url' => 'value1a', + 'debugging' => true, + 'logfile' => 'value4', + 'loglevel' => 'notice', + 'proflier' => true, + ], + 'proxy' => [ + 'trusted_proxies' => 'value5', + ], + ]; + + return [ + 'empty' => [ + 'data' => $data, + 'server' => [], + 'assertDisabled' => [], + ], + 'mixed' => [ + 'data' => $data, + 'server' => [ + 'FRIENDICA_ADMIN_MAIL' => 'test@friendica.local', + 'FRIENDICA_DEBUGGING' => true, + ], + 'assertDisabled' => [ + 'config' => [ + 'admin_email' => true, + ], + 'system' => [ + 'debugging' => true, + ], + ], + ], + ]; + } + + /** + * Tests if environment variables leads to a disabled set + * + * @dataProvider dataEnv + */ + public function testIsSetDisabled(array $data, array $server, array $assertDisabled) + { + $this->setConfigFile('static' . DIRECTORY_SEPARATOR . 'env.config.php', true); + $this->loadDirectFixture($this->configToDbArray($data), $this->getDbInstance()); + + $configFileManager = new ConfigFileManager($this->root->url(), $this->root->url() . '/config/', $this->root->url() . '/static/', $server); + $configFileManager->setupCache($this->configCache); + $config = new DatabaseConfig($this->getDbInstance(), $this->configCache); + + foreach ($data as $category => $keyvalues) { + foreach ($keyvalues as $key => $value) { + if (!empty($assertDisabled[$category][$key])) { + static::assertTrue($config->isSetDisabled($category, $key), sprintf("%s.%s is not true", $category, $key)); + } else { + static::assertFalse($config->isSetDisabled($category, $key), sprintf("%s.%s is not false", $category, $key)); + } + } + } + } }