]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
Fix warnings when upgrading from legacy SebSauvage version 1063/head
authorArthurHoaro <arthur@hoa.ro>
Thu, 25 Jan 2018 18:55:31 +0000 (19:55 +0100)
committerArthurHoaro <arthur@hoa.ro>
Thu, 25 Jan 2018 18:55:31 +0000 (19:55 +0100)
Fixes #1040

application/config/ConfigPhp.php
tests/config/ConfigPhpTest.php
tests/utils/config/emptyConfigPhp.php [new file with mode: 0644]

index 2f66e8e00ac18a537db96d77e2bf66e175c87c29..8add8bcd776009e1cff804f3b8f47e5417ff4c6f 100644 (file)
@@ -83,10 +83,10 @@ class ConfigPhp implements ConfigIO
 
         $out = array();
         foreach (self::$ROOT_KEYS as $key) {
-            $out[$key] = $GLOBALS[$key];
+            $out[$key] = isset($GLOBALS[$key]) ? $GLOBALS[$key] : '';
         }
-        $out['config'] = $GLOBALS['config'];
-        $out['plugins'] = !empty($GLOBALS['plugins']) ? $GLOBALS['plugins'] : array();
+        $out['config'] = isset($GLOBALS['config']) ? $GLOBALS['config'] : [];
+        $out['plugins'] = isset($GLOBALS['plugins']) ? $GLOBALS['plugins'] : [];
         return $out;
     }
 
index abfbb30538f7f27b06468a3be6887a0ebe1f3de1..be23eea1563a909ecce1a981d1194040d8d9fe3a 100644 (file)
@@ -36,6 +36,20 @@ class ConfigPhpTest extends \PHPUnit_Framework_TestCase
         $this->assertEquals(array(), $this->configIO->read('nope'));
     }
 
+    /**
+     * Read an empty existent config file -> array with blank default values.
+     */
+    public function testReadEmpty()
+    {
+        $dataFile = 'tests/utils/config/emptyConfigPhp.php';
+        $conf = $this->configIO->read($dataFile);
+        $this->assertEmpty($conf['login']);
+        $this->assertEmpty($conf['title']);
+        $this->assertEmpty($conf['titleLink']);
+        $this->assertEmpty($conf['config']);
+        $this->assertEmpty($conf['plugins']);
+    }
+
     /**
      * Write a new config file.
      */
diff --git a/tests/utils/config/emptyConfigPhp.php b/tests/utils/config/emptyConfigPhp.php
new file mode 100644 (file)
index 0000000..b3d9bbc
--- /dev/null
@@ -0,0 +1 @@
+<?php