user = User::factory()->create(['status' => 'active']);
Permission::firstOrCreate(['name' => 'documents.access', 'guard_name' => 'web']);
$this->user->givePermissionTo('documents.access');
$this->category = DocumentCategory::create(['name' => 'Test Documents']);
}
public function test_pdf_upload_is_stored_and_available_as_inline_preview(): void
{
$document = $this->upload('plan.pdf', 'application/pdf');
$response = $this->actingAs($this->user)->get(route('documents.preview', $document));
$response->assertOk();
$response->assertHeader('Content-Type', 'application/pdf');
$response->assertHeader('Content-Disposition', 'inline; filename="plan.pdf"');
Storage::disk('local')->assertExists($document->current_file_path);
}
public function test_image_upload_is_stored_and_available_as_inline_preview(): void
{
$file = UploadedFile::fake()->image('site-photo.jpg', 640, 480);
$document = $this->uploadFile($file);
$response = $this->actingAs($this->user)->get(route('documents.preview', $document));
$response->assertOk();
$response->assertHeader('Content-Type', 'image/jpeg');
$response->assertHeader('Content-Disposition', 'inline; filename="site-photo.jpg"');
Storage::disk('local')->assertExists($document->current_file_path);
}
public function test_docx_upload_is_stored_and_downloadable(): void
{
$document = $this->upload(
'specification.docx',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
);
$this->actingAs($this->user)
->get(route('documents.download', $document))
->assertOk()
->assertHeader('Content-Disposition', 'attachment; filename=specification.docx');
Storage::disk('local')->assertExists($document->current_file_path);
}
public function test_valid_docx_is_rendered_as_html_preview(): void
{
$path = tempnam(sys_get_temp_dir(), 'document-preview-');
$archive = new \ZipArchive();
$archive->open($path, \ZipArchive::CREATE);
$archive->addFromString('word/document.xml', '