- 实现基于 Laravel 11 和 Filament 3.X 的文档管理系统 - 添加用户认证和分组管理功能 - 实现文档上传、分类和权限控制 - 集成 Word 文档自动转换为 Markdown - 集成 Meilisearch 全文搜索引擎 - 实现文档在线预览功能 - 添加安全日志和审计功能 - 完整的简体中文界面 - 包含完整的项目文档和部署指南 技术栈: - Laravel 11.x - Filament 3.X - Meilisearch 1.5+ - Pandoc 文档转换 - Redis 队列系统 - Pest PHP 测试框架
71 lines
2.0 KiB
PHP
71 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Models\Document;
|
|
use App\Models\Group;
|
|
use App\Models\User;
|
|
use App\Services\DocumentPreviewService;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Http\UploadedFile;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Tests\TestCase;
|
|
|
|
class DocumentPreviewServiceTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
protected DocumentPreviewService $previewService;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
$this->previewService = new DocumentPreviewService();
|
|
Storage::fake('local');
|
|
}
|
|
|
|
public function test_可以检查文档是否支持预览(): void
|
|
{
|
|
$user = User::factory()->create();
|
|
|
|
// 创建一个 .docx 文档
|
|
$document = Document::factory()->create([
|
|
'file_name' => 'test.docx',
|
|
'uploaded_by' => $user->id,
|
|
]);
|
|
|
|
$this->assertTrue($this->previewService->canPreview($document));
|
|
|
|
// 创建一个 .doc 文档
|
|
$document2 = Document::factory()->create([
|
|
'file_name' => 'test.doc',
|
|
'uploaded_by' => $user->id,
|
|
]);
|
|
|
|
$this->assertTrue($this->previewService->canPreview($document2));
|
|
|
|
// 创建一个不支持的格式
|
|
$document3 = Document::factory()->create([
|
|
'file_name' => 'test.pdf',
|
|
'uploaded_by' => $user->id,
|
|
]);
|
|
|
|
$this->assertFalse($this->previewService->canPreview($document3));
|
|
}
|
|
|
|
public function test_文档不存在时抛出异常(): void
|
|
{
|
|
$user = User::factory()->create();
|
|
$document = Document::factory()->create([
|
|
'file_path' => 'documents/2024/01/01/nonexistent.docx',
|
|
'file_name' => 'nonexistent.docx',
|
|
'uploaded_by' => $user->id,
|
|
]);
|
|
|
|
$this->expectException(\Exception::class);
|
|
$this->expectExceptionMessage('文档文件不存在');
|
|
|
|
$this->previewService->convertToHtml($document);
|
|
}
|
|
}
|