Files
laralog/tests/Feature/HomeViewModeTest.php
T
goukiandCursor ae47447062
Build and Deploy / verify (push) Successful in 40s
Build and Deploy / deploy (push) Successful in 36s
feat: restore sablog browse modes and clean imported HTML
Keep the public site readable after import (nbsp, highlighter, wrapping code, compact pager) and finish the admin extras already in this tree: sticky levels, preview, page cache, and live llms.txt.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-18 21:33:02 +00:00

79 lines
2.3 KiB
PHP

<?php
namespace Tests\Feature;
use App\Models\Category;
use App\Models\Post;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class HomeViewModeTest extends TestCase
{
use RefreshDatabase;
private Post $post;
protected function setUp(): void
{
parent::setUp();
$this->seed();
$user = User::create(['name' => '作者', 'email' => 'view@test.com', 'password' => bcrypt('x')]);
$category = Category::create(['name' => '技术', 'slug' => 'tech-view']);
$this->post = Post::create([
'user_id' => $user->id,
'category_id' => $category->id,
'title' => '浏览模式测试文',
'slug' => 'view-mode-test',
'excerpt' => '列表摘要文字',
'content' => '这是完整正文内容 FULL_BODY_ONLY_TOKEN',
'content_format' => 'markdown',
'status' => 'published',
'published_at' => now(),
]);
}
public function test_list_mode_shows_excerpt_not_full_body(): void
{
$this->get('/?view=list')
->assertOk()
->assertSee('浏览模式', false)
->assertSee('列表摘要文字', false)
->assertDontSee('FULL_BODY_ONLY_TOKEN', false);
}
public function test_full_mode_shows_article_body(): void
{
$this->get('/?view=full')
->assertOk()
->assertSee('浏览模式', false)
->assertSee('FULL_BODY_ONLY_TOKEN', false);
}
public function test_compact_pagination_shows_page_info(): void
{
$userId = $this->post->user_id;
$categoryId = $this->post->category_id;
for ($index = 1; $index <= 12; $index++) {
Post::create([
'user_id' => $userId,
'category_id' => $categoryId,
'title' => '分页文章 '.$index,
'slug' => 'pager-'.$index,
'content' => '正文 '.$index,
'content_format' => 'markdown',
'status' => 'published',
'published_at' => now()->subMinutes($index),
]);
}
$this->get('/')
->assertOk()
->assertSee('第 1 /', false)
->assertSee('页', false);
}
}