oc-resizer-plugin/tests/ResizeMakeTest.php

119 lines
4.2 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-10-31 23:58:16 +01:00
public function testOnlyResizeMissingBreakpointsIfUpdateGiven()
{
Setting::set('folders', [
['folder' => '/pages'],
['folder' => 'otherdir'],
]);
Setting::set('sizes', []);
Setting::set('breakpoints', [100, 200]);
$this->media->put('pages/test.jpg', UploadedFile::fake()->image('test.jpg', 500, 500)->get());
Storage::put('uploads/public/c/pages/test-200x200.jpg', UploadedFile::fake()->image('test.jpg', 200, 200)->get());
$lastModified = Storage::lastModified('uploads/public/c/pages/test-200x200.jpg');
sleep(1);
Artisan::call('resize:make', ['-u' => true]);
$this->assertFileCount(3, 'pages');
$this->assertEquals($lastModified, Storage::lastModified('uploads/public/c/pages/test-200x200.jpg'));
}
public function testOnlyResizeMissingVersionsIfUpdateGiven()
{
Setting::set('folders', [
['folder' => '/pages'],
['folder' => 'otherdir'],
]);
Setting::set('sizes', [['name' => 'testas', 'aspect_ratio' => '1x2']]);
Setting::set('breakpoints', [100, 200]);
$this->media->put('pages/test.jpg', UploadedFile::fake()->image('test.jpg', 500, 500)->get());
Storage::put('uploads/public/c/pages/test-100x200.jpg', UploadedFile::fake()->image('test.jpg', 100, 200)->get());
$lastModified = Storage::lastModified('uploads/public/c/pages/test-100x200.jpg');
sleep(1);
Artisan::call('resize:make', ['-u' => true]);
$this->assertEquals($lastModified, Storage::lastModified('uploads/public/c/pages/test-100x200.jpg'));
}
2021-09-19 12:38:57 +02:00
}