Roman_applicant-site/tests/Feature/admin/catalog/DirectionTest.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 DirectionTest extends TestCase
{
private User $user;
private Direction $direction;
private array $data;
protected function setUp(): void
{
parent::setUp();
EducationalInstitution::factory()->create();
Faculty::factory()->create();
Department::factory()->create();
EducationLevel::factory()->create();
$this->direction = Direction::factory()->create();
$this->data = Direction::factory()->make()->only([
'position',
'name',
'description',
'code',
'slug',
'education_level_id',
'department_id',
]);
$this->user = User::factory()->create([
'name' => 'admin',
'email' => 'test@example.com',
'password' => 123456
]);
}
public function testIndexDirectionsPage(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->get(route('directions.index'));
$response->assertOk();
}
public function testCreateDirectionPage(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->get(route('directions.create'));
$response->assertOk();
}
public function testStoreDirection(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->post(route('directions.store', $this->data));
$response->assertRedirect(route('directions.index'));
$this->assertDatabaseHas('directions', $this->data);
}
public function testShowDirectionPage(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->get(route('directions.show', $this->direction));
$response->assertOk();
}
public function testEditDirectionPage(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->get(route('directions.edit', $this->direction));
$response->assertOk();
}
public function testUpdateDirection(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->patch(route('directions.update', $this->direction), $this->data);
$response->assertRedirect(route('directions.index'));
$this->assertDatabaseHas('directions', $this->data);
}
public function testDestroyDirection(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->delete(route('directions.destroy', $this->direction));
$response->assertRedirect(route('directions.index'));
$this->assertDatabaseMissing('directions', $this->direction->toArray());
}
}