|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Tests\Feature; |
| 4 | + |
| 5 | +use App\Models\Article; |
| 6 | +use Illuminate\Foundation\Testing\RefreshDatabase; |
| 7 | +use PHPUnit\Framework\Attributes\Test; |
| 8 | +use Tests\TestCase; |
| 9 | + |
| 10 | +class BlogTest extends TestCase |
| 11 | +{ |
| 12 | + use RefreshDatabase; |
| 13 | + |
| 14 | + #[Test] |
| 15 | + public function published_articles_are_shown_on_the_blog_listing() |
| 16 | + { |
| 17 | + $article = Article::factory()->published()->create(); |
| 18 | + |
| 19 | + $this->get(route('blog')) |
| 20 | + ->assertOk() |
| 21 | + ->assertSee($article->title) |
| 22 | + ->assertSee(route('article', $article)); |
| 23 | + } |
| 24 | + |
| 25 | + #[Test] |
| 26 | + public function published_articles_are_shown_in_antichronological_order() |
| 27 | + { |
| 28 | + [$article1, $article2, $article3] = [ |
| 29 | + Article::factory()->create([ |
| 30 | + 'published_at' => now()->subDays(2), |
| 31 | + ]), |
| 32 | + Article::factory()->create([ |
| 33 | + 'published_at' => now()->subDays(1), |
| 34 | + ]), |
| 35 | + Article::factory()->create([ |
| 36 | + 'published_at' => now()->subDays(3), |
| 37 | + ]), |
| 38 | + ]; |
| 39 | + |
| 40 | + $this->get(route('blog')) |
| 41 | + ->assertOk() |
| 42 | + ->assertSeeInOrder([ |
| 43 | + $article2->title, |
| 44 | + $article1->title, |
| 45 | + $article3->title, |
| 46 | + ]); |
| 47 | + } |
| 48 | + |
| 49 | + #[Test] |
| 50 | + public function scheduled_articles_are_not_shown_on_the_blog_listing() |
| 51 | + { |
| 52 | + $article = Article::factory()->scheduled()->create(); |
| 53 | + |
| 54 | + $this->get(route('blog')) |
| 55 | + ->assertOk() |
| 56 | + ->assertDontSee($article->title) |
| 57 | + ->assertDontSee(route('article', $article)); |
| 58 | + } |
| 59 | + |
| 60 | + #[Test] |
| 61 | + public function published_articles_are_visitable() |
| 62 | + { |
| 63 | + $article = Article::factory()->published()->create(); |
| 64 | + |
| 65 | + $this->get(route('article', $article)) |
| 66 | + ->assertOk(); |
| 67 | + } |
| 68 | + |
| 69 | + #[Test] |
| 70 | + public function scheduled_articles_return_a_404() |
| 71 | + { |
| 72 | + $article = Article::factory()->scheduled()->create(); |
| 73 | + |
| 74 | + $this->get(route('article', $article)) |
| 75 | + ->assertStatus(404); |
| 76 | + } |
| 77 | +} |
0 commit comments