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

118 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\Place;
use App\Models\PlaceType;
use App\Models\User;
use Tests\TestCase;
class CostTest extends TestCase
{
private User $user;
private Cost $cost;
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->cost = Cost::factory()->create();
$this->data = Cost::factory()->make()->only([
'position',
'description',
'cost',
'education_form_id',
'direction_id',
]);
$this->user = User::factory()->create([
'name' => 'admin',
'email' => 'test@example.com',
'password' => 123456
]);
}
public function testIndexCostsPage(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->get(route('costs.index'));
$response->assertOk();
}
public function testCreateCostPage(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->get(route('costs.create'));
$response->assertOk();
}
public function testStoreCost(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->post(route('costs.store', $this->data));
$response->assertRedirect(route('costs.index'));
$this->assertDatabaseHas('costs', $this->data);
}
public function testShowCost(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->get(route('costs.show', $this->cost));
$response->assertOk();
}
public function testEditCostPage(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->get(route('costs.edit', $this->cost));
$response->assertOk();
}
public function testUpdateCost(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->patch(route('costs.update', $this->cost), $this->data);
$response->assertRedirect(route('costs.index'));
$this->assertDatabaseHas('costs', $this->data);
}
public function testDestroyCost(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->delete(route('costs.destroy', $this->cost));
$response->assertRedirect(route('costs.index'));
$this->assertDatabaseMissing('costs', $this->cost->toArray());
}
}