'演示', 'slug' => 'demo-'.uniqid(), 'content' => '内容', 'content_format' => 'markdown', 'status' => 'published', 'published_at' => now(), ]); } public function test_hello_shortcode_filter_renders_greeting(): void { Setting::set('hello_world_greeting', '嗨'); $html = app(PluginManager::class)->applyFilters('post.rendered', '正文 [hello 世界]', $this->makePost()); $this->assertStringContainsString('嗨,世界!', $html); $this->assertStringNotContainsString('[hello', $html); } public function test_comment_created_action_writes_log(): void { $post = $this->makePost(); $comment = Comment::create([ 'post_id' => $post->id, 'author_name' => '游客', 'content' => '演示评论内容', 'status' => 'pending', ]); app(PluginManager::class)->doAction('comment.created', $comment); $this->assertDatabaseHas('hello_world_logs', ['comment_id' => $comment->id]); } public function test_hello_world_route_renders_plugin_view(): void { $this->get('/hello-world') ->assertOk() ->assertSee('Hello World 演示页'); } public function test_hello_world_page_survives_missing_log_table(): void { \Illuminate\Support\Facades\Schema::dropIfExists('hello_world_logs'); $this->get('/hello-world')->assertOk()->assertSee('Hello World 演示页'); } public function test_enable_hello_world_runs_plugin_migrations(): void { \Illuminate\Support\Facades\Schema::dropIfExists('hello_world_logs'); \Illuminate\Support\Facades\DB::table('migrations') ->where('migration', 'like', '%hello_world_logs%') ->delete(); app(PluginManager::class)->enable('demo.hello-world'); $this->assertTrue(\Illuminate\Support\Facades\Schema::hasTable('hello_world_logs')); $this->assertTrue(app(PluginManager::class)->isEnabled('demo.hello-world')); } }