- redirects 表 + UrlRedirector:go_url() 站外链接改写为 /go/{hash}(确定性 hash、同 URL 复用、并发安全、缓存)
- /go/{hash} 302 跳转 + 点击计数 + 最后点击时间;停用状态 410(二次拦截);后台「外链中转」资源可查看点击量/启停/删除
- 接入点:正文外链(渲染器统一改写)、评论正文自动链接(comment_body)、评论作者网址、友链(侧边栏+友链页);站内/相对/mailto/tel/锚点不中转
- 测试 6 个(改写/计数/拦截/复用/渲染/评论正文);README 补充
66 lines
1.7 KiB
PHP
66 lines
1.7 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_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');
|
|
}
|
|
}
|