forked from aslan/applicant-site
prodV1 #2
|
@ -7,6 +7,7 @@ use App\Http\Requests\admin\Catalog\StoreDirectionRequest;
|
|||
use App\Http\Requests\admin\Catalog\UpdateDirectionRequest;
|
||||
use App\Models\Department;
|
||||
use App\Models\Direction;
|
||||
use App\Models\EducationForm;
|
||||
use App\Models\EducationLevel;
|
||||
use App\Models\Faculty;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
|
@ -25,8 +26,9 @@ class DirectionController extends Controller
|
|||
public function create(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
|
||||
{
|
||||
$levels = EducationLevel::pluck('name', 'id');
|
||||
$forms = EducationForm::pluck('name', 'id');
|
||||
$departments = Department::pluck('name', 'id');
|
||||
return view('admin.catalog.direction.create', compact('departments', 'levels'));
|
||||
return view('admin.catalog.direction.create', compact('departments', 'levels', 'forms'));
|
||||
}
|
||||
|
||||
public function store(StoreDirectionRequest $request): RedirectResponse
|
||||
|
@ -40,6 +42,7 @@ class DirectionController extends Controller
|
|||
$direction->slug = $validated['slug'];
|
||||
$direction->code = $validated['code'];
|
||||
$direction->education_level_id = $validated['education_level_id'];
|
||||
$direction->education_form_id = $validated['education_form_id'];
|
||||
$direction->department_id = $validated['department_id'];
|
||||
$direction->save();
|
||||
|
||||
|
@ -66,7 +69,8 @@ class DirectionController extends Controller
|
|||
{
|
||||
$levels = EducationLevel::pluck('name', 'id');
|
||||
$departments = Department::pluck('name', 'id');
|
||||
return view('admin.catalog.direction.edit', compact('direction', 'departments', 'levels'));
|
||||
$forms = EducationForm::pluck('name', 'id');
|
||||
return view('admin.catalog.direction.edit', compact('direction', 'departments', 'levels', 'forms'));
|
||||
}
|
||||
|
||||
public function update(UpdateDirectionRequest $request, Direction $direction): RedirectResponse
|
||||
|
@ -80,6 +84,7 @@ class DirectionController extends Controller
|
|||
$direction->slug = $validated['slug'];
|
||||
$direction->code = $validated['code'];
|
||||
$direction->education_level_id = $validated['education_level_id'];
|
||||
$direction->education_form_id = $validated['education_form_id'];
|
||||
$direction->department_id = $validated['department_id'];
|
||||
$direction->save();
|
||||
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\admin\Catalog;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\admin\Catalog\StoreEducationFormRequest;
|
||||
use App\Http\Requests\admin\Catalog\UpdateEducationFormRequest;
|
||||
use App\Models\EducationForm;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Foundation\Application;
|
||||
|
||||
class EducationFormController extends Controller
|
||||
{
|
||||
public function index(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
|
||||
{
|
||||
$forms = EducationForm::all();
|
||||
return view('admin.catalog.education_form.index', compact('forms'));
|
||||
}
|
||||
|
||||
public function create(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
|
||||
{
|
||||
return view('admin.catalog.education_form.create');
|
||||
}
|
||||
|
||||
public function store(StoreEducationFormRequest $request)
|
||||
{
|
||||
$validated = $request->validated();
|
||||
$form = new EducationForm();
|
||||
$form->name = $validated['name'];
|
||||
$form->description = $validated['description'];
|
||||
$form->slug = $validated['slug'];
|
||||
$form->save();
|
||||
|
||||
return redirect()->route('education_forms.index');
|
||||
}
|
||||
|
||||
public function show(EducationForm $educationForm): View|Factory|\Illuminate\Contracts\Foundation\Application
|
||||
{
|
||||
$directions = $educationForm->directions;
|
||||
return view('admin.catalog.education_form.show', compact('educationForm', 'directions'));
|
||||
}
|
||||
|
||||
public function edit(EducationForm $educationForm)
|
||||
{
|
||||
return view('admin.catalog.education_form.edit', compact('educationForm'));
|
||||
}
|
||||
|
||||
public function update(UpdateEducationFormRequest $request, EducationForm $educationForm)
|
||||
{
|
||||
$validated = $request->validated();
|
||||
|
||||
$educationForm->name = $validated['name'];
|
||||
$educationForm->description = $validated['description'];
|
||||
$educationForm->slug = $validated['slug'];
|
||||
$educationForm->save();
|
||||
|
||||
return redirect()->route('education_forms.index');
|
||||
}
|
||||
|
||||
public function destroy(EducationForm $educationForm)
|
||||
{
|
||||
if ($educationForm->directions()->exists()) {
|
||||
return back();
|
||||
}
|
||||
$educationForm->delete();
|
||||
return redirect()->route('education_forms.index');
|
||||
}
|
||||
}
|
|
@ -20,6 +20,7 @@ class StoreDirectionRequest extends FormRequest
|
|||
'slug' => 'required|string|max:255',
|
||||
'code' => 'required|string|max:255',
|
||||
'education_level_id' => 'required|int|numeric|max:1000',
|
||||
'education_form_id' => 'required|int|numeric|max:1000',
|
||||
'department_id' => 'required|numeric|int|max:1000'
|
||||
];
|
||||
}
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\admin\Catalog;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class StoreEducationFormRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'name' => 'required|string|max:255|unique:education_levels,name',
|
||||
'description' => 'string',
|
||||
'slug' => 'required|string|max:255',
|
||||
];
|
||||
}
|
||||
}
|
|
@ -21,6 +21,7 @@ class UpdateDirectionRequest extends FormRequest
|
|||
'slug' => 'required|string|max:255',
|
||||
'code' => 'required|string|max:255',
|
||||
'education_level_id' => 'required|int|numeric|max:1000',
|
||||
'education_form_id' => 'required|int|numeric|max:1000',
|
||||
'name' => [
|
||||
'required',
|
||||
'string',
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\admin\Catalog;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class UpdateEducationFormRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'name' => "required|string|max:255|unique:education_forms,name,{$this->education_form->id}",
|
||||
'description' => 'string',
|
||||
'slug' => 'required|string|max:255',
|
||||
];
|
||||
}
|
||||
}
|
|
@ -28,4 +28,9 @@ class Direction extends Model
|
|||
{
|
||||
return $this->belongsTo(EducationLevel::class);
|
||||
}
|
||||
|
||||
public function educationForm(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(EducationForm::class);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class EducationForm extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'name',
|
||||
'description',
|
||||
'slug',
|
||||
];
|
||||
|
||||
public function directions(): HasMany
|
||||
{
|
||||
return $this->hasMany('App\Models\Direction', 'education_form_id');
|
||||
}
|
||||
}
|
|
@ -15,7 +15,8 @@ class DirectionFactory extends Factory
|
|||
'code' => fake()->text(50),
|
||||
'position' => fake()->randomDigit(),
|
||||
'department_id' => 1,
|
||||
'education_level_id' => 1
|
||||
'education_level_id' => 1,
|
||||
'education_form_id' => 1,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class EducationFormFactory extends Factory
|
||||
{
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'name' => fake()->name(),
|
||||
'description' => fake()->text(),
|
||||
'slug' => fake()->slug(),
|
||||
];
|
||||
}
|
||||
}
|
|
@ -17,6 +17,7 @@ return new class extends Migration
|
|||
$table->string('slug');
|
||||
$table->foreignId('department_id')->constrained('departments');
|
||||
$table->foreignId('education_level_id')->constrained('education_levels');
|
||||
$table->foreignId('education_form_id')->constrained('education_forms');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('education_forms', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name');
|
||||
$table->text('description')->nullable();
|
||||
$table->string('slug');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('education_forms');
|
||||
}
|
||||
};
|
|
@ -25,6 +25,7 @@ class DatabaseSeeder extends Seeder
|
|||
FacultySeeder::class,
|
||||
DepartmentSeeder::class,
|
||||
EducationLevelSeeder::class,
|
||||
EducationFormSeeder::class,
|
||||
DirectionSeeder::class,
|
||||
]);
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ class DirectionSeeder extends Seeder
|
|||
'position' => 1,
|
||||
'department_id' => 1,
|
||||
'education_level_id' => 1,
|
||||
'education_form_id' => 1,
|
||||
],
|
||||
[
|
||||
'name' => 'фармация',
|
||||
|
@ -28,6 +29,7 @@ class DirectionSeeder extends Seeder
|
|||
'position' => 2,
|
||||
'department_id' => 1,
|
||||
'education_level_id' => 2,
|
||||
'education_form_id' => 2,
|
||||
],
|
||||
[
|
||||
'name' => 'строительство',
|
||||
|
@ -37,6 +39,7 @@ class DirectionSeeder extends Seeder
|
|||
'position' => 3,
|
||||
'department_id' => 1,
|
||||
'education_level_id' => 3,
|
||||
'education_form_id' => 3,
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class EducationFormSeeder extends Seeder
|
||||
{
|
||||
public function run(): void
|
||||
{
|
||||
DB::table('education_forms')->insert([
|
||||
[
|
||||
'name' => 'очная',
|
||||
'description' => 'очная',
|
||||
'slug' => 'full-time',
|
||||
],
|
||||
[
|
||||
'name' => 'заочная',
|
||||
'description' => 'специалитет',
|
||||
'slug' => 'part-time',
|
||||
],
|
||||
[
|
||||
'name' => 'очно-заочная',
|
||||
'description' => 'очно-заочная',
|
||||
'slug' => 'blended',
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
|
@ -65,6 +65,18 @@
|
|||
@endif
|
||||
</div>
|
||||
|
||||
<div class="mt-3">
|
||||
{{ Form::label('education_form_id', 'Увовень образования') }}
|
||||
</div>
|
||||
<div class="mt-1">
|
||||
{{ Form::select('education_form_id', $forms, null, ['class' => 'form-select']) }}
|
||||
</div>
|
||||
<div>
|
||||
@if ($errors->any())
|
||||
{{ $errors->first('education_form_id') }}
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<div class="mt-3">
|
||||
{{ Form::label('slug', 'URL') }}
|
||||
</div>
|
||||
|
|
|
@ -66,6 +66,18 @@
|
|||
@endif
|
||||
</div>
|
||||
|
||||
<div class="mt-3">
|
||||
{{ Form::label('education_form_id', 'Увовень образования') }}
|
||||
</div>
|
||||
<div class="mt-1">
|
||||
{{ Form::select('education_form_id', $forms, $direction->educationForm->id, ['class' => 'form-select']) }}
|
||||
</div>
|
||||
<div>
|
||||
@if ($errors->any())
|
||||
{{ $errors->first('education_form_id') }}
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<div class="mt-3">
|
||||
{{ Form::label('slug', 'URL') }}
|
||||
</div>
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
@extends('layouts.admin_layout')
|
||||
@section('content')
|
||||
@auth()
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<h1 class=""> Создать форму Образования</h1>
|
||||
{{ Form::open(['url' => route('education_forms.store'), 'method' => 'POST', 'class' => '']) }}
|
||||
<div class="col">
|
||||
<div class="mt-3">
|
||||
{{ Form::label('name', 'Название') }}
|
||||
</div>
|
||||
<div class="mt-1">
|
||||
{{ Form::text('name', '', ['class' => 'form-control']) }}
|
||||
</div>
|
||||
<div>
|
||||
@if ($errors->any())
|
||||
{{ $errors->first('name') }}
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<div class="mt-3">
|
||||
{{ Form::label('description', 'Описание') }}
|
||||
</div>
|
||||
<div class="mt-1">
|
||||
{{ Form::text('description', '', ['class' => 'form-control']) }}
|
||||
</div>
|
||||
<div>
|
||||
@if ($errors->any())
|
||||
{{ $errors->first('description') }}
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<div class="mt-3">
|
||||
{{ Form::label('slug', 'URL') }}
|
||||
</div>
|
||||
<div class="mt-1">
|
||||
{{ Form::text('slug', '', ['class' => 'form-control']) }}
|
||||
</div>
|
||||
<div>
|
||||
@if ($errors->any())
|
||||
{{ $errors->first('slug') }}
|
||||
@endif
|
||||
</div>
|
||||
<div class="mt-3">
|
||||
{{ Form::submit('Создать', ['class' => 'btn btn-primary']) }}
|
||||
</div>
|
||||
</div>
|
||||
{{ Form::close() }}
|
||||
</div>
|
||||
</div>
|
||||
@endauth
|
||||
@endsection
|
|
@ -0,0 +1,53 @@
|
|||
@extends('layouts.admin_layout')
|
||||
@section('content')
|
||||
|
||||
@auth()
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<h1 class="">Изменить форму образования</h1>
|
||||
{{ Form::open(['url' => route('education_forms.update', $educationForm), 'method' => 'PATCH', 'class' => '']) }}
|
||||
<div class="col">
|
||||
<div class="mt-3">
|
||||
{{ Form::label('name', 'Название') }}
|
||||
</div>
|
||||
<div class="mt-1">
|
||||
{{ Form::text('name', $educationForm->name, ['class' => 'form-control']) }}
|
||||
</div>
|
||||
<div>
|
||||
@if ($errors->any())
|
||||
{{ $errors->first('name') }}
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<div class="mt-3">
|
||||
{{ Form::label('description', 'Описание') }}
|
||||
</div>
|
||||
<div class="mt-1">
|
||||
{{ Form::text('description', $educationForm->description, ['class' => 'form-control']) }}
|
||||
</div>
|
||||
<div>
|
||||
@if ($errors->any())
|
||||
{{ $errors->first('description') }}
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<div class="mt-3">
|
||||
{{ Form::label('slug', 'URL') }}
|
||||
</div>
|
||||
<div class="mt-1">
|
||||
{{ Form::text('slug', $educationForm->slug, ['class' => 'form-control']) }}
|
||||
</div>
|
||||
<div>
|
||||
@if ($errors->any())
|
||||
{{ $errors->first('slug') }}
|
||||
@endif
|
||||
</div>
|
||||
<div class="mt-3">
|
||||
{{ Form::submit('Изменить', ['class' => 'btn btn-primary']) }}
|
||||
</div>
|
||||
</div>
|
||||
{{ Form::close() }}
|
||||
</div>
|
||||
</div>
|
||||
@endauth
|
||||
@endsection
|
|
@ -0,0 +1,39 @@
|
|||
@extends('layouts.admin_layout')
|
||||
@section('content')
|
||||
<div class="container">
|
||||
<h2>Формы образования</h2>
|
||||
<br>
|
||||
<a href="{{ route('education_forms.create') }}" class="btn btn-primary">Создать Форму образования</a>
|
||||
<br>
|
||||
<br>
|
||||
<table class="table">
|
||||
<thead class="border-b-2 border-solid border-black text-left" style="text-align: left">
|
||||
<tr>
|
||||
<th scope="col">Название</th>
|
||||
<th scope="col">Описание</th>
|
||||
<th scope="col">URL</th>
|
||||
<th scope="col">действия</th>
|
||||
<th scope="col"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach($forms as $form)
|
||||
<tr class="">
|
||||
<td><a href="{{ route('education_forms.show', $form) }}">{{ $form->name }}</a></td>
|
||||
<td>{{ Str::words($form->description, 10, '...') }}</td>
|
||||
<td>{{ $form->slug }}</td>
|
||||
<td>
|
||||
<a href="{{ route("education_forms.edit", $form) }}"
|
||||
class="btn btn-secondary">редактировать</a>
|
||||
<a rel="nofollow" data-method="delete" data-confirm="Вы действительно хотите удалить?"
|
||||
href="{{ route('education_forms.destroy', $form) }}"
|
||||
class="btn btn-danger">удалить</a>
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
<br>
|
||||
<br>
|
||||
</div>
|
||||
@endsection
|
|
@ -0,0 +1,17 @@
|
|||
@extends('layouts.admin_layout')
|
||||
@section('content')
|
||||
@auth()
|
||||
<div class="container mt-4">
|
||||
<h2>Название</h2>
|
||||
<p>{{ $educationForm->name }}</p>
|
||||
<h2>Описание</h2>
|
||||
<p>{{ $educationForm->description }}</p>
|
||||
<h2>URL</h2>
|
||||
<p>{{ $educationForm->slug }}</p>
|
||||
<h2>Направления</h2>
|
||||
@foreach($directions as $direction)
|
||||
<p><a href="{{ route('directions.show', $direction) }}">{{ $direction->name }}</a></p>
|
||||
@endforeach
|
||||
</div>
|
||||
@endauth
|
||||
@endsection
|
|
@ -57,6 +57,7 @@
|
|||
<li class="list-group-item"><a href="{{ route('departments.index') }}">Кафедры</a></li>
|
||||
<li class="list-group-item"><a href="{{ route('directions.index') }}">Направления</a></li>
|
||||
<li class="list-group-item"><a href="{{ route('education_levels.index') }}">Уровни образования</a></li>
|
||||
<li class="list-group-item"><a href="{{ route('education_forms.index') }}">Формы образования</a></li>
|
||||
</ul>
|
||||
</aside>
|
||||
<main class="col-10">@yield('content')</main>
|
||||
|
|
|
@ -4,6 +4,7 @@ use App\Http\Controllers\admin\AdmissionController;
|
|||
use App\Http\Controllers\admin\Catalog\DepartmentController;
|
||||
use App\Http\Controllers\admin\Catalog\DirectionController;
|
||||
use App\Http\Controllers\admin\Catalog\EducationalInstitutionController;
|
||||
use App\Http\Controllers\admin\Catalog\EducationFormController;
|
||||
use App\Http\Controllers\admin\Catalog\EducationLevelController;
|
||||
use App\Http\Controllers\admin\Catalog\FacultyController;
|
||||
use App\Http\Controllers\admin\DocumentController;
|
||||
|
@ -37,6 +38,9 @@ Route::middleware(['auth', 'verified'])->prefix('admin')->group(function () {
|
|||
Route::resource('/education_levels', EducationLevelController::class)
|
||||
->scoped(['education_level' => 'slug']);
|
||||
|
||||
Route::resource('/education_forms', EducationFormController::class)
|
||||
->scoped(['education_form' => 'slug']);
|
||||
|
||||
Route::resources([
|
||||
'/documents' => DocumentController::class,
|
||||
'/users' => UserController::class,
|
||||
|
|
|
@ -5,6 +5,7 @@ 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\Faculty;
|
||||
use App\Models\User;
|
||||
|
@ -21,6 +22,7 @@ class DepartmentTest extends TestCase
|
|||
EducationalInstitution::factory()->create();
|
||||
Faculty::factory()->create();
|
||||
EducationLevel::factory()->create();
|
||||
EducationForm::factory()->create();
|
||||
|
||||
$this->department = Department::factory()->create();
|
||||
$this->data = Department::factory()->make()->only([
|
||||
|
|
|
@ -5,6 +5,7 @@ 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\Faculty;
|
||||
use App\Models\User;
|
||||
|
@ -22,6 +23,7 @@ class DirectionTest extends TestCase
|
|||
Faculty::factory()->create();
|
||||
Department::factory()->create();
|
||||
EducationLevel::factory()->create();
|
||||
EducationForm::factory()->create();
|
||||
|
||||
$this->direction = Direction::factory()->create();
|
||||
$this->data = Direction::factory()->make()->only([
|
||||
|
@ -31,6 +33,7 @@ class DirectionTest extends TestCase
|
|||
'code',
|
||||
'slug',
|
||||
'education_level_id',
|
||||
'education_form_id',
|
||||
'department_id',
|
||||
]);
|
||||
|
||||
|
|
|
@ -0,0 +1,123 @@
|
|||
<?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\Faculty;
|
||||
use App\Models\User;
|
||||
use Tests\TestCase;
|
||||
|
||||
class EducationFormTest extends TestCase
|
||||
{
|
||||
private User $user;
|
||||
private Direction $direction;
|
||||
private EducationForm $form;
|
||||
private array $data;
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
EducationalInstitution::factory()->create();
|
||||
Faculty::factory()->create();
|
||||
Department::factory()->create();
|
||||
EducationLevel::factory()->create();
|
||||
$this->form = EducationForm::factory()->create();
|
||||
|
||||
$this->direction = Direction::factory()->create();
|
||||
$this->data = EducationForm::factory()->make()->only([
|
||||
'name',
|
||||
'description',
|
||||
'slug',
|
||||
]);
|
||||
|
||||
$this->user = User::factory()->create([
|
||||
'name' => 'admin',
|
||||
'email' => 'test@example.com',
|
||||
'password' => 123456
|
||||
]);
|
||||
}
|
||||
|
||||
public function testIndexEducationFormsPage(): void
|
||||
{
|
||||
$response = $this->actingAs($this->user)
|
||||
->withSession(['banned' => false])
|
||||
->get(route('education_forms.index'));
|
||||
|
||||
$response->assertOk();
|
||||
}
|
||||
|
||||
public function testCreateEducationFormPage(): void
|
||||
{
|
||||
$response = $this->actingAs($this->user)
|
||||
->withSession(['banned' => false])
|
||||
->get(route('education_forms.create'));
|
||||
|
||||
$response->assertOk();
|
||||
}
|
||||
|
||||
public function testStoreEducationForm(): void
|
||||
{
|
||||
$response = $this->actingAs($this->user)
|
||||
->withSession(['banned' => false])
|
||||
->post(route('education_forms.store', $this->data));
|
||||
|
||||
$response->assertRedirect(route('education_forms.index'));
|
||||
|
||||
$this->assertDatabaseHas('education_forms', $this->data);
|
||||
}
|
||||
|
||||
public function testShowEducationFormPage(): void
|
||||
{
|
||||
$response = $this->actingAs($this->user)
|
||||
->withSession(['banned' => false])
|
||||
->get(route('education_forms.show', $this->form));
|
||||
|
||||
$response->assertOk();
|
||||
}
|
||||
|
||||
public function testEditEducationFormPage(): void
|
||||
{
|
||||
$response = $this->actingAs($this->user)
|
||||
->withSession(['banned' => false])
|
||||
->get(route('education_forms.edit', $this->form));
|
||||
|
||||
$response->assertOk();
|
||||
}
|
||||
|
||||
public function testUpdateEducationForm(): void
|
||||
{
|
||||
$response = $this->actingAs($this->user)
|
||||
->withSession(['banned' => false])
|
||||
->patch(route('education_forms.update', $this->form), $this->data);
|
||||
|
||||
$response->assertRedirect(route('education_forms.index'));
|
||||
|
||||
$this->assertDatabaseHas('education_forms', $this->data);
|
||||
}
|
||||
|
||||
public function testDestroyEducationForm(): void
|
||||
{
|
||||
$this->direction->delete();
|
||||
$response = $this->actingAs($this->user)
|
||||
->withSession(['banned' => false])
|
||||
->delete(route('education_forms.destroy', $this->form));
|
||||
|
||||
$response->assertRedirect(route('education_forms.index'));
|
||||
|
||||
$this->assertDatabaseMissing('education_forms', $this->form->toArray());
|
||||
}
|
||||
|
||||
public function testNotDestroyEducationForm(): void
|
||||
{
|
||||
$response = $this->actingAs($this->user)
|
||||
->withSession(['banned' => false])
|
||||
->delete(route('education_forms.destroy', $this->form));
|
||||
|
||||
$response->assertStatus(302);
|
||||
|
||||
$this->assertDatabaseHas('education_forms', $this->form->only(['name', 'slug']));
|
||||
}
|
||||
}
|
|
@ -5,6 +5,7 @@ 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\Faculty;
|
||||
use App\Models\User;
|
||||
|
@ -22,6 +23,7 @@ class EducationLevelTest extends TestCase
|
|||
EducationalInstitution::factory()->create();
|
||||
Faculty::factory()->create();
|
||||
Department::factory()->create();
|
||||
EducationForm::factory()->create();
|
||||
$this->level = EducationLevel::factory()->create();
|
||||
|
||||
$this->direction = Direction::factory()->create();
|
||||
|
|
Loading…
Reference in New Issue