forked from aslan/applicant-site
add Education Level test
This commit is contained in:
parent
75899051c7
commit
639a8c92af
|
@ -7,6 +7,7 @@ use App\Http\Requests\admin\Catalog\StoreDirectionRequest;
|
||||||
use App\Http\Requests\admin\Catalog\UpdateDirectionRequest;
|
use App\Http\Requests\admin\Catalog\UpdateDirectionRequest;
|
||||||
use App\Models\Department;
|
use App\Models\Department;
|
||||||
use App\Models\Direction;
|
use App\Models\Direction;
|
||||||
|
use App\Models\EducationLevel;
|
||||||
use App\Models\Faculty;
|
use App\Models\Faculty;
|
||||||
use Illuminate\Contracts\View\Factory;
|
use Illuminate\Contracts\View\Factory;
|
||||||
use Illuminate\Contracts\View\View;
|
use Illuminate\Contracts\View\View;
|
||||||
|
@ -23,8 +24,9 @@ class DirectionController extends Controller
|
||||||
|
|
||||||
public function create(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
|
public function create(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
|
||||||
{
|
{
|
||||||
|
$levels = EducationLevel::pluck('name', 'id');
|
||||||
$departments = Department::pluck('name', 'id');
|
$departments = Department::pluck('name', 'id');
|
||||||
return view('admin.catalog.direction.create', compact('departments'));
|
return view('admin.catalog.direction.create', compact('departments', 'levels'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function store(StoreDirectionRequest $request): RedirectResponse
|
public function store(StoreDirectionRequest $request): RedirectResponse
|
||||||
|
@ -36,6 +38,8 @@ class DirectionController extends Controller
|
||||||
$direction->description = $validated['description'];
|
$direction->description = $validated['description'];
|
||||||
$direction->position = $validated['position'];
|
$direction->position = $validated['position'];
|
||||||
$direction->slug = $validated['slug'];
|
$direction->slug = $validated['slug'];
|
||||||
|
$direction->code = $validated['code'];
|
||||||
|
$direction->education_level_id = $validated['education_level_id'];
|
||||||
$direction->department_id = $validated['department_id'];
|
$direction->department_id = $validated['department_id'];
|
||||||
$direction->save();
|
$direction->save();
|
||||||
|
|
||||||
|
@ -60,18 +64,22 @@ class DirectionController extends Controller
|
||||||
|
|
||||||
public function edit(Direction $direction): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
|
public function edit(Direction $direction): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
|
||||||
{
|
{
|
||||||
|
$levels = EducationLevel::pluck('name', 'id');
|
||||||
$departments = Department::pluck('name', 'id');
|
$departments = Department::pluck('name', 'id');
|
||||||
return view('admin.catalog.direction.edit', compact('direction', 'departments'));
|
return view('admin.catalog.direction.edit', compact('direction', 'departments', 'levels'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function update(UpdateDirectionRequest $request, Direction $direction): RedirectResponse
|
public function update(UpdateDirectionRequest $request, Direction $direction): RedirectResponse
|
||||||
{
|
{
|
||||||
$validated = $request->validated();
|
$validated = $request->validated();
|
||||||
|
|
||||||
|
$direction = new Direction();
|
||||||
$direction->name = $validated['name'];
|
$direction->name = $validated['name'];
|
||||||
$direction->description = $validated['description'];
|
$direction->description = $validated['description'];
|
||||||
$direction->position = $validated['position'];
|
$direction->position = $validated['position'];
|
||||||
$direction->slug = $validated['slug'];
|
$direction->slug = $validated['slug'];
|
||||||
|
$direction->code = $validated['code'];
|
||||||
|
$direction->education_level_id = $validated['education_level_id'];
|
||||||
$direction->department_id = $validated['department_id'];
|
$direction->department_id = $validated['department_id'];
|
||||||
$direction->save();
|
$direction->save();
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,8 @@ class StoreDirectionRequest extends FormRequest
|
||||||
'name' => 'required|string|max:255|unique:directions,name',
|
'name' => 'required|string|max:255|unique:directions,name',
|
||||||
'description' => 'string',
|
'description' => 'string',
|
||||||
'slug' => 'required|string',
|
'slug' => 'required|string',
|
||||||
|
'code' => 'required|string',
|
||||||
|
'education_level_id' => 'required|int',
|
||||||
'department_id' => 'required|int'
|
'department_id' => 'required|int'
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,8 @@ class UpdateDirectionRequest extends FormRequest
|
||||||
'description' => 'string',
|
'description' => 'string',
|
||||||
'department_id' => 'int|required',
|
'department_id' => 'int|required',
|
||||||
'slug' => 'required|string',
|
'slug' => 'required|string',
|
||||||
|
'code' => 'required|string',
|
||||||
|
'education_level_id' => 'required|int',
|
||||||
'name' => [
|
'name' => [
|
||||||
'required',
|
'required',
|
||||||
'string',
|
'string',
|
||||||
|
|
|
@ -15,10 +15,17 @@ class Direction extends Model
|
||||||
'name',
|
'name',
|
||||||
'description',
|
'description',
|
||||||
'position',
|
'position',
|
||||||
|
'slug',
|
||||||
|
'code',
|
||||||
];
|
];
|
||||||
|
|
||||||
public function department(): BelongsTo
|
public function department(): BelongsTo
|
||||||
{
|
{
|
||||||
return $this->belongsTo(Department::class);
|
return $this->belongsTo(Department::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function educationLevel(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(EducationLevel::class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,8 +12,10 @@ class DirectionFactory extends Factory
|
||||||
'name' => fake()->name(),
|
'name' => fake()->name(),
|
||||||
'description' => fake()->text(),
|
'description' => fake()->text(),
|
||||||
'slug' => fake()->slug(),
|
'slug' => fake()->slug(),
|
||||||
|
'code' => fake()->text(50),
|
||||||
'position' => fake()->randomDigit(),
|
'position' => fake()->randomDigit(),
|
||||||
'department_id' => 1,
|
'department_id' => 1,
|
||||||
|
'education_level_id' => 1
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,9 +15,11 @@ return new class extends Migration
|
||||||
$table->id();
|
$table->id();
|
||||||
$table->string('name');
|
$table->string('name');
|
||||||
$table->text('description');
|
$table->text('description');
|
||||||
|
$table->string('code');
|
||||||
$table->integer('position');
|
$table->integer('position');
|
||||||
$table->string('slug');
|
$table->string('slug');
|
||||||
$table->foreignId('department_id')->constrained('departments');
|
$table->foreignId('department_id')->constrained('departments');
|
||||||
|
$table->foreignId('education_level_id')->constrained('education_levels');
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,11 +4,40 @@ namespace Database\Seeders;
|
||||||
|
|
||||||
use App\Models\Direction;
|
use App\Models\Direction;
|
||||||
use Illuminate\Database\Seeder;
|
use Illuminate\Database\Seeder;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
class DirectionSeeder extends Seeder
|
class DirectionSeeder extends Seeder
|
||||||
{
|
{
|
||||||
public function run(): void
|
public function run(): void
|
||||||
{
|
{
|
||||||
Direction::factory(3)->create();
|
DB::table('directions')->insert([
|
||||||
|
[
|
||||||
|
'name' => 'Юриспруденция',
|
||||||
|
'description' => 'Юриспруденция',
|
||||||
|
'slug' => 'jurisprudence',
|
||||||
|
'code' => '40.03.01',
|
||||||
|
'position' => 1,
|
||||||
|
'department_id' => 1,
|
||||||
|
'education_level_id' => 1,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => 'фармация',
|
||||||
|
'description' => 'фармация',
|
||||||
|
'slug' => 'pharmacy',
|
||||||
|
'code' => '33.05.01',
|
||||||
|
'position' => 2,
|
||||||
|
'department_id' => 1,
|
||||||
|
'education_level_id' => 2,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => 'строительство',
|
||||||
|
'description' => 'строительство',
|
||||||
|
'slug' => 'construction',
|
||||||
|
'code' => '08.04.01',
|
||||||
|
'position' => 3,
|
||||||
|
'department_id' => 1,
|
||||||
|
'education_level_id' => 3,
|
||||||
|
],
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,14 +19,14 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mt-3">
|
<div class="mt-3">
|
||||||
{{ Form::label('name', 'Название') }}
|
{{ Form::label('code', 'Название') }}
|
||||||
</div>
|
</div>
|
||||||
<div class="mt-1">
|
<div class="mt-1">
|
||||||
{{ Form::text('name', '', ['class' => 'form-control']) }}
|
{{ Form::text('code', '', ['class' => 'form-control']) }}
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
@if ($errors->any())
|
@if ($errors->any())
|
||||||
{{ $errors->first('name') }}
|
{{ $errors->first('code') }}
|
||||||
@endif
|
@endif
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@
|
||||||
@endif
|
@endif
|
||||||
</div>
|
</div>
|
||||||
<div class="mt-3">
|
<div class="mt-3">
|
||||||
{{ Form::label('department_id', 'Кафедры') }}
|
{{ Form::label('department_id', 'Кафедра') }}
|
||||||
</div>
|
</div>
|
||||||
<div class="mt-1">
|
<div class="mt-1">
|
||||||
{{ Form::select('department_id', $departments, null, ['class' => 'form-select']) }}
|
{{ Form::select('department_id', $departments, null, ['class' => 'form-select']) }}
|
||||||
|
@ -52,6 +52,19 @@
|
||||||
{{ $errors->first('department_id') }}
|
{{ $errors->first('department_id') }}
|
||||||
@endif
|
@endif
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="mt-3">
|
||||||
|
{{ Form::label('education_level_id', 'Увовень образования') }}
|
||||||
|
</div>
|
||||||
|
<div class="mt-1">
|
||||||
|
{{ Form::select('education_level_id', $levels, null, ['class' => 'form-select']) }}
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
@if ($errors->any())
|
||||||
|
{{ $errors->first('education_level_id') }}
|
||||||
|
@endif
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="mt-3">
|
<div class="mt-3">
|
||||||
{{ Form::label('slug', 'URL') }}
|
{{ Form::label('slug', 'URL') }}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
@auth()
|
@auth()
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<h1 class=""> Создать кафедру</h1>
|
<h1 class="">Изменить направление</h1>
|
||||||
{{ Form::open(['url' => route('departments.update', $direction), 'method' => 'PATCH', 'class' => '']) }}
|
{{ Form::open(['url' => route('departments.update', $direction), 'method' => 'PATCH', 'class' => '']) }}
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<div class="mt-3">
|
<div class="mt-3">
|
||||||
|
@ -43,16 +43,29 @@
|
||||||
@endif
|
@endif
|
||||||
</div>
|
</div>
|
||||||
<div class="mt-3">
|
<div class="mt-3">
|
||||||
{{ Form::label('educational_institution_id', 'Факультет') }}
|
{{ Form::label('department_id', 'Факультет') }}
|
||||||
</div>
|
</div>
|
||||||
<div class="mt-1">
|
<div class="mt-1">
|
||||||
{{ Form::select('faculty_id', $departments, $direction->department->id, ['class' => 'form-select']) }}
|
{{ Form::select('department_id', $departments, $direction->department->id, ['class' => 'form-select']) }}
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
@if ($errors->any())
|
@if ($errors->any())
|
||||||
{{ $errors->first('educational_institution_id') }}
|
{{ $errors->first('department_id') }}
|
||||||
@endif
|
@endif
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="mt-3">
|
||||||
|
{{ Form::label('education_level_id', 'Увовень образования') }}
|
||||||
|
</div>
|
||||||
|
<div class="mt-1">
|
||||||
|
{{ Form::select('education_level_id', $levels, $direction->educationLevel->id, ['class' => 'form-select']) }}
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
@if ($errors->any())
|
||||||
|
{{ $errors->first('education_level_id') }}
|
||||||
|
@endif
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="mt-3">
|
<div class="mt-3">
|
||||||
{{ Form::label('slug', 'URL') }}
|
{{ Form::label('slug', 'URL') }}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
<th scope="col">Описание</th>
|
<th scope="col">Описание</th>
|
||||||
<th scope="col">URL</th>
|
<th scope="col">URL</th>
|
||||||
<th scope="col">Кафедра</th>
|
<th scope="col">Кафедра</th>
|
||||||
|
<th scope="col">Уровень образования</th>
|
||||||
<th scope="col">действия</th>
|
<th scope="col">действия</th>
|
||||||
<th scope="col"></th>
|
<th scope="col"></th>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -27,6 +28,7 @@
|
||||||
<td>{{ Str::words($direction->description, 10, '...') }}</td>
|
<td>{{ Str::words($direction->description, 10, '...') }}</td>
|
||||||
<td>{{ $direction->slug }}</td>
|
<td>{{ $direction->slug }}</td>
|
||||||
<td>{{ $direction->department->name }}</td>
|
<td>{{ $direction->department->name }}</td>
|
||||||
|
<td>{{ $direction->educationLevel->name }}</td>
|
||||||
<td>
|
<td>
|
||||||
<a href="{{ route("directions.edit", $direction) }}"
|
<a href="{{ route("directions.edit", $direction) }}"
|
||||||
class="btn btn-secondary">редактировать</a>
|
class="btn btn-secondary">редактировать</a>
|
||||||
|
|
|
@ -23,6 +23,8 @@
|
||||||
<p>{{ $direction->slug }}</p>
|
<p>{{ $direction->slug }}</p>
|
||||||
<h2>Кафедра</h2>
|
<h2>Кафедра</h2>
|
||||||
<p><a href="{{ route('departments.show', $department) }}">{{ $department->name }}</a></p>
|
<p><a href="{{ route('departments.show', $department) }}">{{ $department->name }}</a></p>
|
||||||
|
<h2>Уровень Образования</h2>
|
||||||
|
<p><a href="{{ route('education_levels.show', $direction->educationLevel) }}">{{ $direction->educationLevel->name }}</a></p>
|
||||||
</div>
|
</div>
|
||||||
@endauth
|
@endauth
|
||||||
@endsection
|
@endsection
|
||||||
|
|
|
@ -5,6 +5,7 @@ namespace Tests\Feature\admin\catalog;
|
||||||
use App\Models\Department;
|
use App\Models\Department;
|
||||||
use App\Models\Direction;
|
use App\Models\Direction;
|
||||||
use App\Models\EducationalInstitution;
|
use App\Models\EducationalInstitution;
|
||||||
|
use App\Models\EducationLevel;
|
||||||
use App\Models\Faculty;
|
use App\Models\Faculty;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
@ -19,6 +20,7 @@ class DepartmentTest extends TestCase
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
EducationalInstitution::factory()->create();
|
EducationalInstitution::factory()->create();
|
||||||
Faculty::factory()->create();
|
Faculty::factory()->create();
|
||||||
|
EducationLevel::factory()->create();
|
||||||
|
|
||||||
$this->department = Department::factory()->create();
|
$this->department = Department::factory()->create();
|
||||||
$this->data = Department::factory()->make()->only([
|
$this->data = Department::factory()->make()->only([
|
||||||
|
|
|
@ -5,6 +5,7 @@ namespace Tests\Feature\admin\catalog;
|
||||||
use App\Models\Department;
|
use App\Models\Department;
|
||||||
use App\Models\Direction;
|
use App\Models\Direction;
|
||||||
use App\Models\EducationalInstitution;
|
use App\Models\EducationalInstitution;
|
||||||
|
use App\Models\EducationLevel;
|
||||||
use App\Models\Faculty;
|
use App\Models\Faculty;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
@ -20,13 +21,16 @@ class DirectionTest extends TestCase
|
||||||
EducationalInstitution::factory()->create();
|
EducationalInstitution::factory()->create();
|
||||||
Faculty::factory()->create();
|
Faculty::factory()->create();
|
||||||
Department::factory()->create();
|
Department::factory()->create();
|
||||||
|
EducationLevel::factory()->create();
|
||||||
|
|
||||||
$this->direction = Direction::factory()->create();
|
$this->direction = Direction::factory()->create();
|
||||||
$this->data = Direction::factory()->make()->only([
|
$this->data = Direction::factory()->make()->only([
|
||||||
'position',
|
'position',
|
||||||
'name',
|
'name',
|
||||||
'description',
|
'description',
|
||||||
|
'code',
|
||||||
'slug',
|
'slug',
|
||||||
|
'education_level_id',
|
||||||
'department_id',
|
'department_id',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,121 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\admin\catalog;
|
||||||
|
|
||||||
|
use App\Models\Department;
|
||||||
|
use App\Models\Direction;
|
||||||
|
use App\Models\EducationalInstitution;
|
||||||
|
use App\Models\EducationLevel;
|
||||||
|
use App\Models\Faculty;
|
||||||
|
use App\Models\User;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class EducationLevelTest extends TestCase
|
||||||
|
{
|
||||||
|
private User $user;
|
||||||
|
private Direction $direction;
|
||||||
|
private EducationLevel $level;
|
||||||
|
private array $data;
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
EducationalInstitution::factory()->create();
|
||||||
|
Faculty::factory()->create();
|
||||||
|
Department::factory()->create();
|
||||||
|
$this->level = EducationLevel::factory()->create();
|
||||||
|
|
||||||
|
$this->direction = Direction::factory()->create();
|
||||||
|
$this->data = EducationLevel::factory()->make()->only([
|
||||||
|
'name',
|
||||||
|
'description',
|
||||||
|
'slug',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->user = User::factory()->create([
|
||||||
|
'name' => 'admin',
|
||||||
|
'email' => 'test@example.com',
|
||||||
|
'password' => 123456
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testIndexEducationLevelsPage(): void
|
||||||
|
{
|
||||||
|
$response = $this->actingAs($this->user)
|
||||||
|
->withSession(['banned' => false])
|
||||||
|
->get(route('education_levels.index'));
|
||||||
|
|
||||||
|
$response->assertOk();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCreateEducationLevelPage(): void
|
||||||
|
{
|
||||||
|
$response = $this->actingAs($this->user)
|
||||||
|
->withSession(['banned' => false])
|
||||||
|
->get(route('education_levels.create'));
|
||||||
|
|
||||||
|
$response->assertOk();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testStoreEducationLevel(): void
|
||||||
|
{
|
||||||
|
$response = $this->actingAs($this->user)
|
||||||
|
->withSession(['banned' => false])
|
||||||
|
->post(route('education_levels.store', $this->data));
|
||||||
|
|
||||||
|
$response->assertRedirect(route('education_levels.index'));
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('education_levels', $this->data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testShowEducationLevelPage(): void
|
||||||
|
{
|
||||||
|
$response = $this->actingAs($this->user)
|
||||||
|
->withSession(['banned' => false])
|
||||||
|
->get(route('education_levels.show', $this->level));
|
||||||
|
|
||||||
|
$response->assertOk();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testEditEducationLevelPage(): void
|
||||||
|
{
|
||||||
|
$response = $this->actingAs($this->user)
|
||||||
|
->withSession(['banned' => false])
|
||||||
|
->get(route('education_levels.edit', $this->level));
|
||||||
|
|
||||||
|
$response->assertOk();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUpdateEducationLevel(): void
|
||||||
|
{
|
||||||
|
$response = $this->actingAs($this->user)
|
||||||
|
->withSession(['banned' => false])
|
||||||
|
->patch(route('education_levels.update', $this->level), $this->data);
|
||||||
|
|
||||||
|
$response->assertRedirect(route('education_levels.index'));
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('education_levels', $this->data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testDestroyEducationLevel(): void
|
||||||
|
{
|
||||||
|
$this->direction->delete();
|
||||||
|
$response = $this->actingAs($this->user)
|
||||||
|
->withSession(['banned' => false])
|
||||||
|
->delete(route('education_levels.destroy', $this->level));
|
||||||
|
|
||||||
|
$response->assertRedirect(route('education_levels.index'));
|
||||||
|
|
||||||
|
$this->assertDatabaseMissing('education_levels', $this->level->toArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNotDestroyEducationLevel(): void
|
||||||
|
{
|
||||||
|
$response = $this->actingAs($this->user)
|
||||||
|
->withSession(['banned' => false])
|
||||||
|
->delete(route('education_levels.destroy', $this->level));
|
||||||
|
|
||||||
|
$response->assertStatus(302);
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('education_levels', $this->level->only(['name', 'slug']));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue