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>
111 lines
3.4 KiB
PHP
111 lines
3.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Blog\Support\PageCacheMiddleware;
|
|
use App\Blog\Support\ThemeManager;
|
|
use App\Models\Category;
|
|
use App\Models\Post;
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
class LlmsFeedTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
private User $author;
|
|
|
|
private Category $category;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
$this->seed();
|
|
|
|
$this->author = User::query()->where('email', 'admin@laralog.test')->firstOrFail();
|
|
$this->category = Category::create([
|
|
'name' => '索引',
|
|
'slug' => 'llms-cat',
|
|
]);
|
|
}
|
|
|
|
public function test_llms_txt_lists_new_published_posts_and_skips_drafts(): void
|
|
{
|
|
$published = $this->makePost('给 Agent 看的新文章', 'agent-new-post', 'published');
|
|
$this->makePost('还没发布', 'agent-draft', 'draft');
|
|
|
|
$this->get('/llms.txt')
|
|
->assertOk()
|
|
->assertHeader('Content-Type', 'text/plain; charset=utf-8')
|
|
->assertSee('给 Agent 看的新文章', false)
|
|
->assertSee('/posts/agent-new-post.md', false)
|
|
->assertSee($published->url, false)
|
|
->assertDontSee('还没发布', false);
|
|
}
|
|
|
|
public function test_markdown_export_is_live_and_hides_restricted_posts(): void
|
|
{
|
|
$this->makePost('Markdown 导出', 'md-export', 'published', '这里是正文。');
|
|
|
|
$this->get('/posts/md-export.md')
|
|
->assertOk()
|
|
->assertHeader('Content-Type', 'text/markdown; charset=utf-8')
|
|
->assertSee('# Markdown 导出', false)
|
|
->assertSee('这里是正文。', false);
|
|
|
|
$this->makePost('会员专享', 'members-only-md', 'published', '秘密', [
|
|
'members_only' => true,
|
|
]);
|
|
|
|
$this->get('/posts/members-only-md.md')->assertNotFound();
|
|
$this->get('/llms.txt')->assertDontSee('会员专享', false);
|
|
}
|
|
|
|
public function test_llms_and_feeds_are_not_page_cached(): void
|
|
{
|
|
$this->makePost('缓存外的文章', 'no-cache-llms', 'published');
|
|
PageCacheMiddleware::flush();
|
|
|
|
$this->get('/llms.txt')->assertOk();
|
|
$this->get('/rss.xml')->assertOk();
|
|
$this->get('/posts/no-cache-llms.md')->assertOk();
|
|
|
|
$this->assertSame(0, PageCacheMiddleware::count());
|
|
}
|
|
|
|
public function test_frontend_feed_links_open_in_a_new_tab(): void
|
|
{
|
|
app(ThemeManager::class)->activate('sablog');
|
|
|
|
$this->get('/')
|
|
->assertOk()
|
|
->assertSee('target="_blank"', false)
|
|
->assertSee('rel="noopener noreferrer"', false)
|
|
->assertSee(route('feed.rss'), false)
|
|
->assertSee(route('feed.sitemap'), false)
|
|
->assertSee(route('feed.llms'), false);
|
|
}
|
|
|
|
/**
|
|
* @param array<string, mixed> $meta
|
|
*/
|
|
private function makePost(string $title, string $slug, string $status, string $content = '内容', array $meta = []): Post
|
|
{
|
|
return Post::create([
|
|
'user_id' => $this->author->id,
|
|
'category_id' => $this->category->id,
|
|
'title' => $title,
|
|
'slug' => $slug,
|
|
'content' => $content,
|
|
'content_format' => 'markdown',
|
|
'status' => $status,
|
|
'meta' => $meta,
|
|
'published_at' => $status === 'published' ? now() : null,
|
|
]);
|
|
}
|
|
}
|