]> git.mxchange.org Git - friendica.git/commitdiff
Fixup and adding tests
authorPhilipp <admin@philipp.info>
Sun, 26 Mar 2023 20:27:24 +0000 (22:27 +0200)
committerPhilipp <admin@philipp.info>
Mon, 27 Mar 2023 17:36:13 +0000 (19:36 +0200)
src/Core/Config/Model/DatabaseConfig.php
tests/Util/VFSTrait.php
tests/src/Core/Config/ConfigTest.php

index 75ce1b149d420cd65c9b0d631a83fc8b97049c8d..058c90359944c313cda98f73b8c2577ef98e3d68 100644 (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} */
index 86b7c167ced278755fc9659254b19aa969a1783a..4c31a5e64e702edd95daef0ad4fa8e3f3ee32ac3 100644 (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 .
index b526fc13b50f5c7849a7e27620a08c11ce4290e6..0c9d671ea96c75eab97b75e48e7ce5bf1a3e57d1 100644 (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));
+                               }
+                       }
+               }
+       }
 }