Testing the ability to remove files + files in subfolders

parent a5fce0e5
...@@ -206,10 +206,10 @@ class Imagy ...@@ -206,10 +206,10 @@ class Imagy
} }
$paths[] = $this->getDestinationPath($file->path->getRelativeUrl()); $paths[] = $this->getDestinationPath($file->path->getRelativeUrl());
$fileName = pathinfo($file->path, PATHINFO_FILENAME);
$extension = pathinfo($file->path, PATHINFO_EXTENSION);
foreach ($this->manager->all() as $thumbnail) { foreach ($this->manager->all() as $thumbnail) {
$path = config('asgard.media.config.files-path') . "{$fileName}_{$thumbnail->name()}.{$extension}"; $path = $this->getFilenameFor($file->path, $thumbnail);
if ($this->fileExists($this->getDestinationPath($path))) { if ($this->fileExists($this->getDestinationPath($path))) {
$paths[] = (new MediaPath($this->getDestinationPath($path)))->getRelativeUrl(); $paths[] = (new MediaPath($this->getDestinationPath($path)))->getRelativeUrl();
} }
......
...@@ -108,6 +108,36 @@ class ImagyTest extends MediaTestCase ...@@ -108,6 +108,36 @@ class ImagyTest extends MediaTestCase
$this->assertEquals($expected, $smallThumbPath); $this->assertEquals($expected, $smallThumbPath);
} }
/** @test */
public function it_can_delete_thumbnail_files()
{
$this->resetDatabase();
$file = \Illuminate\Http\UploadedFile::fake()->image('my-file.jpg');
$file = app(FileService::class)->store($file);
$this->assertCount(3, $this->app['files']->allFiles(public_path(config('asgard.media.config.files-path'))));
$this->imagy->deleteAllFor($file);
$this->assertCount(0, $this->app['files']->allFiles(public_path(config('asgard.media.config.files-path'))));
}
/** @test */
public function it_can_delete_thumbnail_files_in_subdirectory()
{
$this->resetDatabase();
app(FolderRepository::class)->create(['name' => 'My Folder', 'parent_id' => 0]);
$file = \Illuminate\Http\UploadedFile::fake()->image('my-file.jpg');
$file = app(FileService::class)->store($file, 1);
$path = public_path(config('asgard.media.config.files-path') . 'my-folder/');
$this->assertCount(3, $this->app['files']->allFiles($path));
$this->imagy->deleteAllFor($file);
$this->assertCount(0, $this->app['files']->allFiles($path));
}
/** @test */ /** @test */
public function it_should_return_same_path_for_non_images() public function it_should_return_same_path_for_non_images()
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment