]> git.mxchange.org Git - friendica.git/blobdiff - tests/Util/VFSTrait.php
Merge pull request #13651 from annando/picture-upload
[friendica.git] / tests / Util / VFSTrait.php
index ecf0880d29b68729da0ec46e41003521639e3165..4c31a5e64e702edd95daef0ad4fa8e3f3ee32ac3 100644 (file)
@@ -1,4 +1,23 @@
 <?php
+/**
+ * @copyright Copyright (C) 2010-2023, the Friendica project
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
 
 namespace Friendica\Test\Util;
 
@@ -24,44 +43,54 @@ trait VFSTrait
                        'static' => [],
                        'test' => [],
                        'logs' => [],
+                       'config2' => [],
                ];
 
                // create a virtual directory and copy all needed files and folders to it
                $this->root = vfsStream::setup('friendica', 0777, $structure);
 
-               $this->setConfigFile('dbstructure.config.php', true);
-               $this->setConfigFile('defaults.config.php', true);
-               $this->setConfigFile('settings.config.php', true);
-               $this->setConfigFile('local.config.php');
+               $this->setConfigFile('static' . DIRECTORY_SEPARATOR . 'dbstructure.config.php', true);
+               $this->setConfigFile('static' . DIRECTORY_SEPARATOR . 'dbview.config.php', true);
+               $this->setConfigFile('static' . DIRECTORY_SEPARATOR . 'defaults.config.php', true);
+               $this->setConfigFile('static' . DIRECTORY_SEPARATOR . 'settings.config.php', true);
+               $this->setConfigFile(
+                       'mods' . DIRECTORY_SEPARATOR . 'local.config.ci.php',
+                       false, 'local.config.php'
+               );
        }
 
        /**
         * Copying a config file from the file system to the Virtual File System
         *
-        * @param string $filename The filename of the config file
-        * @param bool $static True, if the folder `static` instead of `config` should be used
+        * @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($filename, bool $static = false)
+       public function setConfigFile(string $sourceFilePath, bool $static = false, string $targetFileName = null)
        {
                $file = dirname(__DIR__) . DIRECTORY_SEPARATOR .
                        '..' . DIRECTORY_SEPARATOR .
-                       ($static ? 'static' : 'config') . DIRECTORY_SEPARATOR .
-                       $filename;
+                               $sourceFilePath;
 
                if (file_exists($file)) {
-                       vfsStream::newFile($filename)
+                       if (empty($targetFileName)) {
+                               $tmpArray = preg_split('/\\' . DIRECTORY_SEPARATOR . '/', $sourceFilePath);
+                               $targetFileName = array_pop($tmpArray);
+                       }
+                       vfsStream::newFile($targetFileName)
                                ->at($this->root->getChild(($static ? 'static' : 'config')))
                                ->setContent(file_get_contents($file));
+               } else {
+                       throw new \Exception(sprintf('Unexpected missing config \'%s\'', $file));
                }
        }
 
        /**
-        * Delets a config file from the Virtual File System
+        * Deletes a config file from the Virtual File System
         *
         * @param string $filename The filename of the config file
-        * @param bool $static True, if the folder `static` instead of `config` should be used
+        * @param bool   $static   True, if the folder `static` instead of `config` should be used
         */
-       protected function delConfigFile($filename, bool $static = false)
+       protected function delConfigFile(string $filename, bool $static = false)
        {
                if ($this->root->hasChild(($static ? 'static' : 'config') . '/' . $filename)) {
                        $this->root->getChild(($static ? 'static' : 'config'))->removeChild($filename);