applicant-site/tests/Feature/admin/catalog/DirectionTest.php

134 lines
3.7 KiB
PHP
Raw Permalink Normal View History

<?php
namespace Tests\Feature\admin\catalog;
use App\Models\Department;
use App\Models\Direction;
use App\Models\EducationalInstitution;
2024-02-15 09:58:01 +03:00
use App\Models\EducationForm;
2024-02-14 16:16:44 +03:00
use App\Models\EducationLevel;
2024-02-19 10:51:20 +03:00
use App\Models\EntranceExamination;
use App\Models\ExaminationType;
use App\Models\Faculty;
2024-02-19 10:51:20 +03:00
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;
2024-02-19 10:51:20 +03:00
private EntranceExamination $entranceExamination;
private array $data;
2024-02-19 10:51:20 +03:00
protected function setUp(): void
{
parent::setUp();
EducationalInstitution::factory()->create();
Faculty::factory()->create();
Department::factory()->create();
2024-02-14 16:16:44 +03:00
EducationLevel::factory()->create();
2024-02-15 09:58:01 +03:00
EducationForm::factory()->create();
$this->direction = Direction::factory()->create();
2024-02-19 10:51:20 +03:00
ExaminationType::factory()->create();
Subject::factory()->create();
SubjectType::factory()->create();
$this->entranceExamination = EntranceExamination::factory()->create();
$this->data = Direction::factory()->make()->only([
'position',
'name',
'description',
2024-02-14 16:16:44 +03:00
'code',
'slug',
2024-02-14 16:16:44 +03:00
'education_level_id',
2024-02-15 09:58:01 +03:00
'education_form_id',
'department_id',
2024-03-05 16:51:29 +03:00
'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);
2024-03-06 10:31:27 +03:00
// $response->assertRedirect(route('directions.index'));
$this->assertDatabaseHas('directions', $this->data);
}
public function testDestroyDirection(): void
{
2024-02-19 10:51:20 +03:00
$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());
}
}