]> git.mxchange.org Git - friendica.git/commitdiff
Add test for Addon failures
authorPhilipp <admin@philipp.info>
Sun, 8 Jan 2023 01:28:27 +0000 (02:28 +0100)
committerPhilipp <admin@philipp.info>
Sun, 8 Jan 2023 01:49:56 +0000 (02:49 +0100)
src/Core/Config/Util/ConfigFileManager.php
src/Core/Config/ValueObject/Cache.php
tests/src/Core/Config/Cache/CacheTest.php

index fff240bb301e800e3178697dfd3846a0170ab3a0..011dbf0e48e3f0e3011b09b53c8702d7036f1b37 100644 (file)
@@ -194,11 +194,13 @@ class ConfigFileManager
 
                        try {
                                if (flock($configStream, LOCK_SH)) {
+                                       clearstatcache(true, $filename);
+
                                        if (($filesize = filesize($filename)) === 0) {
                                                return;
                                        }
 
-                                       $content = fread($configStream, filesize($filename));
+                                       $content = fread($configStream, $filesize);
                                        if (!$content) {
                                                throw new ConfigFileException(sprintf('Couldn\'t read file %s', $filename));
                                        }
index 2082511641263ddf4357cd79bc14a8f3d8785963..7492d287340143d0ae4f0c3b157ff646ddbd4aea 100644 (file)
@@ -283,7 +283,7 @@ class Cache
                                $keys = array_keys($config[$category]);
 
                                foreach ($keys as $key) {
-                                       if (!isset($this->config[$category][$key])) {
+                                       if (!key_exists($key, $this->config[$category] ?? [])) {
                                                $return[$category][$key] = $config[$category][$key];
                                        }
                                }
index dc9b62dc00f4752ea57020f262cecf5989c464db..e14b7998c5db3f411cacffd47808b8956d7f924a 100644 (file)
@@ -40,6 +40,7 @@ class CacheTest extends MockedTest
                                                'int' => 235,
                                                'dec' => 2.456,
                                                'array' => ['1', 2, '3', true, false],
+                                               'null' => null,
                                        ],
                                        'config' => [
                                                'a' => 'value',
@@ -503,6 +504,24 @@ class CacheTest extends MockedTest
                                        ],
                                ],
                        ],
+                       /** @see https://github.com/friendica/friendica/issues/12486#issuecomment-1374609349 */
+                       'test_with_null' => [
+                               'data'      => [
+                                       'test_with_null' => null,
+                                       'config'                => [
+                                               'register_policy' => 2,
+                                               'register_text'   => '',
+                                               'sitename'        => 'Friendica Social Network23',
+                                               'hostname'        => 'friendica.local',
+                                               'private_addons'  => false,
+                                       ],
+                                       'system'                => [
+                                               'dbclean_expire_conversation' => 90,
+                                       ],
+                               ],
+                               'cat'       => 'test_with_null',
+                               'assertion' => null,
+                       ],
                ];
        }
 
@@ -511,10 +530,28 @@ class CacheTest extends MockedTest
         *
         * @dataProvider dataTestCat
         */
-       public function testGetCategory(array $data, string $category, array $assertion)
+       public function testGetCategory($data, string $category, $assertion)
        {
                $cache = new Cache($data);
 
                self::assertEquals($assertion, $cache->get($category));
        }
+
+       /**
+        * Test that the cache can get merged with different categories
+        *
+        * @dataProvider dataTestCat
+        */
+       public function testCatMerge($data, string $category)
+       {
+               $cache = new Cache($data);
+
+               $newCache = $cache->merge(new Cache([
+                       $category => [
+                               'new_key' => 'new_value',
+                       ],
+               ]));
+
+               self::assertEquals('new_value', $newCache->get($category, 'new_key'));
+       }
 }