Fixup and adding tests

This commit is contained in:
Philipp Holzer 2023-03-26 22:27:24 +02:00
parent fa9c3d40be
commit e072c9985e
Signed by: nupplaPhil
GPG key ID: 24A7501396EB5432
3 changed files with 72 additions and 2 deletions

View file

@ -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} */

View file

@ -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 .

View file

@ -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));
}
}
}
}
}