diff --git a/app/Http/Controllers/admin/Catalog/Direction/PlaceController.php b/app/Http/Controllers/admin/Catalog/Direction/PlaceController.php new file mode 100644 index 0000000..1e96a3c --- /dev/null +++ b/app/Http/Controllers/admin/Catalog/Direction/PlaceController.php @@ -0,0 +1,93 @@ +validated(); + + $place = new Place(); + $place->position = $validated['position']; + $place->description = $validated['description']; + $place->amount = $validated['amount']; + $place->education_form_id = $validated['education_form_id']; + $place->place_type_id = $validated['place_type_id']; + $place->direction_id = $validated['direction_id']; + $place->save(); + + return redirect()->route('places.index'); + } + + public function show(Place $place): View + { + return view('admin.catalog.direction.place.show', compact('place')); + } + + public function edit(Place $place): View + { + $directions = Direction::pluck('name', 'id'); + $placeTypes = PlaceType::pluck('name', 'id'); + $educationForms = EducationForm::pluck('name', 'id'); + return view( + 'admin.catalog.direction.place.create', + compact( + 'place', + 'directions', + 'placeTypes', + 'educationForms', + )); + } + + public function update(UpdatePlaceRequest $request, Place $place): RedirectResponse + { + $validated = $request->validated(); + + $place->position = $validated['position']; + $place->description = $validated['description']; + $place->amount = $validated['amount']; + $place->education_form_id = $validated['education_form_id']; + $place->place_type_id = $validated['place_type_id']; + $place->direction_id = $validated['direction_id']; + $place->save(); + + return redirect()->route('places.index'); + } + + public function destroy(Place $place): RedirectResponse + { + $place->delete(); + return redirect()->route('places.index'); + } +} diff --git a/app/Http/Controllers/admin/Catalog/Direction/PlaceTypeController.php b/app/Http/Controllers/admin/Catalog/Direction/PlaceTypeController.php new file mode 100644 index 0000000..74e955b --- /dev/null +++ b/app/Http/Controllers/admin/Catalog/Direction/PlaceTypeController.php @@ -0,0 +1,72 @@ +validated(); + + $type = new PlaceType(); + $type->name = $validated['name']; + $type->description = $validated['description']; + $type->slug = $validated['slug']; + $type->position = $validated['position']; + $type->save(); + + return redirect()->route('place_types.index'); + } + + public function show(PlaceType $placeType): View + { + return view('admin.catalog.direction.place_type.show', compact('placeType')); + } + + public function edit(PlaceType $placeType): View + { + return view('admin.catalog.direction.place_type.edit', compact('placeType')); + } + + public function update(UpdatePlaceTypeRequest $request, PlaceType $placeType): RedirectResponse + { + $validated = $request->validated(); + + $placeType->name = $validated['name']; + $placeType->description = $validated['description']; + $placeType->slug = $validated['slug']; + $placeType->position = $validated['position']; + $placeType->save(); + + return redirect()->route('place_types.index'); + } + + public function destroy(PlaceType $placeType): RedirectResponse + { + if ($placeType->places()->exists()) { + return back(); + } + $placeType->delete(); + return redirect()->route('place_types.index'); + } +} diff --git a/app/Http/Requests/admin/Catalog/Direction/StorePlaceRequest.php b/app/Http/Requests/admin/Catalog/Direction/StorePlaceRequest.php new file mode 100644 index 0000000..cb755c8 --- /dev/null +++ b/app/Http/Requests/admin/Catalog/Direction/StorePlaceRequest.php @@ -0,0 +1,24 @@ + 'required|int|numeric|max:255', + 'description' => 'string', + 'amount' => 'required|int|numeric|max:255', + 'education_form_id' => 'required|int|numeric|max:255', + 'place_type_id' => 'required|int|numeric|max:255', + 'direction_id' => 'required|int|numeric|max:255', + ]; + } +} diff --git a/app/Http/Requests/admin/Catalog/Direction/StorePlaceTypeRequest.php b/app/Http/Requests/admin/Catalog/Direction/StorePlaceTypeRequest.php new file mode 100644 index 0000000..311736b --- /dev/null +++ b/app/Http/Requests/admin/Catalog/Direction/StorePlaceTypeRequest.php @@ -0,0 +1,23 @@ + 'required|int|numeric|max:255', + 'name' => 'required|string|max:255|unique:place_types,name', + 'description' => 'string', + 'slug' => 'required|string|max:255|unique:place_types,slug', + ]; + } +} diff --git a/app/Http/Requests/admin/Catalog/Direction/UpdatePlaceRequest.php b/app/Http/Requests/admin/Catalog/Direction/UpdatePlaceRequest.php new file mode 100644 index 0000000..5431012 --- /dev/null +++ b/app/Http/Requests/admin/Catalog/Direction/UpdatePlaceRequest.php @@ -0,0 +1,24 @@ + 'required|int|numeric|max:255', + 'description' => 'string', + 'amount' => 'required|int|numeric|max:255', + 'education_form_id' => 'required|int|numeric|max:255', + 'place_type_id' => 'required|int|numeric|max:255', + 'direction_id' => 'required|int|numeric|max:255', + ]; + } +} diff --git a/app/Http/Requests/admin/Catalog/Direction/UpdatePlaceTypeRequest.php b/app/Http/Requests/admin/Catalog/Direction/UpdatePlaceTypeRequest.php new file mode 100644 index 0000000..9e71114 --- /dev/null +++ b/app/Http/Requests/admin/Catalog/Direction/UpdatePlaceTypeRequest.php @@ -0,0 +1,32 @@ + 'required|int|numeric|max:255', + 'description' => 'string', + 'slug' => [ + 'string', + 'required', + 'max:255', + "unique:place_types,slug,{$this->place_type->id}", + ], + 'name' => [ + 'required', + 'string', + 'max:255', + "unique:place_types,name,{$this->place_type->id}", + ], + ]; + } +} diff --git a/app/Models/Direction.php b/app/Models/Direction.php index 3a302fd..f6db97f 100644 --- a/app/Models/Direction.php +++ b/app/Models/Direction.php @@ -39,4 +39,9 @@ class Direction extends Model { return $this->hasMany('App\Models\EntranceExamination', 'direction_id'); } + + public function places(): HasMany + { + return $this->hasMany('App\Models\Place', 'direction_id'); + } } diff --git a/app/Models/EducationForm.php b/app/Models/EducationForm.php index 94bb1f6..0c1fa1f 100644 --- a/app/Models/EducationForm.php +++ b/app/Models/EducationForm.php @@ -21,4 +21,9 @@ class EducationForm extends Model { return $this->hasMany('App\Models\Direction', 'education_form_id'); } + + public function places(): HasMany + { + return $this->hasMany('App\Models\Place', 'education_form_id'); + } } diff --git a/app/Models/Place.php b/app/Models/Place.php new file mode 100644 index 0000000..690f61a --- /dev/null +++ b/app/Models/Place.php @@ -0,0 +1,37 @@ +belongsTo(Direction::class); + } + + public function placeType(): BelongsTo + { + return $this->belongsTo(PlaceType::class); + } + + public function educationForm(): BelongsTo + { + return $this->belongsTo(EducationForm::class); + } +} diff --git a/app/Models/PlaceType.php b/app/Models/PlaceType.php new file mode 100644 index 0000000..ec93888 --- /dev/null +++ b/app/Models/PlaceType.php @@ -0,0 +1,25 @@ +hasMany('App\Models\Place', 'place_type_id'); + } +} diff --git a/database/factories/PlaceFactory.php b/database/factories/PlaceFactory.php new file mode 100644 index 0000000..2958edc --- /dev/null +++ b/database/factories/PlaceFactory.php @@ -0,0 +1,20 @@ + 1, + 'description' => fake()->text(), + 'amount' => fake()->randomDigit(), + 'education_form_id' => 1, + 'place_type_id' => 1, + 'direction_id' => 1, + ]; + } +} diff --git a/database/factories/PlaceTypeFactory.php b/database/factories/PlaceTypeFactory.php new file mode 100644 index 0000000..be3432e --- /dev/null +++ b/database/factories/PlaceTypeFactory.php @@ -0,0 +1,18 @@ + fake()->name(), + 'description' => fake()->text(), + 'slug' => fake()->slug(), + 'position' => '1', + ]; + } +} diff --git a/database/migrations/2024_02_19_110011_create_place_types_table.php b/database/migrations/2024_02_19_110011_create_place_types_table.php new file mode 100644 index 0000000..aedfcba --- /dev/null +++ b/database/migrations/2024_02_19_110011_create_place_types_table.php @@ -0,0 +1,31 @@ +id(); + $table->integer('position'); + $table->string('name'); + $table->text('description')->nullable(); + $table->string('slug'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('place_types'); + } +}; diff --git a/database/migrations/2024_02_19_110021_create_places_table.php b/database/migrations/2024_02_19_110021_create_places_table.php new file mode 100644 index 0000000..dc58ff2 --- /dev/null +++ b/database/migrations/2024_02_19_110021_create_places_table.php @@ -0,0 +1,33 @@ +id(); + $table->integer('position'); + $table->integer('amount'); + $table->foreignId('education_form_id')->constrained('education_forms'); + $table->foreignId('place_type_id')->constrained('place_types'); + $table->foreignId('direction_id')->constrained('directions'); + $table->text('description')->nullable(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('places'); + } +}; diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index e3e6d62..62dc513 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -32,6 +32,8 @@ class DatabaseSeeder extends Seeder SubjectTypeSeeder::class, DirectionSeeder::class, EntranceExaminationSeeder::class, + PlaceTypeSeeder::class, + PlaceSeeder::class, ]); $this->call([ diff --git a/database/seeders/PlaceSeeder.php b/database/seeders/PlaceSeeder.php new file mode 100644 index 0000000..0984768 --- /dev/null +++ b/database/seeders/PlaceSeeder.php @@ -0,0 +1,32 @@ +insert([ + [ + 'position' => 1, + 'amount' => 25, + 'education_form_id' => 1, + 'place_type_id' => 1, + 'direction_id' => 1, + 'description' => 'очная бюджетная форма 25 мест юриспруденция', + ], + [ + 'position' => 2, + 'amount' => 30, + 'education_form_id' => 2, + 'place_type_id' => 2, + 'direction_id' => 1, + 'description' => 'заочная платная форма 30 мест юриспруденция', + ], + ]); + } +} diff --git a/database/seeders/PlaceTypeSeeder.php b/database/seeders/PlaceTypeSeeder.php new file mode 100644 index 0000000..73e6cb1 --- /dev/null +++ b/database/seeders/PlaceTypeSeeder.php @@ -0,0 +1,31 @@ +insert([ + [ + 'name' => 'бюджетная', + 'description' => 'бюджетная', + 'slug' => 'budget', + 'position' => '1', + ], + [ + 'name' => 'платная', + 'description' => 'платная', + 'slug' => 'paid', + 'position' => '2', + ], + ]); + } +} diff --git a/resources/views/admin/catalog/direction/place/create.blade.php b/resources/views/admin/catalog/direction/place/create.blade.php new file mode 100644 index 0000000..8252df9 --- /dev/null +++ b/resources/views/admin/catalog/direction/place/create.blade.php @@ -0,0 +1,91 @@ +@extends('layouts.admin_layout') +@section('content') + @auth() +
+
+

