oc-resizer-plugin/tests/DeleteTest.php

61 lines
1.9 KiB
PHP

<?php
namespace Aweos\Resizer\Tests\MediaTest;
use Aweos\Resizer\Models\Setting;
use Aweos\Resizer\Tests\TestCase;
use Event;
use Illuminate\Http\UploadedFile;
use Storage;
class DeleteTest extends TestCase
{
public function setUp(): void
{
parent::setUp();
Storage::fake('local');
}
public function testItDeletesAllVersionsIfOriginalImageDeleted()
{
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');
}
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');
}
}