oc-resizer-plugin/tests/MoveTest.php

70 lines
2.6 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 MoveTest extends TestCase
{
public function setUp(): void
{
parent::setUp();
Storage::fake('local');
}
public function testItMovesAllVersionsOfAFile()
{
Setting::set('folders', ['pages']);
Setting::set('sizes', []);
Setting::set('breakpoints', []);
$this->media->put('/pages/alt/test.jpg', UploadedFile::fake()->image(100, 100)->get());
UploadedFile::fake()->image(100, 100)->storeAs('uploads/public/c/pages/alt', 'test.jpg', 'local');
UploadedFile::fake()->image(100, 100)->storeAs('uploads/public/c/pages/alt', 'test-200x300.jpg', 'local');
Event::fire('media.file.move', [null, '/pages/alt/test.jpg', '/pages/neu/test.jpg']);
$this->assertFileCount(0, 'pages/alt');
$this->assertHasFile('pages/neu/test.jpg');
$this->assertHasFile('pages/neu/test-200x300.jpg');
}
public function testItMovesFilesOnRename()
{
Setting::set('folders', ['pages']);
Setting::set('sizes', []);
Setting::set('breakpoints', []);
$this->media->put('/pages/test.jpg', UploadedFile::fake()->image(100, 100)->get());
UploadedFile::fake()->image(100, 100)->storeAs('uploads/public/c/pages', 'test.jpg', 'local');
UploadedFile::fake()->image(100, 100)->storeAs('uploads/public/c/pages', 'test-200x300.jpg', 'local');
Event::fire('media.file.rename', [null, '/pages/test.jpg', '/pages/testneu.jpg']);
$this->assertFileCount(2, 'pages');
$this->assertHasFile('pages/testneu.jpg');
$this->assertHasFile('pages/testneu-200x300.jpg');
}
public function testItDoesntMoveOtherFilesInTheSameDirectory()
{
Setting::set('folders', ['pages']);
Setting::set('sizes', []);
Setting::set('breakpoints', []);
$this->media->put('/pages/test.jpg', UploadedFile::fake()->image(100, 100)->get());
UploadedFile::fake()->image(100, 100)->storeAs('uploads/public/c/pages', 'test.jpg', 'local');
UploadedFile::fake()->image(100, 100)->storeAs('uploads/public/c/pages', 'test-200x300.jpg', 'local');
UploadedFile::fake()->image(100, 100)->storeAs('uploads/public/c/pages', 'testother.jpg', 'local');
Event::fire('media.file.rename', [null, '/pages/test.jpg', '/pages/testneu.jpg']);
$this->assertFileCount(3, 'pages');
$this->assertHasFile('pages/testneu.jpg');
$this->assertHasFile('pages/testneu-200x300.jpg');
}
}