jonnybarnes.uk/tests/Feature/FrontPageTest.php
Jonny Barnes a31c218784
Hide draft articles from the front page and mark drafts when viewed directly
Add an Article::published() scope and use it on the front page (which
previously showed drafts), the /blog listing and the feeds. Draft
articles are still reachable at their URL, but now show a draft notice,
a "[Draft]" title prefix and a noindex robots meta tag.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-26 16:20:50 +01:00

45 lines
1.2 KiB
PHP

<?php
namespace Tests\Feature;
use App\Models\Article;
use App\Models\Bookmark;
use App\Models\Like;
use App\Models\Note;
use Illuminate\Foundation\Testing\RefreshDatabase;
use PHPUnit\Framework\Attributes\Test;
use Tests\TestCase;
class FrontPageTest extends TestCase
{
use RefreshDatabase;
#[Test]
public function front_page_loads_all_content(): void
{
Note::factory()->create(['note' => 'Note 1']);
Article::factory()->create(['title' => 'Article 1']);
Bookmark::factory()->create(['url' => 'https://example.com']);
Like::factory()->create([
'url' => 'https://example.org/1',
'content' => 'Like 1',
]);
$this->get('/')
->assertSee('Note 1')
->assertSee('Article 1')
->assertSee('https://example.com')
->assertSee('Like 1');
}
#[Test]
public function front_page_does_not_show_draft_articles(): void
{
Article::factory()->create(['title' => 'Published Article']);
Article::factory()->create(['title' => 'Draft Article', 'published' => 0]);
$this->get('/')
->assertSee('Published Article')
->assertDontSee('Draft Article');
}
}