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

105 lines
2.9 KiB
PHP
Raw Normal View History

2024-02-12 10:27:08 +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 DepartmentTest extends TestCase
{
private User $user;
private Department $department;
private array $data;
protected function setUp(): void
{
parent::setUp();
EducationalInstitution::factory()->create();
Faculty::factory()->create();
$this->department = Department::factory()->create();
$this->data = Department::factory()->make()->only([
'position',
'name',
'description',
'slug',
'faculty_id',
]);
$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
{
$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());
}
}