2018-10-06 10:27:20 -04:00
|
|
|
<?php
|
2020-02-09 09:45:36 -05:00
|
|
|
/**
|
|
|
|
* @copyright Copyright (C) 2020, Friendica
|
|
|
|
*
|
|
|
|
* @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/>.
|
|
|
|
*
|
|
|
|
*/
|
2018-10-06 10:27:20 -04:00
|
|
|
|
|
|
|
namespace Friendica\Test\Util;
|
|
|
|
|
|
|
|
|
|
|
|
use org\bovigo\vfs\vfsStream;
|
|
|
|
use org\bovigo\vfs\vfsStreamDirectory;
|
|
|
|
|
|
|
|
trait VFSTrait
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var vfsStreamDirectory The Stream Directory
|
|
|
|
*/
|
|
|
|
protected $root;
|
|
|
|
|
2018-10-31 05:24:07 -04:00
|
|
|
/**
|
|
|
|
* Sets up the Virtual File System for Friendica with common files (config, dbstructure)
|
|
|
|
*/
|
2018-10-06 10:27:20 -04:00
|
|
|
protected function setUpVfsDir() {
|
|
|
|
// the used directories inside the App class
|
|
|
|
$structure = [
|
|
|
|
'config' => [],
|
2018-10-31 06:03:15 -04:00
|
|
|
'bin' => [],
|
2019-06-23 13:56:21 -04:00
|
|
|
'static' => [],
|
|
|
|
'test' => [],
|
2019-09-23 09:23:09 -04:00
|
|
|
'logs' => [],
|
2018-10-06 10:27:20 -04:00
|
|
|
];
|
|
|
|
|
|
|
|
// create a virtual directory and copy all needed files and folders to it
|
2019-03-13 18:05:33 -04:00
|
|
|
$this->root = vfsStream::setup('friendica', 0777, $structure);
|
2018-10-06 10:27:20 -04:00
|
|
|
|
2019-08-03 14:48:56 -04:00
|
|
|
$this->setConfigFile('dbstructure.config.php', true);
|
2019-06-23 13:56:21 -04:00
|
|
|
$this->setConfigFile('defaults.config.php', true);
|
|
|
|
$this->setConfigFile('settings.config.php', true);
|
2018-11-25 01:44:09 -05:00
|
|
|
$this->setConfigFile('local.config.php');
|
2018-10-06 10:27:20 -04:00
|
|
|
}
|
|
|
|
|
2018-10-31 05:24:07 -04:00
|
|
|
/**
|
|
|
|
* Copying a config file from the file system to the Virtual File System
|
|
|
|
*
|
|
|
|
* @param string $filename The filename of the config file
|
2019-06-23 13:56:21 -04:00
|
|
|
* @param bool $static True, if the folder `static` instead of `config` should be used
|
2018-10-31 05:24:07 -04:00
|
|
|
*/
|
2019-06-23 13:56:21 -04:00
|
|
|
protected function setConfigFile($filename, bool $static = false)
|
2018-10-06 10:27:20 -04:00
|
|
|
{
|
|
|
|
$file = dirname(__DIR__) . DIRECTORY_SEPARATOR .
|
|
|
|
'..' . DIRECTORY_SEPARATOR .
|
2019-06-23 13:56:21 -04:00
|
|
|
($static ? 'static' : 'config') . DIRECTORY_SEPARATOR .
|
2018-10-06 10:27:20 -04:00
|
|
|
$filename;
|
|
|
|
|
|
|
|
if (file_exists($file)) {
|
|
|
|
vfsStream::newFile($filename)
|
2019-06-23 13:56:21 -04:00
|
|
|
->at($this->root->getChild(($static ? 'static' : 'config')))
|
2018-10-06 10:27:20 -04:00
|
|
|
->setContent(file_get_contents($file));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-31 05:24:07 -04:00
|
|
|
/**
|
|
|
|
* Delets a config file from the Virtual File System
|
|
|
|
*
|
|
|
|
* @param string $filename The filename of the config file
|
2019-06-23 13:56:21 -04:00
|
|
|
* @param bool $static True, if the folder `static` instead of `config` should be used
|
2018-10-31 05:24:07 -04:00
|
|
|
*/
|
2019-06-23 13:56:21 -04:00
|
|
|
protected function delConfigFile($filename, bool $static = false)
|
2018-10-06 10:27:20 -04:00
|
|
|
{
|
2019-06-23 13:56:21 -04:00
|
|
|
if ($this->root->hasChild(($static ? 'static' : 'config') . '/' . $filename)) {
|
|
|
|
$this->root->getChild(($static ? 'static' : 'config'))->removeChild($filename);
|
2018-10-06 10:27:20 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|