Let admin and editor open /admin in a new tab from the public header and profile, so they can jump to the backend without leaving the site. Co-authored-by: Cursor <cursoragent@cursor.com>
100 lines
3.0 KiB
PHP
100 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
class AuthFlowTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
$this->seed();
|
|
}
|
|
|
|
public function test_login_form_posts_to_shtml(): void
|
|
{
|
|
$this->post('/login.shtml', [
|
|
'email' => 'admin@laralog.test',
|
|
'password' => 'password',
|
|
])->assertRedirect('/');
|
|
|
|
$this->assertAuthenticated();
|
|
}
|
|
|
|
public function test_register_form_posts_to_shtml(): void
|
|
{
|
|
$this->post('/register.shtml', [
|
|
'name' => '新用户',
|
|
'email' => 'new@test.com',
|
|
'password' => 'password123',
|
|
'password_confirmation' => 'password123',
|
|
])->assertRedirect('/profile.shtml');
|
|
|
|
$this->assertAuthenticated();
|
|
$this->assertDatabaseHas('users', ['email' => 'new@test.com']);
|
|
}
|
|
|
|
public function test_logout_form_posts_to_shtml(): void
|
|
{
|
|
$user = User::where('email', 'admin@laralog.test')->first();
|
|
$this->actingAs($user)->post('/logout.shtml')->assertRedirect('/');
|
|
|
|
$this->assertGuest();
|
|
}
|
|
|
|
public function test_admin_sees_backend_link_in_new_tab(): void
|
|
{
|
|
$admin = User::where('email', 'admin@laralog.test')->first();
|
|
|
|
$this->actingAs($admin)->get('/')
|
|
->assertOk()
|
|
->assertSee('管理', false)
|
|
->assertSee('target="_blank"', false)
|
|
->assertSee('/admin', false);
|
|
|
|
$this->actingAs($admin)->get('/profile.shtml')
|
|
->assertOk()
|
|
->assertSee('进入后台管理', false);
|
|
}
|
|
|
|
public function test_member_and_guest_do_not_see_backend_link(): void
|
|
{
|
|
$this->get('/')->assertOk()->assertDontSee('>管理</a>', false);
|
|
|
|
$member = User::create(['name' => '会员', 'email' => 'member@test.com', 'password' => bcrypt('x')]);
|
|
$member->assignRole('member');
|
|
|
|
$this->actingAs($member)->get('/')
|
|
->assertOk()
|
|
->assertDontSee('>管理</a>', false);
|
|
}
|
|
|
|
public function test_front_pages_use_shtml_links(): void
|
|
{
|
|
$user = User::create(['name' => '作者', 'email' => 'w@t.com', 'password' => bcrypt('x')]);
|
|
\App\Models\Post::create([
|
|
'user_id' => $user->id,
|
|
'title' => '链接测试',
|
|
'slug' => 'link-test',
|
|
'content' => '内容',
|
|
'content_format' => 'markdown',
|
|
'status' => 'published',
|
|
'published_at' => now(),
|
|
]);
|
|
|
|
$html = $this->get('/')->getContent();
|
|
|
|
// 前台链接应生成 .shtml(不含硬编码无后缀路径)
|
|
$this->assertStringContainsString('/posts/link-test.shtml', $html);
|
|
$this->assertStringNotContainsString('href="/posts/link-test"', $html);
|
|
$this->assertStringNotContainsString('href="/archives"', $html);
|
|
$this->assertStringContainsString('href="http://laralog.test/archives.shtml"', $html);
|
|
}
|
|
}
|