news = News::factory()->create(); $this->data = News::factory()->make()->only([ 'name', 'text', ]); $this->user = User::factory()->create([ 'name' => 'admin', 'email' => 'test@example.com', 'password' => 123456 ]); } public function testIndexNewsPage(): void { $response = $this->actingAs($this->user) ->withSession(['banned' => false]) ->get(route('news.index')); $response->assertOk(); } public function testCreateNewsPage(): void { $response = $this->actingAs($this->user) ->withSession(['banned' => false]) ->get(route('news.create')); $response->assertOk(); } public function testStoreNews(): void { $file = UploadedFile::fake()->create('fake.jpg', 100); $response = $this->actingAs($this->user) ->withSession(['banned' => false]) ->post(route('news.store'), [...$this->data, 'photo' => $file]); $response->assertRedirect(route('news.index')); $this->assertDatabaseHas('news', $this->data); } public function testShowNewsPage(): void { $response = $this->actingAs($this->user) ->withSession(['banned' => false]) ->get(route('news.show', $this->news)); $response->assertOk(); } public function testEditNewsPage(): void { $response = $this->actingAs($this->user) ->withSession(['banned' => false]) ->get(route('news.edit', $this->news)); $response->assertOk(); } public function testUpdateNews(): void { $file = UploadedFile::fake()->create('fake.jpg', 100); $response = $this->actingAs($this->user) ->withSession(['banned' => false]) ->patch(route('news.update', $this->news), [...$this->data, 'photo' => $file]); $response->assertRedirect(route('news.index')); $this->assertDatabaseHas('news', $this->data); } public function testDestroyNews(): void { $response = $this->actingAs($this->user) ->withSession(['banned' => false]) ->delete(route('news.destroy', $this->news)); $response->assertRedirect(route('news.index')); $this->assertDatabaseMissing('news', $this->news->toArray()); } }