Roman_applicant-site/tests/Feature/admin/AdmissionTest.php

102 lines
2.7 KiB
PHP
Raw Permalink Normal View History

<?php
namespace Tests\Feature\admin;
use App\Models\Admission;
use App\Models\User;
use Tests\TestCase;
class AdmissionTest extends TestCase
{
private User $user;
private array $data;
private Admission $admission;
protected function setUp(): void
{
parent::setUp();
$this->admission = Admission::factory()->create();
$this->data = Admission::factory()->make()->only([
'position',
'name',
'description',
'slug',
]);
$this->user = User::factory()->create([
'name' => 'admin',
'email' => 'test@example.com',
'password' => 123456
]);
}
public function testIndexAdmissionsPage(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->get(route('admissions.index'));
$response->assertOk();
}
public function testCreateAdmissionPage(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->get(route('admissions.create'));
$response->assertOk();
}
public function testStoreAdmission(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->post(route('admissions.store', $this->data));
$response->assertRedirect(route('admissions.index'));
$this->assertDatabaseHas('admissions', $this->data);
}
public function testShowAdmissionPage(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->get(route('admissions.show', $this->admission));
$response->assertOk();
}
public function testEditAdmissionPage(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->get(route('admissions.edit', $this->admission));
$response->assertOk();
}
public function testUpdateAdmission(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->patch(route('admissions.update', $this->admission), $this->data);
$response->assertRedirect(route('admissions.index'));
$this->assertDatabaseHas('admissions', $this->data);
}
public function testDestroyFaculty(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->delete(route('admissions.destroy', $this->admission));
$response->assertRedirect(route('admissions.index'));
$this->assertDatabaseMissing('faculties', $this->admission->toArray());
}
}