prodV1 #2

Open
RomanGolienko wants to merge 309 commits from prodV1 into main
4 changed files with 120 additions and 2 deletions
Showing only changes of commit 7d4461e231 - Show all commits

View File

@ -35,6 +35,7 @@ class DepartmentController extends Controller
$department->description = $validated['description']; $department->description = $validated['description'];
$department->position = $validated['position']; $department->position = $validated['position'];
$department->faculty_id = $validated['faculty_id']; $department->faculty_id = $validated['faculty_id'];
$department->slug = $validated['slug'];
$department->save(); $department->save();
return redirect()->route('departments.index'); return redirect()->route('departments.index');
@ -61,6 +62,7 @@ class DepartmentController extends Controller
$department->description = $validated['description']; $department->description = $validated['description'];
$department->position = $validated['position']; $department->position = $validated['position'];
$department->faculty_id = $validated['faculty_id']; $department->faculty_id = $validated['faculty_id'];
$department->slug = $validated['slug'];
$department->save(); $department->save();
return redirect()->route('departments.index'); return redirect()->route('departments.index');

View File

@ -14,8 +14,8 @@ class DepartmentFactory extends Factory
'name' => fake()->name(), 'name' => fake()->name(),
'description' => fake()->text(), 'description' => fake()->text(),
'slug' => fake()->slug(), 'slug' => fake()->slug(),
'position' => fake()->randomNumber(), 'position' => fake()->randomDigit(),
'faculty_id' => fake()->realTextBetween(1,5,1), 'faculty_id' => 1,
]; ];
} }
} }

View File

@ -53,6 +53,18 @@
{{ $errors->first('faculty_id') }} {{ $errors->first('faculty_id') }}
@endif @endif
</div> </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"> <div class="mt-3">
{{ Form::submit('Создать', ['class' => 'btn btn-primary']) }} {{ Form::submit('Создать', ['class' => 'btn btn-primary']) }}
</div> </div>

View File

@ -0,0 +1,104 @@
<?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 DepartmentTest extends TestCase
{
private User $user;
private Department $department;
private array $data;
protected function setUp(): void
{
parent::setUp();
EducationalInstitution::factory()->create();
Faculty::factory()->create();
$this->department = Department::factory()->create();
$this->data = Department::factory()->make()->only([
'position',
'name',
'description',
'slug',
'faculty_id',
]);
$this->user = User::factory()->create([
'name' => 'admin',
'email' => 'test@example.com',
'password' => 123456
]);
}
public function testIndexDepartmentsPage(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->get(route('departments.index'));
$response->assertOk();
}
public function testCreateDepartmentPage(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->get(route('departments.create'));
$response->assertOk();
}
public function testStoreDepartment(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->post(route('departments.store', $this->data));
$response->assertRedirect(route('departments.index'));
$this->assertDatabaseHas('departments', $this->data);
}
public function testShowDepartmentPage(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->get(route('departments.show', $this->department));
$response->assertOk();
}
public function testEditDepartmentPage(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->get(route('departments.edit', $this->department));
$response->assertOk();
}
public function testUpdateDepartment(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->patch(route('departments.update', $this->department), $this->data);
$response->assertRedirect(route('departments.index'));
$this->assertDatabaseHas('departments', $this->data);
}
public function testDestroyDepartment(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->delete(route('departments.destroy', $this->department));
$response->assertRedirect(route('departments.index'));
$this->assertDatabaseMissing('departments', $this->department->toArray());
}
}