docs: 开发规范/教程/demo 全套 + 修复插件运行期自动加载缺口

- demo 插件 plugins/demo.hello-world:演示短代码过滤器、comment.created 钩子、路由+命名空间视图、迁移+模型、后台设置页、filament.post_form 表单注入
- demo 主题 themes/demo:最小可运行主题(覆盖 partials + 绿色系样式)
- 教程 docs/tutorial-plugin.md / docs/tutorial-theme.md(10 分钟上手);规范 docs/development.md(代码/插件/主题/队列/测试/提交)
- README 增加开发者文档导航与上手示例
- 修复关键缺口:插件类原来靠 composer.json 硬编码加载,第三方 ZIP 安装的插件无法加载;现改为启动时扫描 plugins/*/src 运行期注册 PSR-4(register 阶段,保证 Filament 面板解析插件页面前就绪),composer.json 移除硬编码
- 测试:demo 插件 3 个用例 + demo 主题渲染;全量 89 通过
This commit is contained in:
ak
2026-08-12 17:26:34 +08:00
parent 7364def979
commit 8fdf8dbb4b
21 changed files with 840 additions and 11 deletions
+70
View File
@@ -0,0 +1,70 @@
<?php
declare(strict_types=1);
namespace Tests\Feature;
use App\Blog\Support\PluginManager;
use App\Models\Comment;
use App\Models\Post;
use App\Models\Setting;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Plugins\Demo\HelloWorld\ServiceProvider;
use Tests\TestCase;
class DemoPluginTest extends TestCase
{
use RefreshDatabase;
protected function setUp(): void
{
parent::setUp();
// demo 插件默认未启用(不在 config/plugins.php enabled),测试中手动 boot 验证其代码
ServiceProvider::bootPlugin(app(PluginManager::class));
}
private function makePost(): Post
{
return Post::create([
'title' => '演示',
'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 演示页');
}
}