fix tests after ifsg implementation

This commit is contained in:
Xu 2023-08-10 11:33:06 +02:00 committed by msquare
parent 8dd4af1bb6
commit 4378fa2d7d
15 changed files with 106 additions and 59 deletions

View File

@ -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

View File

@ -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' => [

View File

@ -30,4 +30,4 @@ class AddRequiresIfsgCerificateToAngeltypes extends Migration
$table->dropColumn('requires_ifsg_certificate');
});
}
}
}

View File

@ -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'),
'<a href="' . url('/settings/certificates') . '" class="text-info">' . __('ifsg.info') . '</a>'
);
}
}
return null;
}
/**
* Route user driver licenses actions.
*

View File

@ -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);

View File

@ -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) {

View File

@ -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([

View File

@ -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"

View File

@ -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"

View File

@ -21,4 +21,4 @@
</div>
</div>
</form>
{% endblock %}
{% endblock %}

View File

@ -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();
}

View File

@ -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';
}

View File

@ -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<string> */
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',
];
/**

View File

@ -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])

View File

@ -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'));
}
/**