oc-resizer-plugin/tests/MoveTest.php

84 lines
3.3 KiB
PHP
Raw Normal View History

2021-09-06 02:31:27 +02:00
<?php
2021-09-19 12:38:57 +02:00
namespace Aweos\Resizer\Tests;
2021-09-06 02:31:27 +02:00
use Aweos\Resizer\Models\Setting;
use Aweos\Resizer\Tests\TestCase;
2021-09-06 17:22:57 +02:00
use Cache;
2021-09-06 02:31:27 +02:00
use Event;
use Illuminate\Http\UploadedFile;
use Storage;
class MoveTest extends TestCase
{
public function setUp(): void
{
parent::setUp();
Storage::fake('local');
}
public function testItMovesAllVersionsOfAFile()
{
2021-09-06 17:22:57 +02:00
Cache::tags(['resizer', 'resizer.pages/alt/test.jpg'])->set('resizer.original.pages/alt/test.jpg', 'aa');
2021-09-06 02:31:27 +02:00
Setting::set('folders', ['pages']);
Setting::set('sizes', []);
Setting::set('breakpoints', []);
2021-09-17 17:09:17 +02:00
$this->media->put('/pages/alt/test.jpg', UploadedFile::fake()->image('test.jpg', 100, 100)->get());
UploadedFile::fake()->image('test.jpg', 100, 100)->storeAs('uploads/public/c/pages/alt', 'test-200x300.jpg', 'local');
2021-09-06 02:31:27 +02:00
Event::fire('media.file.move', [null, '/pages/alt/test.jpg', '/pages/neu/test.jpg']);
$this->assertFileCount(0, 'pages/alt');
$this->assertHasFile('pages/neu/test-200x300.jpg');
2021-09-06 17:22:57 +02:00
$this->assertNull(Cache::tags(['resizer', 'resizer.pages/alt/test.jpg'])->get('resizer.original.pages/alt/test.jpg'));
2021-09-06 02:31:27 +02:00
}
public function testItMovesFilesOnRename()
{
Setting::set('folders', ['pages']);
Setting::set('sizes', []);
Setting::set('breakpoints', []);
2021-09-17 17:09:17 +02:00
$this->media->put('/pages/test.jpg', UploadedFile::fake()->image('test.jpg', 100, 100)->get());
2021-09-06 02:31:27 +02:00
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']);
2021-09-17 17:09:17 +02:00
$this->assertFileCount(1, 'pages');
2021-09-06 02:31:27 +02:00
$this->assertHasFile('pages/testneu-200x300.jpg');
}
2021-09-17 17:11:50 +02:00
public function testRenamePdfHeaderFile()
{
Setting::set('folders', ['pages']);
Setting::set('sizes', []);
Setting::set('breakpoints', []);
$this->media->put('/pages/test.pdf', file_get_contents(__DIR__.'/stub/dummy.pdf'));
UploadedFile::fake()->image(100, 100)->storeAs('uploads/public/c/pages', 'test-200x300.pdf.jpg', 'local');
Event::fire('media.file.rename', [null, '/pages/test.pdf', '/pages/testneu.pdf']);
$this->assertFileCount(1, 'pages');
$this->assertHasFile('pages/testneu-200x300.pdf.jpg');
}
2021-09-06 02:31:27 +02:00
public function testItDoesntMoveOtherFilesInTheSameDirectory()
{
2021-09-06 17:22:57 +02:00
Cache::tags(['resizer', 'resizer.pages/test.jpg'])->set('resizer.original.pages/test.jpg', 'aa');
2021-09-06 02:31:27 +02:00
Setting::set('folders', ['pages']);
Setting::set('sizes', []);
Setting::set('breakpoints', []);
2021-09-17 17:09:17 +02:00
$this->media->put('/pages/test.jpg', UploadedFile::fake()->image('test.jpg', 100, 100)->get());
UploadedFile::fake()->image('test.jpg', 100, 100)->storeAs('uploads/public/c/pages', 'test-200x300.jpg', 'local');
UploadedFile::fake()->image('test.jpg', 100, 100)->storeAs('uploads/public/c/pages', 'testother-200x300.jpg', 'local');
2021-09-06 02:31:27 +02:00
Event::fire('media.file.rename', [null, '/pages/test.jpg', '/pages/testneu.jpg']);
2021-09-17 17:09:17 +02:00
$this->assertFileCount(2, 'pages');
$this->assertHasFile('pages/testother-200x300.jpg');
2021-09-06 02:31:27 +02:00
$this->assertHasFile('pages/testneu-200x300.jpg');
2021-09-06 17:22:57 +02:00
$this->assertNull(Cache::tags(['resizer', 'resizer.pages/test.jpg'])->get('resizer.original.pages/test.jpg'));
2021-09-06 02:31:27 +02:00
}
}