fix(slides): allow empty text in slide requests and indicate connected visibility in BO
This commit is contained in:
parent
3c309dc356
commit
d4db0cffc6
6 changed files with 70 additions and 3 deletions
|
|
@ -65,7 +65,13 @@ class StoreSlideRequest extends FormRequest
|
|||
#[\Override]
|
||||
protected function prepareForValidation(): void
|
||||
{
|
||||
$text = $this->input('text');
|
||||
if (is_string($text) && trim(html_entity_decode(strip_tags($text), ENT_QUOTES | ENT_HTML5, 'UTF-8')) === '') {
|
||||
$text = null;
|
||||
}
|
||||
|
||||
$this->merge([
|
||||
'text' => $text,
|
||||
'connected' => $this->boolean('connected'),
|
||||
'link_new_tab' => $this->boolean('link_new_tab'),
|
||||
]);
|
||||
|
|
@ -82,7 +88,7 @@ class StoreSlideRequest extends FormRequest
|
|||
'title' => ['required', 'string', 'min:4', 'max:75'],
|
||||
'picture_alt' => ['required_with:picture', 'string', 'min:4', 'max:75'],
|
||||
'picture_title' => ['required_with:picture', 'string', 'min:4', 'max:75'],
|
||||
'text' => ['required_without:picture', 'string', 'min:5'],
|
||||
'text' => ['nullable', 'required_without:picture', 'string', 'min:4'],
|
||||
'link' => ['nullable', 'url:https', 'max:255'],
|
||||
'link_label' => ['nullable', 'string', 'min:5', 'max:255'],
|
||||
'link_new_tab' => ['present', 'boolean:strict'],
|
||||
|
|
|
|||
|
|
@ -25,4 +25,18 @@ class UpdateSlideRequest extends StoreSlideRequest
|
|||
period: $this->toDatePeriod(),
|
||||
);
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
public function rules(): array
|
||||
{
|
||||
$rules = parent::rules();
|
||||
|
||||
/** @var \App\Models\Slide|null $slide */
|
||||
$slide = $this->route('slide');
|
||||
if ($slide && ! empty($slide->picture)) {
|
||||
$rules['text'] = ['nullable', 'string', 'min:4'];
|
||||
}
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -827,5 +827,7 @@
|
|||
"town": "town",
|
||||
"your_message": "your_message",
|
||||
"Visible": "Visible",
|
||||
"Not visible": "Not visible"
|
||||
"Not visible": "Not visible",
|
||||
"Connected": "Connected",
|
||||
"Connected members only": "Connected members only"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -814,5 +814,7 @@
|
|||
"town": "Ville",
|
||||
"your_message": "Votre message",
|
||||
"Visible": "Visible",
|
||||
"Not visible": "Non visible"
|
||||
"Not visible": "Non visible",
|
||||
"Connected": "Connecté",
|
||||
"Connected members only": "Membres connectés uniquement"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,6 +30,9 @@
|
|||
<td class="text-center align-middle">
|
||||
@if ($slide->isVisible())
|
||||
<i class="fas fa-check check-green" data-bs-toggle="tooltip" title="{{ __('Visible') }}"></i>
|
||||
@if ($slide->connected)
|
||||
<br><span class="badge bg-secondary" data-bs-toggle="tooltip" title="{{ __('Connected members only') }}"><i class="fa-solid fa-lock"></i> {{ __('Connected') }}</span>
|
||||
@endif
|
||||
@else
|
||||
<i class="fas fa-times cross-red" data-bs-toggle="tooltip" title="{{ __('Not visible') }}"></i>
|
||||
@endif
|
||||
|
|
|
|||
|
|
@ -74,4 +74,44 @@ describe('StoreSlideRequest', function () {
|
|||
// THEN
|
||||
expect(true)->toBeTrue();
|
||||
});
|
||||
|
||||
it('normalizes empty text to null in prepareForValidation', function () {
|
||||
// GIVEN
|
||||
$authService = mock(AppAdminAuthService::class);
|
||||
$request = new StoreSlideRequest($authService);
|
||||
$request->initialize(request: ['text' => '<p><br></p>']);
|
||||
$method = new \ReflectionMethod($request, 'prepareForValidation');
|
||||
$method->setAccessible(true);
|
||||
|
||||
// WHEN
|
||||
$method->invoke($request);
|
||||
|
||||
// THEN
|
||||
expect($request->input('text'))->toBeNull();
|
||||
});
|
||||
|
||||
it('allows empty text when picture is present', function () {
|
||||
// GIVEN
|
||||
$authService = mock(AppAdminAuthService::class);
|
||||
$request = new StoreSlideRequest($authService);
|
||||
$rules = $request->rules();
|
||||
|
||||
// WHEN
|
||||
$validator = validator(
|
||||
[
|
||||
'title' => 'Slide Title',
|
||||
'picture' => 'some/picture.jpg',
|
||||
'picture_alt' => 'Alt text',
|
||||
'picture_title' => 'Title text',
|
||||
'text' => null,
|
||||
'link_new_tab' => false,
|
||||
'connected' => false,
|
||||
'client_timezone' => 'Europe/Paris',
|
||||
],
|
||||
$rules
|
||||
);
|
||||
|
||||
// THEN
|
||||
expect($validator->errors()->has('text'))->toBeFalse();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue