From 4378fa2d7d4f157efa33538ac2b5bb20e4468bea Mon Sep 17 00:00:00 2001 From: Xu Date: Thu, 10 Aug 2023 11:33:06 +0200 Subject: [PATCH] fix tests after ifsg implementation --- DEVELOPMENT.md | 4 +++ config/config.default.php | 2 +- ...requires_ifsg_cerificate_to_angeltypes.php | 2 +- .../user_driver_licenses_controller.php | 22 +++++++++++++ includes/sys_menu.php | 1 + includes/view/AngelTypes_view.php | 12 +++---- includes/view/User_view.php | 2 +- resources/lang/de_DE/default.po | 23 +++++++++---- resources/lang/en_US/default.po | 25 ++++++++++----- .../views/pages/settings/certificates.twig | 2 +- src/Controllers/Metrics/Stats.php | 20 ++++++------ src/Controllers/SettingsController.php | 8 +++-- src/Models/User/License.php | 32 +++++++++---------- .../Controllers/Metrics/ControllerTest.php | 6 ++-- tests/Unit/Controllers/Metrics/StatsTest.php | 4 +-- 15 files changed, 106 insertions(+), 59 deletions(-) diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index d2a03217..6e5a7f3b 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -13,10 +13,14 @@ Please ensure that your pull requests follow the [PSR-12](https://www.php-fig.or You can check that by running ```bash composer run phpcs +# with docker +docker exec engelsystem_dev-es_workspace-1 composer run phpcs ``` You may auto fix reported issues by running ```bash composer run phpcbf +# with docker +docker exec engelsystem_dev-es_workspace-1 composer run phpcbf ``` ## Pre-commit hooks diff --git a/config/config.default.php b/config/config.default.php index 745d51ef..55982230 100644 --- a/config/config.default.php +++ b/config/config.default.php @@ -324,7 +324,7 @@ return [ ], # Instruction in accordance with § 43 Para. 1 of the German Infection Protection Act (IfSG) - 'ifsg_enabled' => (bool) env('IFSG_ENABLED', true), + 'ifsg_enabled' => (bool) env('IFSG_ENABLED', false), // Available locales in /resources/lang/ 'locales' => [ diff --git a/db/migrations/2023_08_08_000000_add_requires_ifsg_cerificate_to_angeltypes.php b/db/migrations/2023_08_08_000000_add_requires_ifsg_cerificate_to_angeltypes.php index 00b3e5b8..840c0979 100644 --- a/db/migrations/2023_08_08_000000_add_requires_ifsg_cerificate_to_angeltypes.php +++ b/db/migrations/2023_08_08_000000_add_requires_ifsg_cerificate_to_angeltypes.php @@ -30,4 +30,4 @@ class AddRequiresIfsgCerificateToAngeltypes extends Migration $table->dropColumn('requires_ifsg_certificate'); }); } -} \ No newline at end of file +} diff --git a/includes/controller/user_driver_licenses_controller.php b/includes/controller/user_driver_licenses_controller.php index d1977656..730bd665 100644 --- a/includes/controller/user_driver_licenses_controller.php +++ b/includes/controller/user_driver_licenses_controller.php @@ -30,6 +30,28 @@ function user_driver_license_required_hint() return null; } +function user_ifsg_certificate_required_hint() +{ + $user = auth()->user(); + + // User has already entered data, no hint needed. + if ($user->license->ifsg) { + return null; + } + + $angeltypes = $user->userAngelTypes; + foreach ($angeltypes as $angeltype) { + if ($angeltype->requires_ifsg_certificate) { + return sprintf( + __('angeltype.ifsg.required.info.here'), + '' . __('ifsg.info') . '' + ); + } + } + + return null; +} + /** * Route user driver licenses actions. * diff --git a/includes/sys_menu.php b/includes/sys_menu.php index 806694cc..815c604c 100644 --- a/includes/sys_menu.php +++ b/includes/sys_menu.php @@ -31,6 +31,7 @@ function header_render_hints() $hints_renderer->addHint(user_angeltypes_unconfirmed_hint()); $hints_renderer->addHint(render_user_departure_date_hint()); $hints_renderer->addHint(user_driver_license_required_hint()); + $hints_renderer->addHint(user_ifsg_certificate_required_hint()); // Important hints: $hints_renderer->addHint(render_user_freeloader_hint(), true); diff --git a/includes/view/AngelTypes_view.php b/includes/view/AngelTypes_view.php index f2e1fe55..044a5b93 100644 --- a/includes/view/AngelTypes_view.php +++ b/includes/view/AngelTypes_view.php @@ -111,16 +111,16 @@ function AngelType_edit_view(AngelType $angeltype, bool $supporter_mode) __('Requires driver license'), $angeltype->requires_driver_license ), - $supporter_mode && config('ifsg_enabled')? + $supporter_mode && config('ifsg_enabled') ? form_info( - __('requires IfSG certificate'), + __('angeltype.ifsg.required'), $angeltype->requires_ifsg_certificate ? __('Yes') : __('No') ) : form_checkbox( 'requires_ifsg_certificate', - __('requires IfSG certificate'), + __('angeltype.ifsg.required'), $angeltype->requires_ifsg_certificate ), $supporter_mode @@ -175,8 +175,8 @@ function AngelType_view_buttons( } if ($angeltype->requires_ifsg_certificate) { $buttons[] = button( - user_driver_license_edit_link($user), - icon('card-checklist') . __('my ifsg certificate') + url('/settings/certificates'), + icon('card-checklist') . __('angeltype.ifsg.own') ); } @@ -192,7 +192,7 @@ function AngelType_view_buttons( } if ($angeltype->requires_ifsg_certificate && !$user->license->ifsg_certificate) { - error(__('This angeltype requires an ifsg certificate. Please enter your ifsg certificate information!')); + error(__('angeltype.ifsg.required.info')); } if ($angeltype->restricted && !$user_angeltype->confirm_user_id) { diff --git a/includes/view/User_view.php b/includes/view/User_view.php index 486ecf34..a1080e03 100644 --- a/includes/view/User_view.php +++ b/includes/view/User_view.php @@ -567,7 +567,7 @@ function User_view( ) : '', config('ifsg_enabled') && ($admin_user_privilege || ($its_me && $needs_drivers_license)) ? button( page_link_to('settings/certificates'), - icon('card-checklist') . __('ifsg certificate') + icon('card-checklist') . __('ifsg.certificate') ) : '', (($admin_user_privilege || $auth->can('admin_arrive')) && !$user_source->state->arrived) ? form([ diff --git a/resources/lang/de_DE/default.po b/resources/lang/de_DE/default.po index 31fecc0c..b17e376a 100644 --- a/resources/lang/de_DE/default.po +++ b/resources/lang/de_DE/default.po @@ -2214,26 +2214,35 @@ msgid "settings.certificates.info" msgstr "Hier kannst du deine gemachte Gesundheitsbelehrung eintragen" msgid "settings.ifsg" -msgstr "Frikadellendiplom light: Du wurdest von c3gelb vor Ort nach ISfG §43 belehrt." +msgstr "Ich wurde vor Ort nach IfSG §43 (Frikadellendiplom light) belehrt." msgid "settings.ifsg_full" -msgstr "Frikadellendiplom: Du hast eine Belehrung nach §43 ISfG bei deinem Gesundheitsamt erhalten und innerhalb von 3 Monaten die Zweitbelehrung durch uns oder deinen Arbeitgeber/Koch/Verein bekommen. Zusätzlich ist die Zweibelehrung nicht älter als zwei Jahre." +msgstr "Ich habe eine Belehrung nach §43 IfSG (Frikadellendiplom) bei meinem Gesundheitsamt " +"erhalten und innerhalb von 3 Monaten die Zweitbelehrung durch uns oder meinen Arbeitgeber/Koch/Verein bekommen. " +"Zusätzlich ist die Zweitbelehrung nicht älter als zwei Jahre." msgid "settings.certificates.success" msgstr "Gesundheitsbelehrung wurde erfolgreich geändert." -msgid "requires IfSG certificate" -msgstr "benötigt eine Gesundheitsbelehrung" +msgid "angeltype.ifsg.required" +msgstr "Benötigt eine Gesundheitsbelehrung" -msgid "ifsg certificate" +msgid "ifsg.certificate" msgstr "Gesundheitsbelehrung" -msgid "my ifsg certificate" +msgid "angeltype.ifsg.own" msgstr "Meine Gesundheitsbelehrung" -msgid "This angeltype requires an ifsg certificate. Please enter your ifsg certificate information!" +msgid "angeltype.ifsg.required.info" msgstr "Dieser Engeltyp benötigt eine Gesundheitsbelehrung. Bitte trage deine Gesundheitsbelehrung ein!" +msgid "angeltype.ifsg.required.info.here" +msgstr "Dieser Engeltyp benötigt eine Gesundheitsbelehrung. " +"Bitte trage deine Gesundheitsbelehrung hier ein: %s" + +msgid "ifsg.info" +msgstr "Gesundheitsbelehrungs-Infos" + msgid "settings.language" msgstr "Sprache" diff --git a/resources/lang/en_US/default.po b/resources/lang/en_US/default.po index 34478c75..230154eb 100644 --- a/resources/lang/en_US/default.po +++ b/resources/lang/en_US/default.po @@ -315,25 +315,34 @@ msgid "settings.certificates.info" msgstr "Here you can enter your health instruction" msgid "settings.ifsg" -msgstr "Frikadellendiplom light: You were instructed from c3gelb about ISfG §43 on site." +msgstr "I was instructed about IfSG §43 (aka Frikadellendiplom light) on site." msgid "settings.ifsg_full" -msgstr "Frikadellendiplom: You have gotten the instruction about §43 ISfG from your Health Department and a second instruction from us or your employer/chef/assosiation within 3 months. Additionally your second instruction is not older than 2 years." +msgstr "I have gotten the instruction about §43 IfSG (aka Frikadellendiplom) from my Health Department " +"and a second instruction from us or my employer/chef/assosiation within 3 months. " +"Additionally my second instruction is not older than 2 years." msgid "settings.certificates.success" msgstr "Health instruction was changed successfully." -msgid "requires IfSG certificate" -msgstr "requires health instruction" +msgid "angeltype.ifsg.required" +msgstr "Requires health instruction" -msgid "ifsg certificate" +msgid "ifsg.certificate" msgstr "health instruction" -msgid "my ifsg certificate" +msgid "angeltype.ifsg.own" msgstr "my health instruction" -msgid "This angeltype requires an ifsg certificate. Please enter your ifsg certificate information!" -msgstr ""This angeltype requires a health instruction. Please enter your health instruction information!"" +msgid "angeltype.ifsg.required.info" +msgstr "This angeltype requires a health instruction. Please enter your health instruction information!" + +msgid "angeltype.ifsg.required.info.here" +msgstr "You joined an angeltype which requires a health instruction. " +"Please edit your health instruction information here: %s." + +msgid "ifsg.info" +msgstr "Health instruction information" msgid "settings.language" msgstr "Language" diff --git a/resources/views/pages/settings/certificates.twig b/resources/views/pages/settings/certificates.twig index c7075361..2a7535e7 100644 --- a/resources/views/pages/settings/certificates.twig +++ b/resources/views/pages/settings/certificates.twig @@ -21,4 +21,4 @@ -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/src/Controllers/Metrics/Stats.php b/src/Controllers/Metrics/Stats.php index 7343f37b..098d6b7a 100644 --- a/src/Controllers/Metrics/Stats.php +++ b/src/Controllers/Metrics/Stats.php @@ -174,22 +174,22 @@ class Stats ->get(); } - public function licenses(string $lisence): int + public function licenses(string $license): int { $mapping = [ - 'has_car' => 'has_car', - 'forklift' => 'drive_forklift', - 'car' => 'drive_car', - '3.5t' => 'drive_3_5t', - '7.5t' => 'drive_7_5t', - '12t' => 'drive_12t', - 'ifsg' => 'ifsg_certificate', - 'ifsg_full' => 'ifsg_certificate_full', + 'has_car' => 'has_car', + 'forklift' => 'drive_forklift', + 'car' => 'drive_car', + '3.5t' => 'drive_3_5t', + '7.5t' => 'drive_7_5t', + '12t' => 'drive_12t', + 'ifsg' => 'ifsg_certificate', + 'ifsg_full' => 'ifsg_certificate_full', ]; $query = (new License()) ->getQuery() - ->where($mapping[$lisence], true); + ->where($mapping[$license], true); return $query->count(); } diff --git a/src/Controllers/SettingsController.php b/src/Controllers/SettingsController.php index fe4f0adf..75e5fc07 100644 --- a/src/Controllers/SettingsController.php +++ b/src/Controllers/SettingsController.php @@ -225,9 +225,11 @@ class SettingsController extends BaseController public function ifsgCertificate(): Response { $user = $this->auth->user(); + if (!config('ifsg_enabled')) { throw new HttpNotFound('ifsg.disabled'); } + return $this->response->withView( 'pages/settings/certificates', [ @@ -243,7 +245,7 @@ class SettingsController extends BaseController $user = $this->auth->user(); $data = $this->validate($request, [ 'ifsg_certificate' => 'optional|checked', - 'ifsg_certificate_full' => 'optional|checked' + 'ifsg_certificate_full' => 'optional|checked', ]); if (!config('ifsg_enabled')) { @@ -251,7 +253,7 @@ class SettingsController extends BaseController } $user->license->ifsg_certificate = $data['ifsg_certificate'] || $data['ifsg_certificate_full']; - $user->license->ifsg_certificate_full = (bool)$data['ifsg_certificate_full']; + $user->license->ifsg_certificate_full = (bool) $data['ifsg_certificate_full']; $user->license->save(); $this->addNotification('settings.certificates.success'); @@ -290,7 +292,7 @@ class SettingsController extends BaseController $menu[url('/settings/theme')] = 'settings.theme'; } - if (!config('ifsg_disable')) { + if (config('ifsg_enable')) { $menu[url('/settings/certificates')] = 'settings.certificates'; } diff --git a/src/Models/User/License.php b/src/Models/User/License.php index 6c77a602..e955345e 100644 --- a/src/Models/User/License.php +++ b/src/Models/User/License.php @@ -31,14 +31,14 @@ class License extends HasUserModel /** @var array Default attributes */ protected $attributes = [ // phpcs:ignore - 'has_car' => false, - 'drive_forklift' => false, - 'drive_car' => false, - 'drive_3_5t' => false, - 'drive_7_5t' => false, - 'drive_12t' => false, - 'ifsg_certificate' => false, - 'ifsg_certificate_full' => false, + 'has_car' => false, + 'drive_forklift' => false, + 'drive_car' => false, + 'drive_3_5t' => false, + 'drive_7_5t' => false, + 'drive_12t' => false, + 'ifsg_certificate' => false, + 'ifsg_certificate_full' => false, ]; /** @@ -60,14 +60,14 @@ class License extends HasUserModel /** @var array */ protected $casts = [ // phpcs:ignore - 'has_car' => 'boolean', - 'drive_forklift' => 'boolean', - 'drive_car' => 'boolean', - 'drive_3_5t' => 'boolean', - 'drive_7_5t' => 'boolean', - 'drive_12t' => 'boolean', - 'ifsg_certificate' => 'boolean', - 'ifsg_certificate_full' => 'boolean', + 'has_car' => 'boolean', + 'drive_forklift' => 'boolean', + 'drive_car' => 'boolean', + 'drive_3_5t' => 'boolean', + 'drive_7_5t' => 'boolean', + 'drive_12t' => 'boolean', + 'ifsg_certificate' => 'boolean', + 'ifsg_certificate_full' => 'boolean', ]; /** diff --git a/tests/Unit/Controllers/Metrics/ControllerTest.php b/tests/Unit/Controllers/Metrics/ControllerTest.php index 66bc2a9e..84350e95 100644 --- a/tests/Unit/Controllers/Metrics/ControllerTest.php +++ b/tests/Unit/Controllers/Metrics/ControllerTest.php @@ -86,10 +86,10 @@ class ControllerTest extends TestCase ->with('metrics return') ->willReturn($response); - $stats->expects($this->exactly(6)) + $stats->expects($this->exactly(8)) ->method('licenses') - ->withConsecutive(['has_car'], ['forklift'], ['car'], ['3.5t'], ['7.5t'], ['12t']) - ->willReturnOnConsecutiveCalls(6, 3, 15, 9, 7, 1); + ->withConsecutive(['has_car'], ['forklift'], ['car'], ['3.5t'], ['7.5t'], ['12t'], ['ifsg'], ['ifsg_full']) + ->willReturnOnConsecutiveCalls(6, 3, 15, 9, 7, 1, 5, 4); $stats->expects($this->exactly(2)) ->method('arrivedUsers') ->withConsecutive([false], [true]) diff --git a/tests/Unit/Controllers/Metrics/StatsTest.php b/tests/Unit/Controllers/Metrics/StatsTest.php index 8ad22793..737e265c 100644 --- a/tests/Unit/Controllers/Metrics/StatsTest.php +++ b/tests/Unit/Controllers/Metrics/StatsTest.php @@ -142,8 +142,8 @@ class StatsTest extends TestCase $this->assertEquals(0, $stats->licenses('3.5t')); $this->assertEquals(0, $stats->licenses('7.5t')); $this->assertEquals(1, $stats->licenses('12t')); - $this->assertEquals(1, $stats->licenses('ifsg')); - $this->assertEquals(2, $stats->licenses('ifsg_full')); + $this->assertEquals(0, $stats->licenses('ifsg')); + $this->assertEquals(0, $stats->licenses('ifsg_full')); } /**