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

115 lines
3.2 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\Direction;
2024-02-12 10:27:08 +03:00
use App\Models\EducationalInstitution;
2024-02-15 09:58:01 +03:00
use App\Models\EducationForm;
2024-02-14 16:16:44 +03:00
use App\Models\EducationLevel;
2024-02-12 10:27:08 +03:00
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();
2024-02-14 16:16:44 +03:00
EducationLevel::factory()->create();
2024-02-15 09:58:01 +03:00
EducationForm::factory()->create();
2024-02-12 10:27:08 +03:00
$this->department = Department::factory()->create();
$this->data = Department::factory()->make()->only([
'position',
'name',
'description',
'slug',
'faculty_id',
]);
$this->direction = Direction::factory()->create();
2024-02-12 10:27:08 +03:00
$this->user = User::factory()->create([
'name' => 'admin',
'email' => 'test@example.com',
'password' => 123456
]);
}
2024-02-12 10:27:08 +03:00
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();
2024-02-12 10:27:08 +03:00
$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());
}
}