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

107 lines
3.3 KiB
PHP

<?php
namespace Tests\Feature\admin\catalog;
use App\Models\Department;
use App\Models\EducationalInstitution;
use App\Models\Faculty;
use App\Models\User;
use Tests\TestCase;
class EducationalInstitutionTest extends TestCase
{
private User $user;
private EducationalInstitution $educationalInstitution;
private Faculty $faculty;
private array $data;
protected function setUp(): void
{
parent::setUp();
$this->educationalInstitution = EducationalInstitution::factory()->create();
$this->data = EducationalInstitution::factory()->make()->only([
'position',
'name',
'description',
'slug',
]);
$this->faculty = Faculty::factory()->create();
$this->user = User::factory()->create([
'name' => 'admin',
'email' => 'test@example.com',
'password' => 123456
]);
}
public function testIndexEducationalInstitutionsPage(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->get(route('educational_institutions.index'));
$response->assertOk();
}
public function testCreateEducationalInstitutionPage(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->get(route('educational_institutions.create'));
$response->assertOk();
}
public function testStoreEducationalInstitution(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->post(route('educational_institutions.store', $this->data));
$response->assertRedirect(route('educational_institutions.index'));
$this->assertDatabaseHas('educational_institutions', $this->data);
}
public function testShowEducationalInstitutionPage(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->get(route('educational_institutions.show', $this->educationalInstitution));
$response->assertOk();
}
public function testEditEducationalInstitutionPage(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->get(route('educational_institutions.edit', $this->educationalInstitution));
$response->assertOk();
}
public function testUpdateEducationalInstitution(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->patch(route('educational_institutions.update', $this->educationalInstitution), $this->data);
$response->assertRedirect(route('educational_institutions.index'));
$this->assertDatabaseHas('educational_institutions', $this->data);
}
public function testDestroyFaculty(): void
{
$this->faculty->delete();
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->delete(route('educational_institutions.destroy', $this->educationalInstitution));
$response->assertRedirect(route('educational_institutions.index'));
$this->assertDatabaseMissing('educational_institutions', $this->educationalInstitution->toArray());
}
}