applicant-site/tests/Feature/admin/catalog/direction/EntranceExaminationTest.php

124 lines
3.7 KiB
PHP
Raw Permalink Normal View History

2024-02-19 10:51:20 +03:00
<?php
namespace Tests\Feature\admin\catalog\direction;
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 EntranceExaminationTest extends TestCase
{
private User $user;
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();
Direction::factory()->create();
ExaminationType::factory()->create();
Subject::factory()->create();
SubjectType::factory()->create();
$this->entranceExamination = EntranceExamination::factory()->create();
$this->data = EntranceExamination::factory()->make()->only([
'direction_id',
'examination_type_id',
'subject_id',
'subject_type_id',
'scores',
'position',
]);
$this->user = User::factory()->create([
'name' => 'admin',
'email' => 'test@example.com',
'password' => 123456
]);
}
public function testIndexEntranceExaminationsPage(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->get(route('entrance_examinations.index'));
$response->assertOk();
}
public function testCreateEntranceExaminationPage(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->get(route('entrance_examinations.create'));
$response->assertOk();
}
public function testStoreEntranceExamination(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->post(route('entrance_examinations.store', $this->data));
$response->assertRedirect(route('entrance_examinations.index'));
$this->assertDatabaseHas('entrance_examinations', $this->data);
}
public function testShowEntranceExaminationPage(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->get(route('entrance_examinations.show', $this->entranceExamination));
$response->assertOk();
}
public function testEditEntranceExaminationPage(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->get(route('entrance_examinations.edit', $this->entranceExamination));
$response->assertOk();
}
public function testUpdateEntranceExamination(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->patch(route('entrance_examinations.update', $this->entranceExamination), $this->data);
$response->assertRedirect(route('entrance_examinations.index'));
$this->assertDatabaseHas('entrance_examinations', $this->data);
}
public function testEntranceExaminationDirection(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->delete(route('entrance_examinations.destroy', $this->entranceExamination));
$response->assertRedirect(route('entrance_examinations.index'));
$this->assertDatabaseMissing('entrance_examinations', $this->entranceExamination->toArray());
}
}