Создать места

+ {{ Form::open(['url' => route('places.store'), 'method' => 'POST', 'class' => '']) }} +
+ +
+ {{ Form::label('position', 'Позиция') }} +
+
+ {{ Form::text('position', '', ['class' => 'form-control']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('position') }} + @endif +
+ +
+ {{ Form::label('description', 'Описание') }} +
+
+ {{ Form::text('description', '', ['class' => 'form-control']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('description') }} + @endif +
+ +
+ {{ Form::label('amount', 'Количество мест') }} +
+
+ {{ Form::text('amount', '', ['class' => 'form-control']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('amount') }} + @endif +
+ +
+ {{ Form::label('direction_id', 'Направление подготовки') }} +
+
+ {{ Form::select('direction_id', $directions, null, ['class' => 'form-select']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('direction_id') }} + @endif +
+ +
+ {{ Form::label('place_type_id', 'Тип места') }} +
+
+ {{ Form::select('place_type_id', $placeTypes, null, ['class' => 'form-select']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('place_type_id') }} + @endif +
+ +
+ {{ Form::label('education_form_id', 'Форма обучения') }} +
+
+ {{ Form::select('education_form_id', $educationForms, null, ['class' => 'form-select']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('education_form_id') }} + @endif +
+ + +
+ {{ Form::submit('Создать', ['class' => 'btn btn-primary']) }} +
+
+ {{ Form::close() }} +
+
+ @endauth +@endsection diff --git a/resources/views/admin/catalog/direction/place/edit.blade.php b/resources/views/admin/catalog/direction/place/edit.blade.php new file mode 100644 index 0000000..669dac7 --- /dev/null +++ b/resources/views/admin/catalog/direction/place/edit.blade.php @@ -0,0 +1,91 @@ +@extends('layouts.admin_layout') +@section('content') + @auth() +
+
+

Изменить место

+ {{ Form::open(['url' => route('places.update', $place), 'method' => 'PATCH', 'class' => '']) }} +
+ +
+ {{ Form::label('position', 'Позиция') }} +
+
+ {{ Form::text('position', $place->position, ['class' => 'form-control']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('position') }} + @endif +
+ +
+ {{ Form::label('description', 'Описание') }} +
+
+ {{ Form::text('description', $place->description, ['class' => 'form-control']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('description') }} + @endif +
+ +
+ {{ Form::label('amount', 'Количество мест') }} +
+
+ {{ Form::text('amount', $place->amount, ['class' => 'form-control']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('amount') }} + @endif +
+ +
+ {{ Form::label('direction_id', 'Направление подготовки') }} +
+
+ {{ Form::select('direction_id', $directions, $place->direction->id, ['class' => 'form-select']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('direction_id') }} + @endif +
+ +
+ {{ Form::label('place_type_id', 'Тип места') }} +
+
+ {{ Form::select('place_type_id', $placeTypes, $place->placeType->id, ['class' => 'form-select']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('place_type_id') }} + @endif +
+ +
+ {{ Form::label('education_form_id', 'Форма обучения') }} +
+
+ {{ Form::select('education_form_id', $educationForm, $place->educationForm->id, ['class' => 'form-select']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('education_form_id') }} + @endif +
+ + +
+ {{ Form::submit('Изменить', ['class' => 'btn btn-primary']) }} +
+
+ {{ Form::close() }} +
+
+ @endauth +@endsection diff --git a/resources/views/admin/catalog/direction/place/index.blade.php b/resources/views/admin/catalog/direction/place/index.blade.php new file mode 100644 index 0000000..845d261 --- /dev/null +++ b/resources/views/admin/catalog/direction/place/index.blade.php @@ -0,0 +1,47 @@ +@extends('layouts.admin_layout') +@section('content') +
+

Места

+
+ Создать место +
+
+ + + + + + + + + + + + + + + @foreach($places as $place) + + + + + + + + + + @endforeach + +
позицияописаниеФорма обученияТип местанаправлениеКол-водействия
{{ $place->position }}{{ Str::words($place->description, 10, '...') }}{{ $place->educationForm->name }}{{ $place->placeType->name }}{{ $place->direction->name }}{{ $place->amount }} + посмотреть + редактировать + удалить +
+
+
+
+@endsection diff --git a/resources/views/admin/catalog/direction/place/show.blade.php b/resources/views/admin/catalog/direction/place/show.blade.php new file mode 100644 index 0000000..ef87b1e --- /dev/null +++ b/resources/views/admin/catalog/direction/place/show.blade.php @@ -0,0 +1,19 @@ +@extends('layouts.admin_layout') +@section('content') + @auth() +
+

позиция

+

{{ $place->position }}

+

описание

+

{{ $place->description }}

+

Форма обучения

+

{{ $place->educationForm->name }}

+

Тип Места

+

{{ $place->placeType->name }}

+

Направление

+

{{ $place->direction->name }}

+

Кол-во

+

{{ $place->amount }}

+
+ @endauth +@endsection diff --git a/resources/views/admin/catalog/direction/place_type/create.blade.php b/resources/views/admin/catalog/direction/place_type/create.blade.php new file mode 100644 index 0000000..4aec29f --- /dev/null +++ b/resources/views/admin/catalog/direction/place_type/create.blade.php @@ -0,0 +1,65 @@ +@extends('layouts.admin_layout') +@section('content') + @auth() +
+
+

Создать тип Места

+ {{ Form::open(['url' => route('place_types.store'), 'method' => 'POST', 'class' => '']) }} +
+
+ {{ Form::label('name', 'Название') }} +
+
+ {{ Form::text('name', '', ['class' => 'form-control']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('name') }} + @endif +
+ +
+ {{ Form::label('description', 'Описание') }} +
+
+ {{ Form::text('description', '', ['class' => 'form-control']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('description') }} + @endif +
+ +
+ {{ Form::label('slug', 'URL') }} +
+
+ {{ Form::text('slug', '', ['class' => 'form-control']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('slug') }} + @endif +
+ +
+ {{ Form::label('position', 'Позиция') }} +
+
+ {{ Form::text('position', '', ['class' => 'form-control']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('position') }} + @endif +
+ +
+ {{ Form::submit('Создать', ['class' => 'btn btn-primary']) }} +
+
+ {{ Form::close() }} +
+
+ @endauth +@endsection diff --git a/resources/views/admin/catalog/direction/place_type/edit.blade.php b/resources/views/admin/catalog/direction/place_type/edit.blade.php new file mode 100644 index 0000000..a41f7bf --- /dev/null +++ b/resources/views/admin/catalog/direction/place_type/edit.blade.php @@ -0,0 +1,66 @@ +@extends('layouts.admin_layout') +@section('content') + + @auth() +
+
+

Изменить тип экзамена

+ {{ Form::open(['url' => route('place_types.update', $placeType), 'method' => 'PATCH', 'class' => '']) }} +
+
+ {{ Form::label('name', 'Название') }} +
+
+ {{ Form::text('name', $placeType->name, ['class' => 'form-control']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('name') }} + @endif +
+ +
+ {{ Form::label('description', 'Описание') }} +
+
+ {{ Form::text('description', $placeType->description, ['class' => 'form-control']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('description') }} + @endif +
+ +
+ {{ Form::label('slug', 'URL') }} +
+
+ {{ Form::text('slug', $placeType->slug, ['class' => 'form-control']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('slug') }} + @endif +
+ +
+ {{ Form::label('position', 'Позиция') }} +
+
+ {{ Form::text('position', $placeType->position, ['class' => 'form-control']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('position') }} + @endif +
+ +
+ {{ Form::submit('Изменить', ['class' => 'btn btn-primary']) }} +
+
+ {{ Form::close() }} +
+
+ @endauth +@endsection diff --git a/resources/views/admin/catalog/direction/place_type/index.blade.php b/resources/views/admin/catalog/direction/place_type/index.blade.php new file mode 100644 index 0000000..1f6285e --- /dev/null +++ b/resources/views/admin/catalog/direction/place_type/index.blade.php @@ -0,0 +1,41 @@ +@extends('layouts.admin_layout') +@section('content') +
+

Тип Места

+
+ Создать тип экзамена +
+
+ + + + + + + + + + + + + @foreach($placeTypes as $placeType) + + + + + + + + @endforeach + +
ПозицияНазваниеОписаниеURLдействия
{{ $placeType->position }}{{ $placeType->name }}{{ Str::words($placeType->description, 10, '...') }}{{ $placeType->slug }} + редактировать + удалить +
+
+
+
+@endsection diff --git a/resources/views/admin/catalog/direction/place_type/show.blade.php b/resources/views/admin/catalog/direction/place_type/show.blade.php new file mode 100644 index 0000000..4f9e14e --- /dev/null +++ b/resources/views/admin/catalog/direction/place_type/show.blade.php @@ -0,0 +1,19 @@ +@extends('layouts.admin_layout') +@section('content') + @auth() +
+

Название

+

{{ $placeType->name }}

+

Описание

+

{{ $placeType->description }}

+

URL

+

{{ $placeType->slug }}

+

Позиция

+

{{ $placeType->position }}

+

Места

+ @foreach($placeType->places as $place) +

{{ $place->name }}

+ @endforeach +
+ @endauth +@endsection diff --git a/resources/views/layouts/admin_layout.blade.php b/resources/views/layouts/admin_layout.blade.php index b17d99b..a3177a3 100644 --- a/resources/views/layouts/admin_layout.blade.php +++ b/resources/views/layouts/admin_layout.blade.php @@ -62,6 +62,8 @@
  • Типы Экзаменов
  • Предметы
  • Типы Предметов
  • +
  • Кол-во Мест
  • +
  • Типы Мест
  • @yield('content')
    diff --git a/routes/admin.php b/routes/admin.php index 57cb228..09f359e 100644 --- a/routes/admin.php +++ b/routes/admin.php @@ -6,6 +6,8 @@ use App\Http\Controllers\admin\Catalog\Direction\EducationFormController; use App\Http\Controllers\admin\Catalog\Direction\EducationLevelController; use App\Http\Controllers\admin\Catalog\Direction\EntranceExaminationController; use App\Http\Controllers\admin\Catalog\Direction\ExaminationTypeController; +use App\Http\Controllers\admin\Catalog\Direction\PlaceController; +use App\Http\Controllers\admin\Catalog\Direction\PlaceTypeController; use App\Http\Controllers\admin\Catalog\Direction\SubjectController; use App\Http\Controllers\admin\Catalog\Direction\SubjectTypeController; use App\Http\Controllers\admin\Catalog\DirectionController; @@ -56,6 +58,11 @@ Route::middleware(['auth', 'verified'])->prefix('admin')->group(function () { Route::resource('/entrance_examinations', EntranceExaminationController::class); + Route::resource('/place_types', PlaceTypeController::class) + ->scoped(['place_type' => 'slug']); + + Route::resource('/places', PlaceController::class); + Route::resources([ '/documents' => DocumentController::class, '/users' => UserController::class, diff --git a/tests/Feature/admin/catalog/EducationalInstitutionTest.php b/tests/Feature/admin/catalog/EducationalInstitutionTest.php index 163ac3e..0bb4102 100644 --- a/tests/Feature/admin/catalog/EducationalInstitutionTest.php +++ b/tests/Feature/admin/catalog/EducationalInstitutionTest.php @@ -92,7 +92,7 @@ class EducationalInstitutionTest extends TestCase $this->assertDatabaseHas('educational_institutions', $this->data); } - public function testDestroyFaculty(): void + public function testDestroyEducationalInstitution(): void { $this->faculty->delete(); $response = $this->actingAs($this->user) diff --git a/tests/Feature/admin/catalog/direction/PlaceTest.php b/tests/Feature/admin/catalog/direction/PlaceTest.php new file mode 100644 index 0000000..283d9e4 --- /dev/null +++ b/tests/Feature/admin/catalog/direction/PlaceTest.php @@ -0,0 +1,119 @@ +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', + '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(); + } + + public function testCreatePlaceTypePage(): void + { + $response = $this->actingAs($this->user) + ->withSession(['banned' => false]) + ->get(route('places.create')); + + $response->assertOk(); + } + + public function testStorePlaceType(): void + { + $response = $this->actingAs($this->user) + ->withSession(['banned' => false]) + ->post(route('places.store', $this->data)); + + $response->assertRedirect(route('places.index')); + + $this->assertDatabaseHas('places', $this->data); + } + + public function testShowPlaceTypePage(): void + { + $response = $this->actingAs($this->user) + ->withSession(['banned' => false]) + ->get(route('places.show', $this->place)); + + $response->assertOk(); + } + + public function testEditPlaceTypePage(): void + { + $response = $this->actingAs($this->user) + ->withSession(['banned' => false]) + ->get(route('places.edit', $this->place)); + + $response->assertOk(); + } + + public function testUpdatePlaceType(): void + { + $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); + } + + public function testDestroyPlaceType(): void + { + $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()); + } +} diff --git a/tests/Feature/admin/catalog/direction/PlaceTypeTest.php b/tests/Feature/admin/catalog/direction/PlaceTypeTest.php new file mode 100644 index 0000000..21f2d7f --- /dev/null +++ b/tests/Feature/admin/catalog/direction/PlaceTypeTest.php @@ -0,0 +1,102 @@ +type = PlaceType::factory()->create(); + + $this->data = PlaceType::factory()->make()->only([ + 'name', + 'description', + 'position', + 'slug', + ]); + + $this->user = User::factory()->create([ + 'name' => 'admin', + 'email' => 'test@example.com', + 'password' => 123456 + ]); + } + + public function testIndexPlaceTypesPage(): void + { + $response = $this->actingAs($this->user) + ->withSession(['banned' => false]) + ->get(route('place_types.index')); + + $response->assertOk(); + } + + public function testCreatePlaceTypePage(): void + { + $response = $this->actingAs($this->user) + ->withSession(['banned' => false]) + ->get(route('place_types.create')); + + $response->assertOk(); + } + + public function testStorePlaceType(): void + { + $response = $this->actingAs($this->user) + ->withSession(['banned' => false]) + ->post(route('place_types.store', $this->data)); + + $response->assertRedirect(route('place_types.index')); + + $this->assertDatabaseHas('place_types', $this->data); + } + + public function testShowPlaceTypePage(): void + { + $response = $this->actingAs($this->user) + ->withSession(['banned' => false]) + ->get(route('place_types.show', $this->type)); + + $response->assertOk(); + } + + public function testEditPlaceTypePage(): void + { + $response = $this->actingAs($this->user) + ->withSession(['banned' => false]) + ->get(route('place_types.edit', $this->type)); + + $response->assertOk(); + } + + public function testUpdatePlaceType(): void + { + $response = $this->actingAs($this->user) + ->withSession(['banned' => false]) + ->patch(route('place_types.update', $this->type), $this->data); + + $response->assertRedirect(route('place_types.index')); + + $this->assertDatabaseHas('place_types', $this->data); + } + + public function testDestroyPlaceType(): void + { + $response = $this->actingAs($this->user) + ->withSession(['banned' => false]) + ->delete(route('place_types.destroy', $this->type)); + + $response->assertRedirect(route('place_types.index')); + + $this->assertDatabaseMissing('place_types', $this->type->toArray()); + } +}