1
0
mirror of https://github.com/flarum/core.git synced 2025-07-30 21:20:24 +02:00

Use Laravel filesystem interface for assets and avatars (#2729)

* WIP: Use Laravel filesystem interface where possible
* Drop vendorFilesystem
* Support getting URL of cloud-based logo and favicon
* FilesystemAdapter should always be cloud
* Get base avatar URL from filesystem adapter
* Restore deleted getAsset method

Co-authored-by: Alexander Skvortsov <askvortsov1@users.noreply.github.com>
This commit is contained in:
Alexander Skvortsov
2021-04-19 15:11:03 -04:00
committed by GitHub
parent 9a3f579cbb
commit 3e173afa24
13 changed files with 82 additions and 92 deletions

View File

@@ -13,15 +13,17 @@ use Flarum\Testing\unit\TestCase;
use Flarum\User\AvatarUploader;
use Flarum\User\User;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Contracts\Filesystem\Factory;
use Illuminate\Contracts\Filesystem\Filesystem;
use Illuminate\Database\Eloquent\Model;
use Intervention\Image\ImageManagerStatic;
use League\Flysystem\FilesystemInterface;
use Mockery as m;
class AvatarUploaderTest extends TestCase
{
private $dispatcher;
private $filesystem;
private $filesystemFactory;
private $uploader;
/**
@@ -33,13 +35,15 @@ class AvatarUploaderTest extends TestCase
$this->dispatcher->shouldIgnoreMissing();
Model::setEventDispatcher($this->dispatcher);
$this->filesystem = m::mock(FilesystemInterface::class);
$this->uploader = new AvatarUploader($this->filesystem);
$this->filesystem = m::mock(Filesystem::class);
$this->filesystemFactory = m::mock(Factory::class);
$this->filesystemFactory->shouldReceive('disk')->with('flarum-avatars')->andReturn($this->filesystem);
$this->uploader = new AvatarUploader($this->filesystemFactory);
}
public function test_removing_avatar_removes_file()
{
$this->filesystem->shouldReceive('has')->with('ABCDEFGHabcdefgh.png')->andReturn(true);
$this->filesystem->shouldReceive('exists')->with('ABCDEFGHabcdefgh.png')->andReturn(true);
$this->filesystem->shouldReceive('delete')->with('ABCDEFGHabcdefgh.png')->once();
$user = new User();
@@ -61,7 +65,7 @@ class AvatarUploaderTest extends TestCase
public function test_removing_url_avatar_removes_no_file()
{
$this->filesystem->shouldReceive('has')->with('https://example.com/avatar.png')->andReturn(false)->once();
$this->filesystem->shouldReceive('exists')->with('https://example.com/avatar.png')->andReturn(false)->once();
$this->filesystem->shouldNotReceive('delete');
$user = new User();
@@ -82,7 +86,7 @@ class AvatarUploaderTest extends TestCase
public function test_changing_avatar_removes_file()
{
$this->filesystem->shouldReceive('put')->once();
$this->filesystem->shouldReceive('has')->with('ABCDEFGHabcdefgh.png')->andReturn(true);
$this->filesystem->shouldReceive('exists')->with('ABCDEFGHabcdefgh.png')->andReturn(true);
$this->filesystem->shouldReceive('delete')->with('ABCDEFGHabcdefgh.png')->once();
$user = new User();