mirror of
https://github.com/friendica/friendica
synced 2025-04-25 11:10:11 +00:00
Split Storage usage and Storage configuration
This commit is contained in:
parent
ac9e5df614
commit
065b46c721
12 changed files with 379 additions and 208 deletions
|
@ -23,11 +23,9 @@ namespace Friendica\Test\src\Model\Storage;
|
|||
|
||||
use Friendica\Factory\ConfigFactory;
|
||||
use Friendica\Model\Storage\Database;
|
||||
use Friendica\Model\Storage\IWritableStorage;
|
||||
use Friendica\Test\DatabaseTestTrait;
|
||||
use Friendica\Test\Util\Database\StaticDatabase;
|
||||
use Friendica\Test\Util\VFSTrait;
|
||||
use Friendica\Util\ConfigFileLoader;
|
||||
use Friendica\Util\Profiler;
|
||||
use Psr\Log\NullLogger;
|
||||
|
||||
|
@ -47,7 +45,7 @@ class DatabaseStorageTest extends StorageTest
|
|||
|
||||
protected function getInstance()
|
||||
{
|
||||
$logger = new NullLogger();
|
||||
$logger = new NullLogger();
|
||||
$profiler = \Mockery::mock(Profiler::class);
|
||||
$profiler->shouldReceive('startRecording');
|
||||
$profiler->shouldReceive('stopRecording');
|
||||
|
@ -55,19 +53,14 @@ class DatabaseStorageTest extends StorageTest
|
|||
|
||||
// load real config to avoid mocking every config-entry which is related to the Database class
|
||||
$configFactory = new ConfigFactory();
|
||||
$loader = (new ConfigFactory())->createConfigFileLoader($this->root->url(), []);
|
||||
$configCache = $configFactory->createCache($loader);
|
||||
$loader = (new ConfigFactory())->createConfigFileLoader($this->root->url(), []);
|
||||
$configCache = $configFactory->createCache($loader);
|
||||
|
||||
$dba = new StaticDatabase($configCache, $profiler, $logger);
|
||||
|
||||
return new Database($dba);
|
||||
}
|
||||
|
||||
protected function assertOption(IWritableStorage $storage)
|
||||
{
|
||||
self::assertEmpty($storage->getOptions());
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->tearDownDb();
|
||||
|
|
67
tests/src/Model/Storage/FilesystemStorageConfigTest.php
Normal file
67
tests/src/Model/Storage/FilesystemStorageConfigTest.php
Normal file
|
@ -0,0 +1,67 @@
|
|||
<?php
|
||||
/**
|
||||
* @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
|
||||
* 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\src\Model\Storage;
|
||||
|
||||
use Friendica\Core\Config\IConfig;
|
||||
use Friendica\Core\L10n;
|
||||
use Friendica\Model\Storage\FilesystemConfig;
|
||||
use Friendica\Model\Storage\IStorageConfiguration;
|
||||
use Friendica\Test\Util\VFSTrait;
|
||||
use Mockery\MockInterface;
|
||||
use org\bovigo\vfs\vfsStream;
|
||||
|
||||
class FilesystemStorageConfigTest extends StorageConfigTest
|
||||
{
|
||||
use VFSTrait;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->setUpVfsDir();
|
||||
|
||||
vfsStream::create(['storage' => []], $this->root);
|
||||
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
protected function getInstance()
|
||||
{
|
||||
/** @var MockInterface|L10n $l10n */
|
||||
$l10n = \Mockery::mock(L10n::class)->makePartial();
|
||||
$config = \Mockery::mock(IConfig::class);
|
||||
$config->shouldReceive('get')
|
||||
->with('storage', 'filesystem_path', FilesystemConfig::DEFAULT_BASE_FOLDER)
|
||||
->andReturn($this->root->getChild('storage')->url());
|
||||
|
||||
return new FilesystemConfig($config, $l10n);
|
||||
}
|
||||
|
||||
protected function assertOption(IStorageConfiguration $storage)
|
||||
{
|
||||
self::assertEquals([
|
||||
'storagepath' => [
|
||||
'input', 'Storage base path',
|
||||
$this->root->getChild('storage')->url(),
|
||||
'Folder where uploaded files are saved. For maximum security, This should be a path outside web server folder tree'
|
||||
]
|
||||
], $storage->getOptions());
|
||||
}
|
||||
}
|
|
@ -21,23 +21,15 @@
|
|||
|
||||
namespace Friendica\Test\src\Model\Storage;
|
||||
|
||||
use Friendica\Core\Config\IConfig;
|
||||
use Friendica\Core\L10n;
|
||||
use Friendica\Model\Storage\Filesystem;
|
||||
use Friendica\Model\Storage\IWritableStorage;
|
||||
use Friendica\Model\Storage\StorageException;
|
||||
use Friendica\Test\Util\VFSTrait;
|
||||
use Friendica\Util\Profiler;
|
||||
use Mockery\MockInterface;
|
||||
use org\bovigo\vfs\vfsStream;
|
||||
|
||||
class FilesystemStorageTest extends StorageTest
|
||||
{
|
||||
use VFSTrait;
|
||||
|
||||
/** @var MockInterface|IConfig */
|
||||
protected $config;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->setUpVfsDir();
|
||||
|
@ -49,30 +41,7 @@ class FilesystemStorageTest extends StorageTest
|
|||
|
||||
protected function getInstance()
|
||||
{
|
||||
$profiler = \Mockery::mock(Profiler::class);
|
||||
$profiler->shouldReceive('startRecording');
|
||||
$profiler->shouldReceive('stopRecording');
|
||||
$profiler->shouldReceive('saveTimestamp')->withAnyArgs()->andReturn(true);
|
||||
|
||||
/** @var MockInterface|L10n $l10n */
|
||||
$l10n = \Mockery::mock(L10n::class)->makePartial();
|
||||
$this->config = \Mockery::mock(IConfig::class);
|
||||
$this->config->shouldReceive('get')
|
||||
->with('storage', 'filesystem_path', Filesystem::DEFAULT_BASE_FOLDER)
|
||||
->andReturn($this->root->getChild('storage')->url());
|
||||
|
||||
return new Filesystem($this->config, $l10n);
|
||||
}
|
||||
|
||||
protected function assertOption(IWritableStorage $storage)
|
||||
{
|
||||
self::assertEquals([
|
||||
'storagepath' => [
|
||||
'input', 'Storage base path',
|
||||
$this->root->getChild('storage')->url(),
|
||||
'Folder where uploaded files are saved. For maximum security, This should be a path outside web server folder tree'
|
||||
]
|
||||
], $storage->getOptions());
|
||||
return new Filesystem($this->root->getChild('storage')->url());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -116,7 +85,7 @@ class FilesystemStorageTest extends StorageTest
|
|||
|
||||
$instance->put('test', 'f0c0d0i0');
|
||||
|
||||
$dir = $this->root->getChild('storage/f0/c0')->url();
|
||||
$dir = $this->root->getChild('storage/f0/c0')->url();
|
||||
$file = $this->root->getChild('storage/f0/c0/d0i0')->url();
|
||||
|
||||
self::assertDirectoryExists($dir);
|
||||
|
|
43
tests/src/Model/Storage/StorageConfigTest.php
Normal file
43
tests/src/Model/Storage/StorageConfigTest.php
Normal file
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
/**
|
||||
* @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
|
||||
* 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\src\Model\Storage;
|
||||
|
||||
use Friendica\Model\Storage\IStorageConfiguration;
|
||||
use Friendica\Test\MockedTest;
|
||||
|
||||
abstract class StorageConfigTest extends MockedTest
|
||||
{
|
||||
/** @return IStorageConfiguration */
|
||||
abstract protected function getInstance();
|
||||
|
||||
abstract protected function assertOption(IStorageConfiguration $storage);
|
||||
|
||||
/**
|
||||
* Test if the "getOption" is asserted
|
||||
*/
|
||||
public function testGetOptions()
|
||||
{
|
||||
$instance = $this->getInstance();
|
||||
|
||||
$this->assertOption($instance);
|
||||
}
|
||||
}
|
|
@ -31,8 +31,6 @@ abstract class StorageTest extends MockedTest
|
|||
/** @return IWritableStorage */
|
||||
abstract protected function getInstance();
|
||||
|
||||
abstract protected function assertOption(IWritableStorage $storage);
|
||||
|
||||
/**
|
||||
* Test if the instance is "really" implementing the interface
|
||||
*/
|
||||
|
@ -42,16 +40,6 @@ abstract class StorageTest extends MockedTest
|
|||
self::assertInstanceOf(IStorage::class, $instance);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the "getOption" is asserted
|
||||
*/
|
||||
public function testGetOptions()
|
||||
{
|
||||
$instance = $this->getInstance();
|
||||
|
||||
$this->assertOption($instance);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test basic put, get and delete operations
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue