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

110 lines
2.9 KiB
PHP
Raw Permalink Normal View History

2024-02-12 12:15:46 +03:00
<?php
namespace Tests\Feature\admin\catalog;
use App\Models\Department;
use App\Models\EducationalInstitution;
use App\Models\Faculty;
use App\Models\User;
use Tests\TestCase;
class FacultyTest extends TestCase
{
private User $user;
private Faculty $faculty;
private Department $department;
2024-02-12 12:15:46 +03:00
private array $data;
protected function setUp(): void
{
parent::setUp();
EducationalInstitution::factory()->create();
$this->faculty = Faculty::factory()->create();
$this->data = Faculty::factory()->make()->only([
'position',
'name',
'description',
'slug',
'educational_institution_id',
]);
$this->department = Department::factory()->create();
$this->user = User::factory()->create([
'name' => 'admin',
'email' => 'test@example.com',
'password' => 123456
]);
}
public function testIndexFacultiesPage(): void
2024-02-12 12:15:46 +03:00
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->get(route('faculties.index'));
$response->assertOk();
}
public function testCreateFacultyPage(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->get(route('faculties.create'));
$response->assertOk();
}
public function testStoreFaculty(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->post(route('faculties.store', $this->data));
$response->assertRedirect(route('faculties.index'));
$this->assertDatabaseHas('faculties', $this->data);
}
public function testShowFacultyPage(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->get(route('faculties.show', $this->faculty));
$response->assertOk();
}
public function testEditFacultyPage(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->get(route('faculties.edit', $this->faculty));
$response->assertOk();
}
public function testUpdateFaculty(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->patch(route('faculties.update', $this->faculty), $this->data);
$response->assertRedirect(route('faculties.index'));
$this->assertDatabaseHas('faculties', $this->data);
}
public function testDestroyFaculty(): void
{
$this->department->delete();
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->delete(route('faculties.destroy', $this->faculty));
$response->assertRedirect(route('faculties.index'));
$this->assertDatabaseMissing('faculties', $this->faculty->toArray());
}
}