3 * @copyright Copyright (C) 2010-2023, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Test\Util;
25 use org\bovigo\vfs\vfsStream;
26 use org\bovigo\vfs\vfsStreamDirectory;
31 * @var vfsStreamDirectory The Stream Directory
36 * Sets up the Virtual File System for Friendica with common files (config, dbstructure)
38 protected function setUpVfsDir() {
39 // the used directories inside the App class
49 // create a virtual directory and copy all needed files and folders to it
50 $this->root = vfsStream::setup('friendica', 0777, $structure);
52 $this->setConfigFile('dbstructure.config.php', true);
53 $this->setConfigFile('dbview.config.php', true);
54 $this->setConfigFile('defaults.config.php', true);
55 $this->setConfigFile('settings.config.php', true);
56 $this->setConfigFile('local.config.php');
57 $this->setDataFile('node.config.php');
60 protected function setDataFile(string $filename)
62 $file = dirname(__DIR__) . DIRECTORY_SEPARATOR .
63 'datasets' . DIRECTORY_SEPARATOR .
64 'config' . DIRECTORY_SEPARATOR .
67 if (file_exists($file)) {
68 vfsStream::newFile($filename)
69 ->at($this->root->getChild('config'))
70 ->setContent(file_get_contents($file));
75 * Copying a config file from the file system to the Virtual File System
77 * @param string $filename The filename of the config file
78 * @param bool $static True, if the folder `static` instead of `config` should be used
80 protected function setConfigFile(string $filename, bool $static = false)
82 $file = dirname(__DIR__) . DIRECTORY_SEPARATOR .
83 '..' . DIRECTORY_SEPARATOR .
84 ($static ? 'static' : 'config') . DIRECTORY_SEPARATOR .
87 if (file_exists($file)) {
88 vfsStream::newFile($filename)
89 ->at($this->root->getChild(($static ? 'static' : 'config')))
90 ->setContent(file_get_contents($file));
95 * Delets a config file from the Virtual File System
97 * @param string $filename The filename of the config file
98 * @param bool $static True, if the folder `static` instead of `config` should be used
100 protected function delConfigFile(string $filename, bool $static = false)
102 if ($this->root->hasChild(($static ? 'static' : 'config') . '/' . $filename)) {
103 $this->root->getChild(($static ? 'static' : 'config'))->removeChild($filename);