- Added standard Laravel directory structure and configuration. - Included Svelte and Tailwind configuration for the admin interface. - Added core PHPUnit and testing scripts.
60 lines
1.7 KiB
PHP
60 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use Tests\TestCase;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Illuminate\Support\Facades\File;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
class MediaJitTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
// Ensure the source directory exists
|
|
if (! File::exists(storage_path('app/public/media'))) {
|
|
File::makeDirectory(storage_path('app/public/media'), 0755, true);
|
|
}
|
|
|
|
// Create a dummy image for testing
|
|
// A simple 1x1 black png
|
|
$imageContent = base64_decode('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=');
|
|
File::put(storage_path('app/public/media/test.png'), $imageContent);
|
|
}
|
|
|
|
protected function tearDown(): void
|
|
{
|
|
File::delete(storage_path('app/public/media/test.png'));
|
|
File::deleteDirectory(storage_path('app/public/media/cache'));
|
|
parent::tearDown();
|
|
}
|
|
|
|
public function test_it_serves_jit_images(): void
|
|
{
|
|
$response = $this->get('/media/test.png?w=10&h=10');
|
|
|
|
$response->assertStatus(200);
|
|
$this->assertEquals('image/png', $response->headers->get('Content-Type'));
|
|
}
|
|
|
|
public function test_it_handles_conversions(): void
|
|
{
|
|
$response = $this->get('/media/test.png?fm=webp');
|
|
|
|
$response->assertStatus(200);
|
|
$this->assertEquals('image/webp', $response->headers->get('Content-Type'));
|
|
}
|
|
|
|
public function test_sw_file_routes_to_media_jit(): void
|
|
{
|
|
$html = sw_file('media/test.png', ['w' => 100]);
|
|
|
|
$this->assertStringContainsString('/media/test.png', $html);
|
|
$this->assertStringContainsString('w=100', $html);
|
|
}
|
|
}
|