2024-02-19 18:55:44 +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\Faculty;
|
|
|
|
use App\Models\Place;
|
|
|
|
use App\Models\PlaceType;
|
|
|
|
use App\Models\User;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
class PlaceTest extends TestCase
|
|
|
|
{
|
|
|
|
private User $user;
|
|
|
|
private Place $place;
|
|
|
|
private array $data;
|
|
|
|
protected function setUp(): void
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
PlaceType::factory()->create();
|
|
|
|
EducationalInstitution::factory()->create();
|
|
|
|
Faculty::factory()->create();
|
|
|
|
Department::factory()->create();
|
|
|
|
EducationLevel::factory()->create();
|
|
|
|
EducationForm::factory()->create();
|
|
|
|
Direction::factory()->create();
|
|
|
|
|
|
|
|
$this->place = Place::factory()->create();
|
|
|
|
|
|
|
|
$this->data = Place::factory()->make()->only([
|
|
|
|
'position',
|
|
|
|
'description',
|
|
|
|
'amount',
|
2024-02-28 15:03:46 +03:00
|
|
|
'quota',
|
2024-02-19 18:55:44 +03:00
|
|
|
'education_form_id',
|
|
|
|
'place_type_id',
|
|
|
|
'direction_id',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->user = User::factory()->create([
|
|
|
|
'name' => 'admin',
|
|
|
|
'email' => 'test@example.com',
|
|
|
|
'password' => 123456
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testIndexPlacesPage(): void
|
|
|
|
{
|
|
|
|
$response = $this->actingAs($this->user)
|
|
|
|
->withSession(['banned' => false])
|
|
|
|
->get(route('places.index'));
|
|
|
|
|
|
|
|
$response->assertOk();
|
|
|
|
}
|
|
|
|
|
2024-02-26 09:38:17 +03:00
|
|
|
public function testCreatePlacePage(): void
|
2024-02-19 18:55:44 +03:00
|
|
|
{
|
|
|
|
$response = $this->actingAs($this->user)
|
|
|
|
->withSession(['banned' => false])
|
|
|
|
->get(route('places.create'));
|
|
|
|
|
|
|
|
$response->assertOk();
|
|
|
|
}
|
|
|
|
|
2024-02-26 09:38:17 +03:00
|
|
|
public function testStorePlace(): void
|
2024-02-19 18:55:44 +03:00
|
|
|
{
|
|
|
|
$response = $this->actingAs($this->user)
|
|
|
|
->withSession(['banned' => false])
|
|
|
|
->post(route('places.store', $this->data));
|
|
|
|
|
|
|
|
$response->assertRedirect(route('places.index'));
|
|
|
|
|
|
|
|
$this->assertDatabaseHas('places', $this->data);
|
|
|
|
}
|
|
|
|
|
2024-02-26 09:38:17 +03:00
|
|
|
public function testShowPlacePage(): void
|
2024-02-19 18:55:44 +03:00
|
|
|
{
|
|
|
|
$response = $this->actingAs($this->user)
|
|
|
|
->withSession(['banned' => false])
|
|
|
|
->get(route('places.show', $this->place));
|
|
|
|
|
|
|
|
$response->assertOk();
|
|
|
|
}
|
|
|
|
|
2024-02-26 09:38:17 +03:00
|
|
|
public function testEditPlacePage(): void
|
2024-02-19 18:55:44 +03:00
|
|
|
{
|
|
|
|
$response = $this->actingAs($this->user)
|
|
|
|
->withSession(['banned' => false])
|
|
|
|
->get(route('places.edit', $this->place));
|
|
|
|
|
|
|
|
$response->assertOk();
|
|
|
|
}
|
|
|
|
|
2024-02-26 09:38:17 +03:00
|
|
|
public function testUpdatePlace(): void
|
2024-02-19 18:55:44 +03:00
|
|
|
{
|
|
|
|
$response = $this->actingAs($this->user)
|
|
|
|
->withSession(['banned' => false])
|
|
|
|
->patch(route('places.update', $this->place), $this->data);
|
|
|
|
|
|
|
|
$response->assertRedirect(route('places.index'));
|
|
|
|
|
|
|
|
$this->assertDatabaseHas('places', $this->data);
|
|
|
|
}
|
|
|
|
|
2024-02-26 09:38:17 +03:00
|
|
|
public function testDestroyPlace(): void
|
2024-02-19 18:55:44 +03:00
|
|
|
{
|
|
|
|
$response = $this->actingAs($this->user)
|
|
|
|
->withSession(['banned' => false])
|
|
|
|
->delete(route('places.destroy', $this->place));
|
|
|
|
|
|
|
|
$response->assertRedirect(route('places.index'));
|
|
|
|
|
|
|
|
$this->assertDatabaseMissing('places', $this->place->toArray());
|
|
|
|
}
|
|
|
|
}
|