Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

130 lines
3.8 KiB

* @copyright Copyright (C) 2010-2021, 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
* 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 <>.
namespace Friendica\Test\src\Model\Storage;
use Friendica\Core\Config\IConfig;
use Friendica\Core\L10n;
use Friendica\Model\Storage\Filesystem;
use Friendica\Model\Storage\IStorage;
use Friendica\Model\Storage\StorageException;
use Friendica\Test\Util\VFSTrait;
use Friendica\Util\Profiler;
use Mockery\MockInterface;
use org\bovigo\vfs\vfsStream;
use Psr\Log\NullLogger;
class FilesystemStorageTest extends StorageTest
use VFSTrait;
/** @var MockInterface|IConfig */
protected $config;
protected function setUp(): void
vfsStream::create(['storage' => []], $this->root);
protected function getInstance()
$logger = new NullLogger();
$profiler = \Mockery::mock(Profiler::class);
/** @var MockInterface|L10n $l10n */
$l10n = \Mockery::mock(L10n::class)->makePartial();
$this->config = \Mockery::mock(IConfig::class);
->with('storage', 'filesystem_path', Filesystem::DEFAULT_BASE_FOLDER)
return new Filesystem($this->config, $logger, $l10n);
protected function assertOption(IStorage $storage)
'storagepath' => [
'input', 'Storage base path',
'Folder where uploaded files are saved. For maximum security, This should be a path outside web server folder tree'
], $storage->getOptions());
* Test the exception in case of missing directorsy permissions
public function testMissingDirPermissions()
$this->expectExceptionMessageMatches("/Filesystem storage failed to create \".*\". Check you write permissions./");
$instance = $this->getInstance();
* Test the exception in case of missing file permissions
public function testMissingFilePermissions()
static::markTestIncomplete("Cannot catch file_put_content() error due vfsStream failure");
$this->expectExceptionMessageMatches("/Filesystem storage failed to save data to \".*\". Check your write permissions/");
vfsStream::create(['storage' => ['f0' => ['c0' => ['k0i0' => '']]]], $this->root);
$instance = $this->getInstance();
$instance->put('test', 'f0c0k0i0');
* Test the backend storage of the Filesystem Storage class
public function testDirectoryTree()
$instance = $this->getInstance();
$instance->put('test', 'f0c0d0i0');
$dir = $this->root->getChild('storage/f0/c0')->url();
$file = $this->root->getChild('storage/f0/c0/d0i0')->url();
self::assertEquals('test', file_get_contents($file));