You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.5 KiB
50 lines
1.5 KiB
|
3 months ago
|
<?php
|
||
|
|
|
||
|
|
namespace Tests\Feature;
|
||
|
|
|
||
|
|
use App\Models\Application;
|
||
|
|
use App\Models\ApplicationFile;
|
||
|
|
use App\Models\Competition;
|
||
|
|
use App\Models\User;
|
||
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||
|
|
use Illuminate\Support\Facades\Storage;
|
||
|
|
use Tests\TestCase;
|
||
|
|
|
||
|
|
class ParticipantApplicationFileDownloadTest extends TestCase
|
||
|
|
{
|
||
|
|
use RefreshDatabase;
|
||
|
|
|
||
|
|
public function test_signed_download_resolves_file_model_and_streams_content(): void
|
||
|
|
{
|
||
|
|
Storage::fake('public');
|
||
|
|
Storage::disk('public')->put('applications/1/plan.pdf', 'pdf-bytes');
|
||
|
|
|
||
|
|
$user = User::query()->create(['mobile' => '13800138099']);
|
||
|
|
$competition = Competition::query()->create([
|
||
|
|
'slug' => 'xxf',
|
||
|
|
'name' => '测试赛',
|
||
|
|
'published' => true,
|
||
|
|
]);
|
||
|
|
$application = Application::query()->create([
|
||
|
|
'user_id' => $user->id,
|
||
|
|
'competition_id' => $competition->id,
|
||
|
|
'status' => 'draft',
|
||
|
|
]);
|
||
|
|
$file = ApplicationFile::query()->create([
|
||
|
|
'application_id' => $application->id,
|
||
|
|
'kind' => 'plan',
|
||
|
|
'disk' => 'public',
|
||
|
|
'path' => 'applications/1/plan.pdf',
|
||
|
|
'original_name' => '商业计划书.pdf',
|
||
|
|
'size' => 8,
|
||
|
|
'mime' => 'application/pdf',
|
||
|
|
]);
|
||
|
|
|
||
|
|
$url = $file->participantPreviewSignedUrl();
|
||
|
|
|
||
|
|
$this->get($url)
|
||
|
|
->assertOk()
|
||
|
|
->assertHeader('content-type', 'application/pdf');
|
||
|
|
}
|
||
|
|
}
|