httpStatus === $status, 'Unexpected rejection status: ' . $exception->httpStatus); return; } throw new RuntimeException('Expected rejection was accepted.'); }; $capsule = new Capsule(); $capsule->addConnection(['driver' => 'sqlite', 'database' => ':memory:'], 'default'); $capsule->setAsGlobal(); $capsule->bootEloquent(); $connection = $capsule->getConnection(); $schema = $connection->getSchemaBuilder(); $schema->create('legal_documents', static function (Blueprint $table): void { $table->bigIncrements('id'); $table->string('slug', 32); $table->string('locale', 10); $table->string('title', 120); $table->longText('draft_html'); $table->date('effective_date'); $table->unsignedInteger('draft_version')->default(0); $table->unsignedBigInteger('published_revision_id')->nullable(); $table->unsignedBigInteger('updated_by')->default(0); $table->dateTime('created_at'); $table->dateTime('updated_at'); $table->unique(['slug', 'locale']); }); $schema->create('legal_document_revisions', static function (Blueprint $table): void { $table->bigIncrements('id'); $table->unsignedBigInteger('document_id'); $table->unsignedInteger('version'); $table->string('title', 120); $table->longText('content_html'); $table->date('effective_date'); $table->dateTime('published_at'); $table->unsignedBigInteger('published_by'); $table->unique(['document_id', 'version']); }); $customer = ['user_id' => 1, 'is_admin' => false, 'is_super_admin' => false, 'can_manage' => false]; $admin = ['user_id' => 2, 'is_admin' => true, 'is_super_admin' => false, 'can_manage' => false]; $super = ['user_id' => 3, 'is_admin' => true, 'is_super_admin' => true, 'can_manage' => true]; $initial = LegalDocumentService::editorState($admin, 'terms', 'zh-CN'); $assert($initial['draft_version'] === 0 && $initial['published'] === null && str_contains($initial['content_html'], '接受与适用范围'), 'New editor did not expose safe default copy.'); $fallback = LegalDocumentService::published('terms', 'zh-CN', '测试云'); $assert($fallback['fallback'] === true && $fallback['version'] === 1 && str_contains($fallback['content_html'], '测试云') && count($fallback['outline']) >= 5, 'Public fallback or site-name substitution is incorrect.'); $englishFallback = LegalDocumentService::published('terms', 'en', '测试云'); $assert($englishFallback['fallback'] === true && str_contains($englishFallback['content_html'], '接受与适用范围') && $englishFallback['title'] === '服务条款', 'An unpublished target locale did not use the Chinese safety baseline.'); $serviceSource = file_get_contents(dirname(__DIR__) . '/app/Services/LegalDocumentService.php'); $assert(is_string($serviceSource) && !str_contains($serviceSource, 'Acceptance and scope') && !str_contains($serviceSource, 'Information we collect'), 'Legal target-language translations remain embedded in source.'); $draft = LegalDocumentService::saveDraft($super, 'terms', [ 'locale' => 'zh-CN', 'title' => '平台服务条款', 'effective_date' => '2026-11-01', 'draft_version' => '0', 'content_html' => '
使用 {{site_name}}。
' . '危险链接' . '说明', ]); $assert($draft['draft_version'] === 1 && !str_contains($draft['content_html'], '
仍可显示。
', ]); $sanitizedRead = LegalDocumentService::published('terms', 'zh-CN', '站点'); $assert(!str_contains($sanitizedRead['content_html'], '