diff --git a/app/Http/Controllers/Catalog/DirectionController.php b/app/Http/Controllers/admin/Catalog/DirectionController.php similarity index 74% rename from app/Http/Controllers/Catalog/DirectionController.php rename to app/Http/Controllers/admin/Catalog/DirectionController.php index f65be02..04d314e 100644 --- a/app/Http/Controllers/Catalog/DirectionController.php +++ b/app/Http/Controllers/admin/Catalog/DirectionController.php @@ -1,10 +1,11 @@ validated(); $direction->name = $validated['name']; $direction->description = $validated['description']; $direction->position = $validated['position']; + $direction->slug = $validated['slug']; $direction->department_id = $validated['department_id']; $direction->save(); diff --git a/app/Http/Requests/Catalog/StoreDirectionRequest.php b/app/Http/Requests/admin/Catalog/StoreDirectionRequest.php similarity index 63% rename from app/Http/Requests/Catalog/StoreDirectionRequest.php rename to app/Http/Requests/admin/Catalog/StoreDirectionRequest.php index 5ddc838..16e0f91 100644 --- a/app/Http/Requests/Catalog/StoreDirectionRequest.php +++ b/app/Http/Requests/admin/Catalog/StoreDirectionRequest.php @@ -1,24 +1,16 @@ |string> - */ public function rules(): array { return [ diff --git a/app/Http/Requests/Catalog/UpdateDirectionRequest.php b/app/Http/Requests/admin/Catalog/UpdateDirectionRequest.php similarity index 70% rename from app/Http/Requests/Catalog/UpdateDirectionRequest.php rename to app/Http/Requests/admin/Catalog/UpdateDirectionRequest.php index e95fc9f..f5db324 100644 --- a/app/Http/Requests/Catalog/UpdateDirectionRequest.php +++ b/app/Http/Requests/admin/Catalog/UpdateDirectionRequest.php @@ -1,31 +1,24 @@ - */ public function rules(): array { return [ 'position' => 'int|max:255', 'description' => 'string', 'department_id' => 'int|required', + 'slug' => 'required|string', 'name' => [ 'required', 'string', diff --git a/app/Policies/DirectionPolicy.php b/app/Policies/DirectionPolicy.php deleted file mode 100644 index 885ae5c..0000000 --- a/app/Policies/DirectionPolicy.php +++ /dev/null @@ -1,66 +0,0 @@ - - */ class DirectionFactory extends Factory { - /** - * Define the model's default state. - * - * @return array - */ public function definition(): array { return [ - // + 'name' => fake()->name(), + 'description' => fake()->text(), + 'slug' => fake()->slug(), + 'position' => fake()->randomDigit(), + 'department_id' => 1, ]; } } diff --git a/database/seeders/DirectionSeeder.php b/database/seeders/DirectionSeeder.php index b6bbc3b..1b26f73 100644 --- a/database/seeders/DirectionSeeder.php +++ b/database/seeders/DirectionSeeder.php @@ -2,16 +2,13 @@ namespace Database\Seeders; -use Illuminate\Database\Console\Seeds\WithoutModelEvents; +use App\Models\Direction; use Illuminate\Database\Seeder; class DirectionSeeder extends Seeder { - /** - * Run the database seeds. - */ public function run(): void { - // + Direction::factory(3)->create(); } } diff --git a/resources/views/admin/catalog/department/create.blade.php b/resources/views/admin/catalog/department/create.blade.php index b8e8623..6b963be 100644 --- a/resources/views/admin/catalog/department/create.blade.php +++ b/resources/views/admin/catalog/department/create.blade.php @@ -1,6 +1,5 @@ @extends('layouts.admin-layout') @section('content') - @auth()
diff --git a/resources/views/catalog/direction/create.blade.php b/resources/views/admin/catalog/direction/create.blade.php similarity index 99% rename from resources/views/catalog/direction/create.blade.php rename to resources/views/admin/catalog/direction/create.blade.php index 46f4a5c..5f94105 100644 --- a/resources/views/catalog/direction/create.blade.php +++ b/resources/views/admin/catalog/direction/create.blade.php @@ -1,6 +1,5 @@ @extends('layouts.admin-layout') @section('content') - @auth()
diff --git a/resources/views/catalog/direction/edit.blade.php b/resources/views/admin/catalog/direction/edit.blade.php similarity index 85% rename from resources/views/catalog/direction/edit.blade.php rename to resources/views/admin/catalog/direction/edit.blade.php index 5193984..ec4d2de 100644 --- a/resources/views/catalog/direction/edit.blade.php +++ b/resources/views/admin/catalog/direction/edit.blade.php @@ -53,6 +53,17 @@ {{ $errors->first('educational_institution_id') }} @endif
+
+ {{ Form::label('slug', 'URL') }} +
+
+ {{ Form::text('slug', $direction->slug, ['class' => 'form-control']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('slug') }} + @endif +
{{ Form::submit('Изменить', ['class' => 'btn btn-primary']) }}
diff --git a/resources/views/catalog/direction/index.blade.php b/resources/views/admin/catalog/direction/index.blade.php similarity index 95% rename from resources/views/catalog/direction/index.blade.php rename to resources/views/admin/catalog/direction/index.blade.php index c1adf31..8067380 100644 --- a/resources/views/catalog/direction/index.blade.php +++ b/resources/views/admin/catalog/direction/index.blade.php @@ -13,6 +13,7 @@ Позиция Название Описание + URL Кафедра действия @@ -24,6 +25,7 @@ {{ $direction->position }} {{ $direction->name }} {{ Str::words($direction->description, 10, '...') }} + {{ $direction->slug }} {{ $direction->department->name }}
- @endsection diff --git a/resources/views/catalog/direction/show.blade.php b/resources/views/admin/catalog/direction/show.blade.php similarity index 100% rename from resources/views/catalog/direction/show.blade.php rename to resources/views/admin/catalog/direction/show.blade.php diff --git a/tests/Feature/admin/catalog/DirectionTest.php b/tests/Feature/admin/catalog/DirectionTest.php new file mode 100644 index 0000000..363e255 --- /dev/null +++ b/tests/Feature/admin/catalog/DirectionTest.php @@ -0,0 +1,108 @@ +create(); + Faculty::factory()->create(); + Department::factory()->create(); + + $this->direction = Direction::factory()->create(); + $this->data = Direction::factory()->make()->only([ + 'position', + 'name', + 'description', + 'slug', + 'department_id', + ]); + + $this->user = User::factory()->create([ + 'name' => 'admin', + 'email' => 'test@example.com', + 'password' => 123456 + ]); + } + + public function testIndexDirectionsPage(): void + { + $response = $this->actingAs($this->user) + ->withSession(['banned' => false]) + ->get(route('directions.index')); + + $response->assertOk(); + } + + public function testCreateDirectionPage(): void + { + $response = $this->actingAs($this->user) + ->withSession(['banned' => false]) + ->get(route('directions.create')); + + $response->assertOk(); + } + + public function testStoreDirection(): void + { + $response = $this->actingAs($this->user) + ->withSession(['banned' => false]) + ->post(route('directions.store', $this->data)); + + $response->assertRedirect(route('directions.index')); + + $this->assertDatabaseHas('directions', $this->data); + } + + public function testShowDirectionPage(): void + { + $response = $this->actingAs($this->user) + ->withSession(['banned' => false]) + ->get(route('directions.show', $this->direction)); + + $response->assertOk(); + } + + public function testEditDirectionPage(): void + { + $response = $this->actingAs($this->user) + ->withSession(['banned' => false]) + ->get(route('directions.edit', $this->direction)); + + $response->assertOk(); + } + + public function testUpdateDirection(): void + { + $response = $this->actingAs($this->user) + ->withSession(['banned' => false]) + ->patch(route('directions.update', $this->direction), $this->data); + + $response->assertRedirect(route('directions.index')); + + $this->assertDatabaseHas('directions', $this->data); + } + + public function testDestroyDirection(): void + { + $response = $this->actingAs($this->user) + ->withSession(['banned' => false]) + ->delete(route('directions.destroy', $this->direction)); + + $response->assertRedirect(route('directions.index')); + + $this->assertDatabaseMissing('directions', $this->direction->toArray()); + } +}