- Added standard Laravel directory structure and configuration. - Included Svelte and Tailwind configuration for the admin interface. - Added core PHPUnit and testing scripts.
63 lines
1.6 KiB
PHP
63 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Admin;
|
|
|
|
use App\Models\Media;
|
|
use App\Models\User;
|
|
use App\Models\Role;
|
|
use App\Models\Permission;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Illuminate\Http\UploadedFile;
|
|
|
|
class MediaApiTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
Storage::fake('public');
|
|
}
|
|
|
|
public function test_admin_can_fetch_media_list()
|
|
{
|
|
// Create admin user
|
|
$adminRole = Role::create(['name' => 'Admin', 'slug' => 'admin']);
|
|
$admin = User::factory()->create();
|
|
$admin->roles()->attach($adminRole);
|
|
|
|
// Create some media
|
|
Media::create([
|
|
'filename' => 'test.jpg',
|
|
'path' => 'media/test.jpg',
|
|
'mime_type' => 'image/jpeg',
|
|
'size' => 1024,
|
|
]);
|
|
|
|
$response = $this->actingAs($admin)
|
|
->getJson(route('admin.media.index'));
|
|
|
|
$response->assertStatus(200);
|
|
$response->assertJsonCount(1, 'media');
|
|
$response->assertJsonPath('media.0.filename', 'test.jpg');
|
|
}
|
|
|
|
public function test_media_jit_route_works()
|
|
{
|
|
// Create some media
|
|
Media::create([
|
|
'filename' => 'test.jpg',
|
|
'path' => 'media/test.jpg',
|
|
'mime_type' => 'image/jpeg',
|
|
'size' => 1024,
|
|
]);
|
|
Storage::disk('public')->put('media/test.jpg', 'fake content');
|
|
|
|
$response = $this->get('/media/test.jpg?w=100');
|
|
|
|
$response->assertStatus(200);
|
|
}
|
|
}
|