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

113 lines
3.1 KiB
PHP

<?php
namespace Tests\Feature\admin\catalog;
use App\Models\Department;
use App\Models\Direction;
use App\Models\EducationalInstitution;
use App\Models\EducationLevel;
use App\Models\Faculty;
use App\Models\User;
use Tests\TestCase;
class DepartmentTest extends TestCase
{
private User $user;
private Department $department;
private array $data;
protected function setUp(): void
{
parent::setUp();
EducationalInstitution::factory()->create();
Faculty::factory()->create();
EducationLevel::factory()->create();
$this->department = Department::factory()->create();
$this->data = Department::factory()->make()->only([
'position',
'name',
'description',
'slug',
'faculty_id',
]);
$this->direction = Direction::factory()->create();
$this->user = User::factory()->create([
'name' => 'admin',
'email' => 'test@example.com',
'password' => 123456
]);
}
public function testIndexDepartmentsPage(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->get(route('departments.index'));
$response->assertOk();
}
public function testCreateDepartmentPage(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->get(route('departments.create'));
$response->assertOk();
}
public function testStoreDepartment(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->post(route('departments.store', $this->data));
$response->assertRedirect(route('departments.index'));
$this->assertDatabaseHas('departments', $this->data);
}
public function testShowDepartmentPage(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->get(route('departments.show', $this->department));
$response->assertOk();
}
public function testEditDepartmentPage(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->get(route('departments.edit', $this->department));
$response->assertOk();
}
public function testUpdateDepartment(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->patch(route('departments.update', $this->department), $this->data);
$response->assertRedirect(route('departments.index'));
$this->assertDatabaseHas('departments', $this->data);
}
public function testDestroyDepartment(): void
{
$this->direction->delete();
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->delete(route('departments.destroy', $this->department));
$response->assertRedirect(route('departments.index'));
$this->assertDatabaseMissing('departments', $this->department->toArray());
}
}