Filament comments package with: - Polymorphic commenting on any Eloquent model - Threaded replies with configurable depth - @mentions with autocomplete and user search - Emoji reactions with toggle and who-reacted tooltips - File attachments via Livewire uploads - Reply and mention notifications via Filament notification system - Thread subscriptions for notification control - Real-time broadcasting (opt-in Echo) with polling fallback - Dark mode support - CommentsAction, CommentsTableAction, CommentsEntry for Filament integration - 204 tests, 421 assertions
134 lines
4.5 KiB
PHP
134 lines
4.5 KiB
PHP
<?php
|
|
|
|
namespace Relaticle\Comments\Tests;
|
|
|
|
use Filament\FilamentServiceProvider;
|
|
use Filament\Support\SupportServiceProvider;
|
|
use Illuminate\Database\Schema\Blueprint;
|
|
use Illuminate\Support\Facades\Schema;
|
|
use Livewire\LivewireServiceProvider;
|
|
use Livewire\Mechanisms\DataStore;
|
|
use Orchestra\Testbench\TestCase as Orchestra;
|
|
use Relaticle\Comments\CommentsServiceProvider;
|
|
use Relaticle\Comments\Tests\Models\User;
|
|
|
|
abstract class TestCase extends Orchestra
|
|
{
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
$this->app->singleton(DataStore::class);
|
|
}
|
|
|
|
/** @return array<int, class-string> */
|
|
protected function getPackageProviders($app): array
|
|
{
|
|
return [
|
|
LivewireServiceProvider::class,
|
|
SupportServiceProvider::class,
|
|
FilamentServiceProvider::class,
|
|
CommentsServiceProvider::class,
|
|
];
|
|
}
|
|
|
|
protected function defineDatabaseMigrations(): void
|
|
{
|
|
Schema::create('users', function (Blueprint $table) {
|
|
$table->id();
|
|
$table->string('name');
|
|
$table->string('email');
|
|
$table->string('password');
|
|
$table->timestamps();
|
|
});
|
|
|
|
Schema::create('posts', function (Blueprint $table) {
|
|
$table->id();
|
|
$table->string('title');
|
|
$table->timestamps();
|
|
});
|
|
|
|
Schema::create(config('comments.tables.comments', 'comments'), function (Blueprint $table) {
|
|
$table->id();
|
|
$table->morphs('commentable');
|
|
$table->morphs('user');
|
|
$table->foreignId('parent_id')
|
|
->nullable()
|
|
->constrained(config('comments.tables.comments', 'comments'))
|
|
->cascadeOnDelete();
|
|
$table->text('body');
|
|
$table->timestamp('edited_at')->nullable();
|
|
$table->softDeletes();
|
|
$table->timestamps();
|
|
|
|
$table->index(['commentable_type', 'commentable_id', 'parent_id']);
|
|
});
|
|
|
|
Schema::create('comment_mentions', function (Blueprint $table) {
|
|
$table->id();
|
|
$table->foreignId('comment_id')
|
|
->constrained(config('comments.tables.comments', 'comments'))
|
|
->cascadeOnDelete();
|
|
$table->morphs('user');
|
|
$table->timestamps();
|
|
|
|
$table->unique(['comment_id', 'user_id', 'user_type']);
|
|
});
|
|
|
|
Schema::create('comment_reactions', function (Blueprint $table) {
|
|
$table->id();
|
|
$table->foreignId('comment_id')
|
|
->constrained(config('comments.tables.comments', 'comments'))
|
|
->cascadeOnDelete();
|
|
$table->morphs('user');
|
|
$table->string('reaction');
|
|
$table->timestamps();
|
|
|
|
$table->unique(['comment_id', 'user_id', 'user_type', 'reaction']);
|
|
});
|
|
|
|
Schema::create('comment_attachments', function (Blueprint $table) {
|
|
$table->id();
|
|
$table->foreignId('comment_id')
|
|
->constrained(config('comments.tables.comments', 'comments'))
|
|
->cascadeOnDelete();
|
|
$table->string('file_path');
|
|
$table->string('original_name');
|
|
$table->string('mime_type');
|
|
$table->unsignedBigInteger('size');
|
|
$table->string('disk');
|
|
$table->timestamps();
|
|
});
|
|
|
|
Schema::create('notifications', function (Blueprint $table) {
|
|
$table->uuid('id')->primary();
|
|
$table->string('type');
|
|
$table->morphs('notifiable');
|
|
$table->text('data');
|
|
$table->timestamp('read_at')->nullable();
|
|
$table->timestamps();
|
|
});
|
|
|
|
Schema::create('comment_subscriptions', function (Blueprint $table) {
|
|
$table->id();
|
|
$table->morphs('commentable');
|
|
$table->morphs('user');
|
|
$table->timestamp('created_at')->nullable();
|
|
|
|
$table->unique(['commentable_type', 'commentable_id', 'user_type', 'user_id'], 'comment_subscriptions_unique');
|
|
});
|
|
}
|
|
|
|
protected function getEnvironmentSetUp($app): void
|
|
{
|
|
$app['config']->set('app.key', 'base64:'.base64_encode(random_bytes(32)));
|
|
$app['config']->set('database.default', 'testing');
|
|
$app['config']->set('database.connections.testing', [
|
|
'driver' => 'sqlite',
|
|
'database' => ':memory:',
|
|
'prefix' => '',
|
|
]);
|
|
$app['config']->set('comments.commenter.model', User::class);
|
|
}
|
|
}
|