subject = Subject::factory()->create(); $this->data = Subject::factory()->make()->only([ 'name', 'description', 'position', 'slug', ]); $this->user = User::factory()->create([ 'name' => 'admin', 'email' => 'test@example.com', 'password' => 123456 ]); } public function testIndexSubjectsPage(): void { $response = $this->actingAs($this->user) ->withSession(['banned' => false]) ->get(route('subjects.index')); $response->assertOk(); } public function testCreateSubjectPage(): void { $response = $this->actingAs($this->user) ->withSession(['banned' => false]) ->get(route('subjects.create')); $response->assertOk(); } public function testStoreSubject(): void { $response = $this->actingAs($this->user) ->withSession(['banned' => false]) ->post(route('subjects.store', $this->data)); $response->assertRedirect(route('subjects.index')); $this->assertDatabaseHas('subjects', $this->data); } public function testShowSubjectPage(): void { $response = $this->actingAs($this->user) ->withSession(['banned' => false]) ->get(route('subjects.show', $this->subject)); $response->assertOk(); } public function testEditSubjectPage(): void { $response = $this->actingAs($this->user) ->withSession(['banned' => false]) ->get(route('subjects.edit', $this->subject)); $response->assertOk(); } public function testUpdateSubject(): void { $response = $this->actingAs($this->user) ->withSession(['banned' => false]) ->patch(route('subjects.update', $this->subject), $this->data); $response->assertRedirect(route('subjects.index')); $this->assertDatabaseHas('subjects', $this->data); } public function testDestroySubject(): void { $response = $this->actingAs($this->user) ->withSession(['banned' => false]) ->delete(route('subjects.destroy', $this->subject)); $response->assertRedirect(route('subjects.index')); $this->assertDatabaseMissing('subjects', $this->subject->toArray()); } }