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_rejected_by_pdf_only_policy(): void
{
$file = UploadedFile::fake()->create('site-photo.jpg', 100, 'image/jpeg');
$response = $this->actingAs($this->user)
->from(route('documents.index'))
->post(route('documents.upload'), [
'title' => 'Site Photo',
'category_id' => $this->category->id,
'description' => 'Media preview test file',
'file' => $file,
]);
$response->assertSessionHasErrors(['file']);
}
public function test_docx_upload_is_rejected_by_pdf_only_policy(): void
{
$file = UploadedFile::fake()->create('specification.docx', 10, 'application/vnd.openxmlformats-officedocument.wordprocessingml.document');
$response = $this->actingAs($this->user)
->from(route('documents.index'))
->post(route('documents.upload'), [
'title' => 'Specification',
'category_id' => $this->category->id,
'description' => 'Media preview test file',
'file' => $file,
]);
$response->assertSessionHasErrors(['file']);
}
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', '