From 563b5eab8e99828bc1bf007d3ab8943605a52614 Mon Sep 17 00:00:00 2001 From: Paul Isaris Date: Thu, 24 Oct 2024 11:50:48 +0300 Subject: [PATCH 01/20] Fixed action --- .github/workflows/laravel-tests.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/laravel-tests.yml b/.github/workflows/laravel-tests.yml index acccc6dd..2e93bafd 100644 --- a/.github/workflows/laravel-tests.yml +++ b/.github/workflows/laravel-tests.yml @@ -54,6 +54,9 @@ jobs: - name: Seed run: php artisan db:seed --database=sqlite_testing --env=testing + - name: Create storage directory + run: mkdir -p storage/app/public/uploads/user_profile_img + - name: Storage Link run: php artisan storage:link --env=testing From d36cce348c7b99ccd599b6df0cad1537bd01f0cb Mon Sep 17 00:00:00 2001 From: Paul Isaris Date: Thu, 24 Oct 2024 12:16:34 +0300 Subject: [PATCH 02/20] Comment --- app/Http/Controllers/UserController.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 344b7f65..9eed7c9f 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -15,9 +15,9 @@ class UserController extends Controller { private QuestionnaireResponseManager $questionnaireResponseManager; protected UserDashboardManager $userDashboardManager; - public function __construct(UserManager $userManager, - QuestionnaireResponseManager $questionnaireResponseManager, - UserDashboardManager $userDashboardManager) { + public function __construct(UserManager $userManager, + QuestionnaireResponseManager $questionnaireResponseManager, + UserDashboardManager $userDashboardManager) { $this->userManager = $userManager; $this->questionnaireResponseManager = $questionnaireResponseManager; $this->userDashboardManager = $userDashboardManager; @@ -49,6 +49,7 @@ public function patch(Request $request) { $validationArray['password'] = 'required_with:password_confirmation|string|min:8|confirmed'; $validationArray['current_password'] = 'required|string|min:8'; } + // here we need to add custom messages for the validation, since the field is called 'avatar' and not 'profile image'. $customMessages = [ 'avatar.image' => __('validation.image', ['attribute' => __('my-account.profile_image')]), 'avatar.mimes' => __('validation.mimes', ['attribute' => __('my-account.profile_image'), 'values' => 'jpeg, png, jpg']), @@ -99,9 +100,9 @@ public function showUsersByCriteria(Request $request) { if ($users->count() == 0) { $errorMessage = 'No Users found'; - return json_encode(new OperationResponse(config('app.OPERATION_FAIL'), (string) view('partials.ajax_error_message', compact('errorMessage')))); + return json_encode(new OperationResponse(config('app.OPERATION_FAIL'), (string)view('partials.ajax_error_message', compact('errorMessage')))); } else { - return json_encode(new OperationResponse(config('app.OPERATION_SUCCESS'), (string) view('loggedin-environment.management.partials.users-list', compact('users')))); + return json_encode(new OperationResponse(config('app.OPERATION_SUCCESS'), (string)view('loggedin-environment.management.partials.users-list', compact('users')))); } } From 87c106fa52be065d071e72503d96166e17f2efe4 Mon Sep 17 00:00:00 2001 From: Paul Isaris Date: Thu, 24 Oct 2024 12:28:34 +0300 Subject: [PATCH 03/20] Fixed actions --- .github/workflows/laravel-tests.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/laravel-tests.yml b/.github/workflows/laravel-tests.yml index 2e93bafd..0f3db3f6 100644 --- a/.github/workflows/laravel-tests.yml +++ b/.github/workflows/laravel-tests.yml @@ -43,6 +43,11 @@ jobs: - name: Directory Permissions run: chmod -R 777 storage bootstrap/cache + - name: Create storage directories + run: | + mkdir -p storage/app + mkdir -p storage/app/public/uploads/user_profile_img + - name: Create Database run: | mkdir -p database @@ -54,9 +59,6 @@ jobs: - name: Seed run: php artisan db:seed --database=sqlite_testing --env=testing - - name: Create storage directory - run: mkdir -p storage/app/public/uploads/user_profile_img - - name: Storage Link run: php artisan storage:link --env=testing From 09f607e95e59959b8ddf6d9f946959801709915d Mon Sep 17 00:00:00 2001 From: Kostas Papandreou Date: Thu, 24 Oct 2024 12:29:15 +0300 Subject: [PATCH 04/20] IP-188: quick 'n' dirty problem creation form --- .../CrowdSourcingProjectProblemController.php | 78 +++++++ .../Problem/CrowdSourcingProjectProblem.php | 2 +- .../Problem/CreateEditProblem.php | 13 ++ .../partials/basic-details.blade.php | 2 +- .../problem/create-edit/form-page.blade.php | 196 ++++++++++++++++++ .../management/problem/index.blade.php | 20 ++ routes/web.php | 1 + 7 files changed, 310 insertions(+), 2 deletions(-) create mode 100644 app/ViewModels/CrowdSourcingProject/Problem/CreateEditProblem.php create mode 100644 resources/views/loggedin-environment/management/problem/create-edit/form-page.blade.php create mode 100644 resources/views/loggedin-environment/management/problem/index.blade.php diff --git a/app/Http/Controllers/CrowdSourcingProject/Problem/CrowdSourcingProjectProblemController.php b/app/Http/Controllers/CrowdSourcingProject/Problem/CrowdSourcingProjectProblemController.php index c5b400a9..952a9441 100644 --- a/app/Http/Controllers/CrowdSourcingProject/Problem/CrowdSourcingProjectProblemController.php +++ b/app/Http/Controllers/CrowdSourcingProject/Problem/CrowdSourcingProjectProblemController.php @@ -4,6 +4,9 @@ use App\BusinessLogicLayer\CrowdSourcingProject\Problem\CrowdSourcingProjectProblemManager; use App\Http\Controllers\Controller; +use App\Models\CrowdSourcingProject\Problem\CrowdSourcingProjectProblem; +use App\Models\CrowdSourcingProject\Problem\CrowdSourcingProjectProblemTranslation; +use App\ViewModels\CrowdSourcingProject\Problem\CreateEditProblem; use Illuminate\Database\Eloquent\ModelNotFoundException; use Illuminate\Http\Request; use Illuminate\Support\Facades\Validator; @@ -33,4 +36,79 @@ public function showProblemsPage(Request $request) { abort(ResponseAlias::HTTP_NOT_FOUND); } } + + /** + * Display a listing of the resource. + */ + public function index() + { + $viewModel = []; + $viewModel['problems'] = CrowdSourcingProjectProblem::with('translations')->latest()->get(); + return view('loggedin-environment.management.problem.index', ['viewModel' => $viewModel]); + } + + /** + * Show the form for creating a new resource. + */ + public function create() + { + $newProblem = new CrowdSourcingProjectProblem(); + $newProblem->default_language_id = 6; // @todo change with lookuptable value - bookmark2 + $newProblem->setRelation('defaultTranslation', new CrowdSourcingProjectProblemTranslation()); // bookmark2 - is this an "empty" relationship? + $viewModel = new CreateEditProblem($newProblem); + return view('loggedin-environment.management.problem.create-edit.form-page'); + } + + /** + * Store a newly created resource in storage. + */ + public function store(Request $request) + { + request()->validate([ // bookmark2 + 'problem-title' => ['required'], + 'problem-description' => ['required'], + 'problem-status' => ['required'], // bookmark2 + 'problem-default-language' => ['required'], // bookmark2 + ]); + + $crowdSourcingProjectProblem = CrowdSourcingProjectProblem::create([ + 'project_id' => '3', // bookmark2 + 'user_creator_id' => '2', // bookmark2 + 'slug' => 'test-slug-1', // bookmark2 + 'status_id' => request('problem-status'), // bookmark2 + 'img_url' => 'zxcv', // bookmark2 + 'default_language_id' => request('problem-default-language'), // bookmark2 - default or generally another translation language? + ]); + + $crowdSourcingProjectProblemTranslation = $crowdSourcingProjectProblem->defaultTranslation()->create([ // bookmark2 - default or regular translation? + 'title' => request('problem-title'), + 'description' => request('problem-description'), + ]); + + return redirect()->route('problems.index'); + } + + /** + * Show the form for editing the specified resource. + */ + public function edit(string $id) + { + // + } + + /** + * Update the specified resource in storage. + */ + public function update(Request $request, string $id) + { + // + } + + /** + * Remove the specified resource from storage. + */ + public function destroy(string $id) + { + // + } } diff --git a/app/Models/CrowdSourcingProject/Problem/CrowdSourcingProjectProblem.php b/app/Models/CrowdSourcingProject/Problem/CrowdSourcingProjectProblem.php index 7182bb0f..9868472b 100644 --- a/app/Models/CrowdSourcingProject/Problem/CrowdSourcingProjectProblem.php +++ b/app/Models/CrowdSourcingProject/Problem/CrowdSourcingProjectProblem.php @@ -15,7 +15,7 @@ class CrowdSourcingProjectProblem extends Model { use SoftDeletes; protected $table = 'crowd_sourcing_project_problems'; - protected $fillable = ['id', 'project_id', 'slug', 'status_id', 'img_url', 'default_language_id']; + protected $fillable = ['id', 'project_id', 'user_creator_id', 'slug', 'status_id', 'img_url', 'default_language_id']; public function defaultTranslation(): HasOne { return $this->hasOne(CrowdSourcingProjectProblemTranslation::class, diff --git a/app/ViewModels/CrowdSourcingProject/Problem/CreateEditProblem.php b/app/ViewModels/CrowdSourcingProject/Problem/CreateEditProblem.php new file mode 100644 index 00000000..4fef6f32 --- /dev/null +++ b/app/ViewModels/CrowdSourcingProject/Problem/CreateEditProblem.php @@ -0,0 +1,13 @@ +crowdSourcingProjectProblem = $crowdSourcingProjectProblem; + } + +} \ No newline at end of file diff --git a/resources/views/loggedin-environment/management/crowdsourcing-project/create-edit/partials/basic-details.blade.php b/resources/views/loggedin-environment/management/crowdsourcing-project/create-edit/partials/basic-details.blade.php index 8c0c78f2..e8135bc2 100644 --- a/resources/views/loggedin-environment/management/crowdsourcing-project/create-edit/partials/basic-details.blade.php +++ b/resources/views/loggedin-environment/management/crowdsourcing-project/create-edit/partials/basic-details.blade.php @@ -90,7 +90,7 @@
- + + {{ $errors->first('problem-title') }} +
+
+
+ +
+ +
+
+ + {{ $errors->first('problem-description') }} +
+
+
+ +
+ +
+
+ + {{ $errors->first('problem-status') }} +
+
+
+ + + +
+ +
+
+ + {{ $errors->first('problem-default-language') }} +
+
+
+ + + + {{--
+ +
+
+ + {{ $errors->first('slug') }} +
+
+
--}} + + + + + + + + + + diff --git a/resources/views/loggedin-environment/management/problem/index.blade.php b/resources/views/loggedin-environment/management/problem/index.blade.php new file mode 100644 index 00000000..53e33d27 --- /dev/null +++ b/resources/views/loggedin-environment/management/problem/index.blade.php @@ -0,0 +1,20 @@ +@php + // var_dump($viewModel); +@endphp + +
    + @foreach ($viewModel['problems'] as $problem) +
  1. + id: {{ $problem->id }}
    + slug: {{ $problem->slug }}
    + default_language_id: {{ $problem->default_language_id }}
    + @foreach ($problem->translations as $translation) + @if ($translation->language_id === $problem->default_language_id) + default_lang_title: {{ $translation->title }}
    + default_lang_desc: {{ $translation->description }}
    + @endif + @endforeach +
  2. +
    + @endforeach +
diff --git a/routes/web.php b/routes/web.php index 3ea750f5..e446dc66 100644 --- a/routes/web.php +++ b/routes/web.php @@ -73,6 +73,7 @@ Route::post('/questionnaire/update-status', [QuestionnaireController::class, 'saveQuestionnaireStatus'])->name('questionnaire.update-status'); Route::get('/questionnaires/{questionnaire}/colors', [QuestionnaireStatisticsController::class, 'showEditStatisticsColorsPage'])->name('questionnaire.statistics-colors'); Route::post('/questionnaires/{questionnaire}/colors', [QuestionnaireStatisticsController::class, 'saveStatisticsColors'])->name('questionnaire.statistics-colors.store'); + Route::resource('problems', CrowdSourcingProjectProblemController::class)->except(['show']); }); Route::group(['middleware' => ['auth', 'can:moderate-content-by-users']], function () { From 6d5adb5677dff7354af525e743670cf5c2dd0380 Mon Sep 17 00:00:00 2001 From: Paul Isaris Date: Fri, 25 Oct 2024 08:03:25 +0300 Subject: [PATCH 05/20] Test commit for Husky pre-commit hook --- .husky/pre-commit | 5 +++++ .../CrowdSourcingProjectProblemController.php | 1 + package-lock.json | 17 +++++++++++++++++ package.json | 4 +++- 4 files changed, 26 insertions(+), 1 deletion(-) create mode 100755 .husky/pre-commit diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100755 index 00000000..7d4d4120 --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1,5 @@ +# .husky/pre-commit +#!/bin/sh +. "$(dirname "$0")/_/husky.sh" + +vendor/bin/pint diff --git a/app/Http/Controllers/CrowdSourcingProject/Problem/CrowdSourcingProjectProblemController.php b/app/Http/Controllers/CrowdSourcingProject/Problem/CrowdSourcingProjectProblemController.php index 952a9441..32960bbc 100644 --- a/app/Http/Controllers/CrowdSourcingProject/Problem/CrowdSourcingProjectProblemController.php +++ b/app/Http/Controllers/CrowdSourcingProject/Problem/CrowdSourcingProjectProblemController.php @@ -42,6 +42,7 @@ public function showProblemsPage(Request $request) { */ public function index() { + $viewModel = []; $viewModel['problems'] = CrowdSourcingProjectProblem::with('translations')->latest()->get(); return view('loggedin-environment.management.problem.index', ['viewModel' => $viewModel]); diff --git a/package-lock.json b/package-lock.json index a6bc0160..d3c9b7b3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -56,6 +56,7 @@ "eslint-plugin-prefer-arrow": "^1.2.3", "eslint-plugin-vue": "^9.28.0", "goodparts": "^1.3.0", + "husky": "^9.1.6", "laravel-vite-plugin": "^1.0.5", "postcss": "^8.4.47", "prettier": "^3.3.3", @@ -4001,6 +4002,22 @@ "he": "bin/he" } }, + "node_modules/husky": { + "version": "9.1.6", + "resolved": "https://registry.npmjs.org/husky/-/husky-9.1.6.tgz", + "integrity": "sha512-sqbjZKK7kf44hfdE94EoX8MZNk0n7HeW37O4YrVGCF4wzgQjp+akPAkfUK5LZ6KuR/6sqeAVuXHji+RzQgOn5A==", + "dev": true, + "license": "MIT", + "bin": { + "husky": "bin.js" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/typicode" + } + }, "node_modules/icheck": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/icheck/-/icheck-1.0.2.tgz", diff --git a/package.json b/package.json index d753a321..e713b315 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,8 @@ "format": "prettier --write \"resources/assets/\"", "dev": "vite", "build": "vite build", - "prod": "cross-env NODE_ENV=production NODE_OPTIONS=--max-old-space-size=7680 vite build" + "prod": "cross-env NODE_ENV=production NODE_OPTIONS=--max-old-space-size=7680 vite build", + "prepare": "husky install" }, "devDependencies": { "@vitejs/plugin-vue": "^5.1.4", @@ -26,6 +27,7 @@ "eslint-plugin-prefer-arrow": "^1.2.3", "eslint-plugin-vue": "^9.28.0", "goodparts": "^1.3.0", + "husky": "^9.1.6", "laravel-vite-plugin": "^1.0.5", "postcss": "^8.4.47", "prettier": "^3.3.3", From a62df94f7548916a32d6a638e6c1f3d96a4d38ee Mon Sep 17 00:00:00 2001 From: Paul Isaris Date: Fri, 25 Oct 2024 08:06:52 +0300 Subject: [PATCH 06/20] Husky hook --- .husky/pre-commit | 5 +--- .../CrowdSourcingProjectProblemController.php | 29 ++++++++----------- app/Http/Controllers/UserController.php | 10 +++---- .../Problem/CreateEditProblem.php | 4 +-- 4 files changed, 20 insertions(+), 28 deletions(-) diff --git a/.husky/pre-commit b/.husky/pre-commit index 7d4d4120..197c0fb0 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,5 +1,2 @@ -# .husky/pre-commit -#!/bin/sh -. "$(dirname "$0")/_/husky.sh" - +# Run Pint to beautify the code vendor/bin/pint diff --git a/app/Http/Controllers/CrowdSourcingProject/Problem/CrowdSourcingProjectProblemController.php b/app/Http/Controllers/CrowdSourcingProject/Problem/CrowdSourcingProjectProblemController.php index 32960bbc..1c25030f 100644 --- a/app/Http/Controllers/CrowdSourcingProject/Problem/CrowdSourcingProjectProblemController.php +++ b/app/Http/Controllers/CrowdSourcingProject/Problem/CrowdSourcingProjectProblemController.php @@ -40,38 +40,36 @@ public function showProblemsPage(Request $request) { /** * Display a listing of the resource. */ - public function index() - { - + public function index() { $viewModel = []; $viewModel['problems'] = CrowdSourcingProjectProblem::with('translations')->latest()->get(); + return view('loggedin-environment.management.problem.index', ['viewModel' => $viewModel]); } /** * Show the form for creating a new resource. */ - public function create() - { - $newProblem = new CrowdSourcingProjectProblem(); + public function create() { + $newProblem = new CrowdSourcingProjectProblem; $newProblem->default_language_id = 6; // @todo change with lookuptable value - bookmark2 - $newProblem->setRelation('defaultTranslation', new CrowdSourcingProjectProblemTranslation()); // bookmark2 - is this an "empty" relationship? + $newProblem->setRelation('defaultTranslation', new CrowdSourcingProjectProblemTranslation); // bookmark2 - is this an "empty" relationship? $viewModel = new CreateEditProblem($newProblem); + return view('loggedin-environment.management.problem.create-edit.form-page'); } /** * Store a newly created resource in storage. */ - public function store(Request $request) - { + public function store(Request $request) { request()->validate([ // bookmark2 'problem-title' => ['required'], 'problem-description' => ['required'], 'problem-status' => ['required'], // bookmark2 'problem-default-language' => ['required'], // bookmark2 ]); - + $crowdSourcingProjectProblem = CrowdSourcingProjectProblem::create([ 'project_id' => '3', // bookmark2 'user_creator_id' => '2', // bookmark2 @@ -80,7 +78,7 @@ public function store(Request $request) 'img_url' => 'zxcv', // bookmark2 'default_language_id' => request('problem-default-language'), // bookmark2 - default or generally another translation language? ]); - + $crowdSourcingProjectProblemTranslation = $crowdSourcingProjectProblem->defaultTranslation()->create([ // bookmark2 - default or regular translation? 'title' => request('problem-title'), 'description' => request('problem-description'), @@ -92,24 +90,21 @@ public function store(Request $request) /** * Show the form for editing the specified resource. */ - public function edit(string $id) - { + public function edit(string $id) { // } /** * Update the specified resource in storage. */ - public function update(Request $request, string $id) - { + public function update(Request $request, string $id) { // } /** * Remove the specified resource from storage. */ - public function destroy(string $id) - { + public function destroy(string $id) { // } } diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 9eed7c9f..840fbe6e 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -15,9 +15,9 @@ class UserController extends Controller { private QuestionnaireResponseManager $questionnaireResponseManager; protected UserDashboardManager $userDashboardManager; - public function __construct(UserManager $userManager, - QuestionnaireResponseManager $questionnaireResponseManager, - UserDashboardManager $userDashboardManager) { + public function __construct(UserManager $userManager, + QuestionnaireResponseManager $questionnaireResponseManager, + UserDashboardManager $userDashboardManager) { $this->userManager = $userManager; $this->questionnaireResponseManager = $questionnaireResponseManager; $this->userDashboardManager = $userDashboardManager; @@ -100,9 +100,9 @@ public function showUsersByCriteria(Request $request) { if ($users->count() == 0) { $errorMessage = 'No Users found'; - return json_encode(new OperationResponse(config('app.OPERATION_FAIL'), (string)view('partials.ajax_error_message', compact('errorMessage')))); + return json_encode(new OperationResponse(config('app.OPERATION_FAIL'), (string) view('partials.ajax_error_message', compact('errorMessage')))); } else { - return json_encode(new OperationResponse(config('app.OPERATION_SUCCESS'), (string)view('loggedin-environment.management.partials.users-list', compact('users')))); + return json_encode(new OperationResponse(config('app.OPERATION_SUCCESS'), (string) view('loggedin-environment.management.partials.users-list', compact('users')))); } } diff --git a/app/ViewModels/CrowdSourcingProject/Problem/CreateEditProblem.php b/app/ViewModels/CrowdSourcingProject/Problem/CreateEditProblem.php index 4fef6f32..0000f412 100644 --- a/app/ViewModels/CrowdSourcingProject/Problem/CreateEditProblem.php +++ b/app/ViewModels/CrowdSourcingProject/Problem/CreateEditProblem.php @@ -6,8 +6,8 @@ class CreateEditProblem { public CrowdSourcingProjectProblem $crowdSourcingProjectProblem; + public function __construct(CrowdSourcingProjectProblem $crowdSourcingProjectProblem) { $this->crowdSourcingProjectProblem = $crowdSourcingProjectProblem; } - -} \ No newline at end of file +} From a9ef7219d2c522093fc514dcea6aa62dceafa559 Mon Sep 17 00:00:00 2001 From: Paul Isaris Date: Fri, 25 Oct 2024 08:14:20 +0300 Subject: [PATCH 07/20] husky script --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e713b315..75430c6a 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "dev": "vite", "build": "vite build", "prod": "cross-env NODE_ENV=production NODE_OPTIONS=--max-old-space-size=7680 vite build", - "prepare": "husky install" + "prepare": "husky install && chmod +x .husky/*" }, "devDependencies": { "@vitejs/plugin-vue": "^5.1.4", From df064a229d6c22a8434317d86abac95d7bdc0da2 Mon Sep 17 00:00:00 2001 From: Paul Isaris Date: Fri, 25 Oct 2024 08:28:24 +0300 Subject: [PATCH 08/20] Added check for directory --- tests/Feature/Controllers/UserControllerTest.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/Feature/Controllers/UserControllerTest.php b/tests/Feature/Controllers/UserControllerTest.php index f81e8238..b09568f2 100644 --- a/tests/Feature/Controllers/UserControllerTest.php +++ b/tests/Feature/Controllers/UserControllerTest.php @@ -80,6 +80,10 @@ public function patchUpdatesUserProfileWithValidData() { /** @test */ public function patchUpdatesUserProfileWithValidDataWithImage() { + // Ensure the directory exists + if (!file_exists(storage_path('app'))) { + mkdir(storage_path('app'), 0777, true); + } $user = User::factory()->create(); $this->be($user); $faker = Faker::create(); @@ -115,6 +119,10 @@ public function patchUpdatesUserProfileWithValidDataWithImage() { /** @test */ public function patchUpdatesUserProfileWithInvalidImage() { + // Ensure the directory exists + if (!file_exists(storage_path('app'))) { + mkdir(storage_path('app'), 0777, true); + } $user = User::factory()->create(); $this->be($user); $faker = Faker::create(); @@ -143,6 +151,10 @@ public function patchUpdatesUserProfileWithInvalidImage() { /** @test */ public function pathUpdatesUserProfileWithVeryBigImage() { + // Ensure the directory exists + if (!file_exists(storage_path('app'))) { + mkdir(storage_path('app'), 0777, true); + } $user = User::factory()->create(); $this->be($user); $faker = Faker::create(); From a625e18797f0dba6793b470f6eec002dcc858f40 Mon Sep 17 00:00:00 2001 From: Paul Isaris Date: Fri, 25 Oct 2024 08:33:02 +0300 Subject: [PATCH 09/20] setUp --- .../Controllers/UserControllerTest.php | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/Feature/Controllers/UserControllerTest.php b/tests/Feature/Controllers/UserControllerTest.php index b09568f2..572d28d7 100644 --- a/tests/Feature/Controllers/UserControllerTest.php +++ b/tests/Feature/Controllers/UserControllerTest.php @@ -18,6 +18,18 @@ class UserControllerTest extends TestCase { protected $seed = true; + protected function setUp(): void { + parent::setUp(); + + // Ensure the directory exists for testing + $storagePath = storage_path('app'); + if (!is_dir($storagePath)) { + if (!mkdir($storagePath, 0777, true) && !is_dir($storagePath)) { + $this->fail("Failed to create the directory: {$storagePath}"); + } + } + } + /** @test */ public function myDashboardDisplaysDashboardForAuthenticated_user() { $user = User::factory()->create(); @@ -80,10 +92,6 @@ public function patchUpdatesUserProfileWithValidData() { /** @test */ public function patchUpdatesUserProfileWithValidDataWithImage() { - // Ensure the directory exists - if (!file_exists(storage_path('app'))) { - mkdir(storage_path('app'), 0777, true); - } $user = User::factory()->create(); $this->be($user); $faker = Faker::create(); @@ -119,10 +127,6 @@ public function patchUpdatesUserProfileWithValidDataWithImage() { /** @test */ public function patchUpdatesUserProfileWithInvalidImage() { - // Ensure the directory exists - if (!file_exists(storage_path('app'))) { - mkdir(storage_path('app'), 0777, true); - } $user = User::factory()->create(); $this->be($user); $faker = Faker::create(); @@ -151,10 +155,6 @@ public function patchUpdatesUserProfileWithInvalidImage() { /** @test */ public function pathUpdatesUserProfileWithVeryBigImage() { - // Ensure the directory exists - if (!file_exists(storage_path('app'))) { - mkdir(storage_path('app'), 0777, true); - } $user = User::factory()->create(); $this->be($user); $faker = Faker::create(); From 823a4c5e50c67ceaaa626c5d8beb2c67e62bdcfa Mon Sep 17 00:00:00 2001 From: Paul Isaris Date: Fri, 25 Oct 2024 08:37:32 +0300 Subject: [PATCH 10/20] setUp --- tests/Feature/Controllers/UserControllerTest.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/Feature/Controllers/UserControllerTest.php b/tests/Feature/Controllers/UserControllerTest.php index 572d28d7..299d9c07 100644 --- a/tests/Feature/Controllers/UserControllerTest.php +++ b/tests/Feature/Controllers/UserControllerTest.php @@ -16,15 +16,18 @@ class UserControllerTest extends TestCase { use RefreshDatabase; - protected $seed = true; + protected bool $seed = true; protected function setUp(): void { parent::setUp(); // Ensure the directory exists for testing $storagePath = storage_path('app'); + echo "Storage path: {$storagePath}\n"; if (!is_dir($storagePath)) { + echo "Creating the directory: {$storagePath}\n"; if (!mkdir($storagePath, 0777, true) && !is_dir($storagePath)) { + echo "Failed to create the directory: {$storagePath}\n"; $this->fail("Failed to create the directory: {$storagePath}"); } } From c49e5142db5cf41be14410ebff7b5ba735e4e858 Mon Sep 17 00:00:00 2001 From: Paul Isaris Date: Fri, 25 Oct 2024 08:43:16 +0300 Subject: [PATCH 11/20] setUp --- tests/Feature/Controllers/UserControllerTest.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/Feature/Controllers/UserControllerTest.php b/tests/Feature/Controllers/UserControllerTest.php index 299d9c07..556b188f 100644 --- a/tests/Feature/Controllers/UserControllerTest.php +++ b/tests/Feature/Controllers/UserControllerTest.php @@ -23,13 +23,18 @@ protected function setUp(): void { // Ensure the directory exists for testing $storagePath = storage_path('app'); - echo "Storage path: {$storagePath}\n"; if (!is_dir($storagePath)) { - echo "Creating the directory: {$storagePath}\n"; + echo "Storage path does not exist. Creating the directory: {$storagePath}\n"; if (!mkdir($storagePath, 0777, true) && !is_dir($storagePath)) { echo "Failed to create the directory: {$storagePath}\n"; $this->fail("Failed to create the directory: {$storagePath}"); } + // also create the tree of directories for user_profile_img + $userProfileImgPath = $storagePath . '/public/uploads/user_profile_img'; + if (!mkdir($userProfileImgPath, 0777, true) && !is_dir($userProfileImgPath)) { + echo "Failed to create the directory: {$userProfileImgPath}\n"; + $this->fail("Failed to create the directory: {$userProfileImgPath}"); + } } } From 80b58c2672219fb458f3ebe8271f95d11ba6ddb8 Mon Sep 17 00:00:00 2001 From: Paul Isaris Date: Fri, 25 Oct 2024 09:34:35 +0300 Subject: [PATCH 12/20] fixed storage in tests --- .../partials/header-controls.blade.php | 20 +++--- storage/storage/storage_initialized.lock | 0 .../Controllers/UserControllerTest.php | 24 +++---- tests/StorageInitializer.php | 66 +++++++++++++++++++ 4 files changed, 85 insertions(+), 25 deletions(-) create mode 100644 storage/storage/storage_initialized.lock create mode 100644 tests/StorageInitializer.php diff --git a/resources/views/loggedin-environment/partials/header-controls.blade.php b/resources/views/loggedin-environment/partials/header-controls.blade.php index 7f47b45a..bec3030d 100644 --- a/resources/views/loggedin-environment/partials/header-controls.blade.php +++ b/resources/views/loggedin-environment/partials/header-controls.blade.php @@ -1,17 +1,12 @@