From: Philipp Date: Sun, 26 Mar 2023 20:27:24 +0000 (+0200) Subject: Fixup and adding tests X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=e072c9985e7a644e712c6259974cd7ba587adf4c;p=friendica.git Fixup and adding tests --- diff --git a/src/Core/Config/Model/DatabaseConfig.php b/src/Core/Config/Model/DatabaseConfig.php index 75ce1b149d..058c903599 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 86b7c167ce..4c31a5e64e 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 b526fc13b5..0c9d671ea9 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)); + } + } + } + } }