* feat(home): alinhar cadência editorial * test(home): ajustar contrato do hero dividido
87 lines
2.7 KiB
PHP
87 lines
2.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Models\Service;
|
|
use App\Models\SiteSetting;
|
|
use App\Support\ResponsiveImage;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\Artisan;
|
|
use Illuminate\Support\Facades\Cache;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Intervention\Image\Drivers\Gd\Driver;
|
|
use Intervention\Image\ImageManager;
|
|
use Tests\TestCase;
|
|
|
|
class MediaGenerateVariantsCommandTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_command_backfills_variants_for_existing_images(): void
|
|
{
|
|
Storage::fake('public');
|
|
|
|
$manager = new ImageManager(new Driver);
|
|
$path = 'content/services/backfill.jpg';
|
|
Storage::disk('public')->put($path, (string) $manager->create(1400, 900)->toJpeg());
|
|
|
|
Service::factory()->published()->create([
|
|
'cover_image_path' => $path,
|
|
]);
|
|
|
|
$exitCode = Artisan::call('media:generate-variants');
|
|
|
|
$this->assertSame(0, $exitCode);
|
|
|
|
foreach (ResponsiveImage::WIDTHS as $width) {
|
|
Storage::disk('public')->assertExists(ResponsiveImage::variantPath($path, $width));
|
|
}
|
|
}
|
|
|
|
public function test_command_invalidates_metadata_for_a_missing_original(): void
|
|
{
|
|
config(['cache.default' => 'array']);
|
|
Cache::store('array')->flush();
|
|
Storage::fake('public');
|
|
|
|
$manager = new ImageManager(new Driver);
|
|
$path = 'content/services/missing.jpg';
|
|
Storage::disk('public')->put($path, (string) $manager->create(1400, 900)->toJpeg());
|
|
ResponsiveImage::generate($path, 'public');
|
|
ResponsiveImage::metadata($path, 'public');
|
|
Storage::disk('public')->delete($path);
|
|
|
|
Service::factory()->published()->create([
|
|
'cover_image_path' => $path,
|
|
]);
|
|
|
|
$exitCode = Artisan::call('media:generate-variants');
|
|
|
|
$this->assertSame(0, $exitCode);
|
|
$this->assertNull(ResponsiveImage::metadata($path, 'public'));
|
|
}
|
|
|
|
public function test_command_backfills_variants_for_the_home_hero_image(): void
|
|
{
|
|
Storage::fake('public');
|
|
|
|
$manager = new ImageManager(new Driver);
|
|
$path = 'content/home/hero.jpg';
|
|
Storage::disk('public')->put($path, (string) $manager->create(1600, 1000)->toJpeg());
|
|
|
|
SiteSetting::instance()->update([
|
|
'hero_image_path' => $path,
|
|
'hero_image_alt' => 'Celebração ao ar livre',
|
|
]);
|
|
|
|
$exitCode = Artisan::call('media:generate-variants');
|
|
|
|
$this->assertSame(0, $exitCode);
|
|
foreach (ResponsiveImage::WIDTHS as $width) {
|
|
Storage::disk('public')->assertExists(ResponsiveImage::variantPath($path, $width));
|
|
}
|
|
}
|
|
}
|