67 lines
2.1 KiB
PHP
67 lines
2.1 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace Aweos\Resizer\Tests;
|
||
|
|
||
|
use Artisan;
|
||
|
use Aweos\Resizer\Models\Setting;
|
||
|
use Aweos\Resizer\Tests\TestCase;
|
||
|
use Cache;
|
||
|
use Event;
|
||
|
use Illuminate\Http\UploadedFile;
|
||
|
use Storage;
|
||
|
|
||
|
class ResizeMakeTest extends TestCase
|
||
|
{
|
||
|
|
||
|
public function setUp(): void
|
||
|
{
|
||
|
parent::setUp();
|
||
|
Storage::fake('local');
|
||
|
}
|
||
|
|
||
|
public function testItCanRunResizeMakeCommandOnAllFolders()
|
||
|
{
|
||
|
Setting::set('folders', [['folder' => 'pages']]);
|
||
|
Setting::set('sizes', []);
|
||
|
Setting::set('breakpoints', []);
|
||
|
$this->media->put('pages/test.jpg', UploadedFile::fake()->image('test.jpg', 100, 100)->get());
|
||
|
|
||
|
Artisan::call('resize:make');
|
||
|
|
||
|
$this->assertFileCount(1, 'pages');
|
||
|
}
|
||
|
|
||
|
public function testItDeletesOtherFilesBeforeResizingAll()
|
||
|
{
|
||
|
Setting::set('folders', [['folder' => 'pages']]);
|
||
|
Setting::set('sizes', []);
|
||
|
Setting::set('breakpoints', []);
|
||
|
Storage::put('uploads/public/c/otherdir/test.jpg', UploadedFile::fake()->image('test.jpg', 100, 100)->get());
|
||
|
|
||
|
Artisan::call('resize:make');
|
||
|
|
||
|
$this->assertFileCount(0, 'otherdir');
|
||
|
}
|
||
|
|
||
|
public function testOnlyResizeASingleFolder()
|
||
|
{
|
||
|
Setting::set('folders', [
|
||
|
['folder' => 'pages'],
|
||
|
['folder' => 'otherdir'],
|
||
|
]);
|
||
|
Setting::set('sizes', []);
|
||
|
Setting::set('breakpoints', []);
|
||
|
$this->media->put('pages/test.jpg', UploadedFile::fake()->image('test.jpg', 100, 100)->get());
|
||
|
Storage::put('uploads/public/c/pages/test-100x100.jpg', UploadedFile::fake()->image('test.jpg', 100, 100)->get());
|
||
|
$this->media->put('otherdir/test.jpg', UploadedFile::fake()->image('test.jpg', 100, 100)->get());
|
||
|
Storage::put('uploads/public/c/otherdir/test-100x100.jpg', UploadedFile::fake()->image('test.jpg', 100, 100)->get());
|
||
|
Storage::put('uploads/public/c/otherdir/test-200x200.jpg', UploadedFile::fake()->image('test.jpg', 100, 100)->get());
|
||
|
|
||
|
Artisan::call('resize:make', ['-f' => 'pages']);
|
||
|
|
||
|
$this->assertFileCount(2, 'otherdir');
|
||
|
$this->assertFileCount(1, 'pages');
|
||
|
}
|
||
|
|
||
|
}
|