oc-resizer-plugin/tests/ResizeMakeTest.php

82 lines
2.6 KiB
PHP
Raw Normal View History

2021-09-19 12:38:57 +02:00
<?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');
}
public function testCleanSingleFolderBeforeResizing()
{
Setting::set('folders', [
['folder' => '/pages'],
['folder' => 'otherdir'],
]);
Setting::set('sizes', []);
Setting::set('breakpoints', []);
Storage::put('uploads/public/c/pages/test-100x100.jpg', UploadedFile::fake()->image('test.jpg', 100, 100)->get());
Artisan::call('resize:make', ['-f' => '/pages']);
$this->assertFileCount(0, 'pages');
}
2021-09-19 12:38:57 +02:00
}