Roman_applicant-site/tests/Feature/admin/catalog/direction/PeriodTest.php

117 lines
3.1 KiB
PHP

<?php
namespace Tests\Feature\admin\catalog\direction;
use App\Models\Cost;
use App\Models\Department;
use App\Models\Direction;
use App\Models\EducationalInstitution;
use App\Models\EducationForm;
use App\Models\EducationLevel;
use App\Models\Faculty;
use App\Models\Period;
use App\Models\User;
use Tests\TestCase;
class PeriodTest extends TestCase
{
private User $user;
private Period $period;
private array $data;
protected function setUp(): void
{
parent::setUp();
EducationalInstitution::factory()->create();
Faculty::factory()->create();
Department::factory()->create();
EducationLevel::factory()->create();
EducationForm::factory()->create();
Direction::factory()->create();
$this->period = Period::factory()->create();
$this->data = Period::factory()->make()->only([
'position',
'description',
'period',
'education_form_id',
'direction_id',
]);
$this->user = User::factory()->create([
'name' => 'admin',
'email' => 'test@example.com',
'password' => 123456
]);
}
public function testIndexPeriodsPage(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->get(route('periods.index'));
$response->assertOk();
}
public function testCreatePeriodPage(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->get(route('periods.create'));
$response->assertOk();
}
public function testStorePeriod(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->post(route('periods.store', $this->data));
$response->assertRedirect(route('periods.index'));
$this->assertDatabaseHas('periods', $this->data);
}
public function testShowPeriod(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->get(route('periods.show', $this->period));
$response->assertOk();
}
public function testEditPeriodPage(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->get(route('periods.edit', $this->period));
$response->assertOk();
}
public function testUpdatePeriod(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->patch(route('periods.update', $this->period), $this->data);
$response->assertRedirect(route('periods.index'));
$this->assertDatabaseHas('periods', $this->data);
}
public function testDestroyPeriod(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->delete(route('periods.destroy', $this->period));
$response->assertRedirect(route('periods.index'));
$this->assertDatabaseMissing('periods', $this->period->toArray());
}
}