oc-resizer-plugin/tests/DeleteTest.php

77 lines
2.6 KiB
PHP
Raw Normal View History

2021-09-06 02:31:27 +02:00
<?php
namespace Aweos\Resizer\Tests\MediaTest;
use Aweos\Resizer\Models\Setting;
use Aweos\Resizer\Tests\TestCase;
2021-09-06 14:37:35 +02:00
use Cache;
2021-09-06 02:31:27 +02:00
use Event;
use Illuminate\Http\UploadedFile;
use Storage;
class DeleteTest extends TestCase
{
public function setUp(): void
{
parent::setUp();
Storage::fake('local');
}
public function testItDeletesAllVersionsIfOriginalImageDeleted()
{
2021-09-06 15:35:45 +02:00
Cache::tags('pages/test.jpg')->set('resizer.original.pages/test.jpg', '::cacheContent::');
2021-09-06 02:31:27 +02:00
Setting::set('folders', ['pages']);
Setting::set('sizes', []);
Setting::set('breakpoints', []);
UploadedFile::fake()->image(100, 100)->storeAs('uploads/public/c/pages', 'test.jpg', 'local');
Event::fire('media.file.delete', [null, '/pages/test.jpg', null]);
$this->assertFileCount(0, 'pages');
Storage::assertMissing('uploads/public/c/pages');
2021-09-06 14:37:35 +02:00
$this->assertNull(Cache::get('resizer.original.pages/test.jpg'));
2021-09-06 02:31:27 +02:00
}
public function testItDeletesAFileThatDoesntBeginWithASlash()
{
Cache::tags('pages/test.jpg')->set('resizer.original.pages/test.jpg', '::cacheContent::');
Setting::set('folders', ['pages']);
Setting::set('sizes', []);
Setting::set('breakpoints', []);
UploadedFile::fake()->image(100, 100)->storeAs('uploads/public/c/pages', 'test.jpg', 'local');
Event::fire('media.file.delete', [null, 'pages/test.jpg', null]);
$this->assertFileCount(0, 'pages');
}
2021-09-06 02:31:27 +02:00
public function testItPreservesDirectoryWhenThereAreOtherFiles()
{
Setting::set('folders', ['pages']);
Setting::set('sizes', []);
Setting::set('breakpoints', []);
UploadedFile::fake()->image(100, 100)->storeAs('uploads/public/c/pages', 'test.jpg', 'local');
UploadedFile::fake()->image(100, 100)->storeAs('uploads/public/c/pages', 'test2.jpg', 'local');
Event::fire('media.file.delete', [null, '/pages/test.jpg', null]);
$this->assertHasFile('pages/test2.jpg');
$this->assertDoesntHaveFile('pages/test.jpg');
}
public function testItDeletesFileVersions()
{
Setting::set('folders', ['pages']);
Setting::set('sizes', []);
Setting::set('breakpoints', []);
UploadedFile::fake()->image(100, 100)->storeAs('uploads/public/c/pages', 'test.jpg', 'local');
UploadedFile::fake()->image(300, 500)->storeAs('uploads/public/c/pages', 'test-300x500.jpg', 'local');
Event::fire('media.file.delete', [null, '/pages/test.jpg', null]);
$this->assertDoesntHaveFile('pages/test-300x500.jpg');
}
}