Files
laralog/tests/Feature/AdminPagesTest.php
T
goukiandCursor 469160dc3f
Build and Deploy / verify (push) Failing after 15m17s
Build and Deploy / deploy (push) Skipped
feat: add admin env badge, quick post button, and harden plugin enable
Show local/prod in the Filament topbar, jump to create post in one click, tighten sidebar spacing, and stop Hello World from 500ing when its tables are missing.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-18 08:24:16 +00:00

107 lines
3.3 KiB
PHP

<?php
namespace Tests\Feature;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class AdminPagesTest extends TestCase
{
use RefreshDatabase;
private User $admin;
protected function setUp(): void
{
parent::setUp();
$this->seed();
$this->admin = User::query()->firstOrCreate(
['email' => 'admin@laralog.test'],
['name' => '管理员', 'password' => bcrypt('password')]
);
}
public function test_dashboard_loads(): void
{
$this->actingAs($this->admin)->get('/admin')->assertOk();
}
public function test_post_resource_loads(): void
{
$this->actingAs($this->admin)->get('/admin/posts')->assertOk();
$this->actingAs($this->admin)->get('/admin/posts/create')->assertOk();
}
public function test_settings_page_loads(): void
{
$this->actingAs($this->admin)->get('/admin/blog-settings')->assertOk();
}
public function test_comment_resource_loads(): void
{
$this->actingAs($this->admin)->get('/admin/comments')->assertOk();
}
public function test_media_resource_loads(): void
{
$this->actingAs($this->admin)->get('/admin/media')->assertOk();
}
public function test_media_library_resource_loads(): void
{
$this->actingAs($this->admin)->get('/admin/media-library')->assertOk();
$this->actingAs($this->admin)->get('/admin/media-folders')->assertOk();
$this->actingAs($this->admin)->get('/admin/posts/create')
->assertOk()
->assertSee('media:ID', false);
}
public function test_plugin_and_payment_pages_load(): void
{
$this->actingAs($this->admin)->get('/admin/plugins')->assertOk();
$this->actingAs($this->admin)->get('/admin/payments')->assertOk();
$this->actingAs($this->admin)->get('/admin/ai-settings')->assertOk();
$this->actingAs($this->admin)->get('/admin/redirects')->assertOk();
}
public function test_guest_is_redirected_to_login(): void
{
$this->get('/admin')->assertRedirect('/admin/login');
}
public function test_admin_environment_maps_production_to_prod(): void
{
$original = app()->environment();
app()['env'] = 'production';
$this->assertSame('prod', \App\Filament\Support\AdminEnvironment::name());
$this->assertSame('danger', \App\Filament\Support\AdminEnvironment::color());
app()['env'] = $original;
}
public function test_admin_topbar_shows_environment_and_create_post_button(): void
{
$this->actingAs($this->admin)
->get('/admin')
->assertOk()
->assertSee(\App\Filament\Support\AdminEnvironment::name(), false)
->assertSee('写文章', false)
->assertSee('/admin/posts/create', false);
}
public function test_hello_world_plugin_pages_load_when_enabled(): void
{
$manager = app(\App\Blog\Support\PluginManager::class);
$manager->enable('demo.hello-world');
\Plugins\Demo\HelloWorld\ServiceProvider::bootPlugin($manager);
$this->actingAs($this->admin)->get('/admin')->assertOk();
$this->actingAs($this->admin)->get('/admin/posts/create')->assertOk();
$this->get('/hello-world')->assertOk();
}
}