157 lines
4.4 KiB
PHP
157 lines
4.4 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\admin\catalog;
|
|
|
|
use App\Models\Department;
|
|
use App\Models\Direction;
|
|
use App\Models\EducationalInstitution;
|
|
use App\Models\EducationForm;
|
|
use App\Models\EducationLevel;
|
|
use App\Models\EntranceExamination;
|
|
use App\Models\ExaminationType;
|
|
use App\Models\Faculty;
|
|
use App\Models\Subject;
|
|
use App\Models\SubjectType;
|
|
use App\Models\User;
|
|
use Tests\TestCase;
|
|
|
|
class DirectionTest extends TestCase
|
|
{
|
|
private User $user;
|
|
private Direction $direction;
|
|
private EntranceExamination $entranceExamination;
|
|
private array $data;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
EducationalInstitution::factory()->create();
|
|
Faculty::factory()->create();
|
|
Department::factory()->create();
|
|
EducationLevel::factory()->create();
|
|
EducationForm::factory()->create();
|
|
|
|
$this->direction = Direction::factory()->create();
|
|
|
|
ExaminationType::factory()->create();
|
|
Subject::factory()->create();
|
|
SubjectType::factory()->create();
|
|
$this->entranceExamination = EntranceExamination::factory()->create();
|
|
|
|
$this->data = Direction::factory()->make()->only([
|
|
'position',
|
|
'name',
|
|
'description',
|
|
'code',
|
|
'slug',
|
|
'education_level_id',
|
|
'education_form_id',
|
|
'department_id',
|
|
'budget_places',
|
|
'quota',
|
|
'paid_places',
|
|
'cost_paid_place',
|
|
'period'
|
|
]);
|
|
|
|
$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
|
|
{
|
|
$this->entranceExamination->delete();
|
|
$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());
|
|
}
|
|
|
|
public function testNotDestroyDirectionWithEntranceExamination(): void
|
|
{
|
|
$response = $this->actingAs($this->user)
|
|
->withSession(['banned' => false])
|
|
->delete(route('directions.destroy', $this->direction));
|
|
|
|
$response->assertStatus(302);
|
|
|
|
$this->assertDatabaseHas(
|
|
'directions',
|
|
$this->direction->only([
|
|
'position',
|
|
'name',
|
|
'description',
|
|
'code',
|
|
'slug',
|
|
'education_level_id',
|
|
'education_form_id',
|
|
'department_id',
|
|
])
|
|
);
|
|
}
|
|
}
|