2026-06-14 21:32:07 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2026-11-16 14:26:35 +01:00
|
|
|
namespace Tests\Feature\App\Http\Requests\Bo\Pages;
|
|
|
|
|
|
2026-06-14 21:32:07 +02:00
|
|
|
use App\Http\Requests\Bo\Pages\UpdatePageRequest;
|
2026-11-16 15:23:40 +01:00
|
|
|
use App\Models\Page;
|
|
|
|
|
use Illuminate\Support\Facades\Validator;
|
2026-06-14 21:32:07 +02:00
|
|
|
use Infrastructure\Adapters\Services\AppAdminAuthService;
|
|
|
|
|
|
2026-11-16 15:23:40 +01:00
|
|
|
describe('UpdatePageRequest', function (): void {
|
|
|
|
|
it('authorizes only when admin auth service returns true', function (): void {
|
2026-06-14 21:32:07 +02:00
|
|
|
// GIVEN
|
2026-11-16 15:23:40 +01:00
|
|
|
$authService = \Mockery::mock(AppAdminAuthService::class);
|
|
|
|
|
$authService->shouldReceive('check')->twice()->andReturn(true, false);
|
2026-06-14 21:32:07 +02:00
|
|
|
|
|
|
|
|
$request = new UpdatePageRequest($authService);
|
2026-11-16 15:23:40 +01:00
|
|
|
$request->initialize();
|
2026-06-14 21:32:07 +02:00
|
|
|
|
|
|
|
|
// WHEN
|
2026-11-16 15:23:40 +01:00
|
|
|
$authorized = $request->authorize();
|
|
|
|
|
$denied = $request->authorize();
|
2026-06-14 21:32:07 +02:00
|
|
|
|
|
|
|
|
// THEN
|
2026-11-16 15:23:40 +01:00
|
|
|
expect($authorized)->toBeTrue()
|
|
|
|
|
->and($denied)->toBeFalse();
|
2026-06-14 21:32:07 +02:00
|
|
|
});
|
|
|
|
|
|
2026-11-16 15:23:40 +01:00
|
|
|
it('validates SEO length bounds and required content', function (): void {
|
2026-06-14 21:32:07 +02:00
|
|
|
// GIVEN
|
2026-11-16 15:23:40 +01:00
|
|
|
$authService = \Mockery::mock(AppAdminAuthService::class);
|
|
|
|
|
$rules = new UpdatePageRequest($authService)->rules();
|
2026-06-14 21:32:07 +02:00
|
|
|
|
|
|
|
|
// WHEN
|
2026-11-16 15:23:40 +01:00
|
|
|
$invalid = Validator::make([
|
|
|
|
|
'seo_title' => 'Trop court',
|
|
|
|
|
'seo_description' => 'Trop courte aussi',
|
|
|
|
|
'content' => '',
|
|
|
|
|
], $rules);
|
|
|
|
|
$valid = Validator::make([
|
|
|
|
|
'seo_title' => str_repeat('a', 50),
|
|
|
|
|
'seo_description' => str_repeat('b', 80),
|
|
|
|
|
'title' => 'Conditions générales',
|
|
|
|
|
'content' => '<p>Contenu valide.</p>',
|
|
|
|
|
], $rules);
|
2026-06-14 21:32:07 +02:00
|
|
|
|
|
|
|
|
// THEN
|
2026-11-16 15:23:40 +01:00
|
|
|
expect($invalid->errors()->keys())->toContain('seo_title', 'seo_description', 'content')
|
|
|
|
|
->and($valid->passes())->toBeTrue();
|
2026-06-14 21:32:07 +02:00
|
|
|
});
|
|
|
|
|
|
2026-11-16 15:23:40 +01:00
|
|
|
it('maps request data into UpdatePageInput', function (): void {
|
2026-06-14 21:32:07 +02:00
|
|
|
// GIVEN
|
2026-11-16 15:23:40 +01:00
|
|
|
$authService = \Mockery::mock(AppAdminAuthService::class);
|
|
|
|
|
$page = new Page();
|
2026-06-14 21:32:07 +02:00
|
|
|
$request = new UpdatePageRequest($authService);
|
2026-11-16 15:23:40 +01:00
|
|
|
$request->initialize(
|
|
|
|
|
request: [
|
|
|
|
|
'seo_title' => str_repeat('T', 50),
|
|
|
|
|
'seo_description' => str_repeat('D', 80),
|
|
|
|
|
'title' => 'Mentions légales',
|
|
|
|
|
'content' => '<p>Texte légal</p>',
|
|
|
|
|
],
|
|
|
|
|
server: ['REQUEST_METHOD' => 'PUT'],
|
|
|
|
|
);
|
2026-06-14 21:32:07 +02:00
|
|
|
|
|
|
|
|
// WHEN
|
2026-11-16 15:23:40 +01:00
|
|
|
$input = $request->toUpdatePageInput($page);
|
2026-06-14 21:32:07 +02:00
|
|
|
|
|
|
|
|
// THEN
|
2026-11-16 15:23:40 +01:00
|
|
|
expect($input->page)->toBe($page)
|
|
|
|
|
->and($input->seo->title)->toBe(str_repeat('T', 50))
|
|
|
|
|
->and($input->seo->description)->toBe(str_repeat('D', 80))
|
|
|
|
|
->and($input->title)->toBe('Mentions légales')
|
|
|
|
|
->and($input->content)->toBe('<p>Texte légal</p>');
|
2026-06-14 21:32:07 +02:00
|
|
|
});
|
|
|
|
|
});
|