applicant-site/tests/Feature/admin/catalog/EducationFormTest.php

124 lines
3.6 KiB
PHP

<?php
namespace Tests\Feature\admin\catalog;
use App\Models\Department;
use App\Models\Direction;
use App\Models\EducationalInstitution;
use App\Models\EducationForm;
use App\Models\EducationLevel;
use App\Models\Faculty;
use App\Models\User;
use Tests\TestCase;
class EducationFormTest extends TestCase
{
private User $user;
private Direction $direction;
private EducationForm $form;
private array $data;
protected function setUp(): void
{
parent::setUp();
EducationalInstitution::factory()->create();
Faculty::factory()->create();
Department::factory()->create();
EducationLevel::factory()->create();
$this->form = EducationForm::factory()->create();
$this->direction = Direction::factory()->create();
$this->data = EducationForm::factory()->make()->only([
'name',
'description',
'slug',
]);
$this->user = User::factory()->create([
'name' => 'admin',
'email' => 'test@example.com',
'password' => 123456
]);
}
public function testIndexEducationFormsPage(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->get(route('education_forms.index'));
$response->assertOk();
}
public function testCreateEducationFormPage(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->get(route('education_forms.create'));
$response->assertOk();
}
public function testStoreEducationForm(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->post(route('education_forms.store', $this->data));
$response->assertRedirect(route('education_forms.index'));
$this->assertDatabaseHas('education_forms', $this->data);
}
public function testShowEducationFormPage(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->get(route('education_forms.show', $this->form));
$response->assertOk();
}
public function testEditEducationFormPage(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->get(route('education_forms.edit', $this->form));
$response->assertOk();
}
public function testUpdateEducationForm(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->patch(route('education_forms.update', $this->form), $this->data);
$response->assertRedirect(route('education_forms.index'));
$this->assertDatabaseHas('education_forms', $this->data);
}
public function testDestroyEducationForm(): void
{
$this->direction->delete();
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->delete(route('education_forms.destroy', $this->form));
$response->assertRedirect(route('education_forms.index'));
$this->assertDatabaseMissing('education_forms', $this->form->toArray());
}
public function testNotDestroyEducationForm(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->delete(route('education_forms.destroy', $this->form));
$response->assertStatus(302);
$this->assertDatabaseHas('education_forms', $this->form->only(['name', 'slug']));
}
}