shouldReceive('check')->twice()->andReturn(true, false); $request = new UpdatePageRequest($authService); $request->initialize(); // WHEN $authorized = $request->authorize(); $denied = $request->authorize(); // THEN expect($authorized)->toBeTrue() ->and($denied)->toBeFalse(); }); it('validates SEO length bounds and required content', function (): void { // GIVEN $authService = \Mockery::mock(AppAdminAuthService::class); $rules = new UpdatePageRequest($authService)->rules(); // WHEN $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' => '
Contenu valide.
', ], $rules); // THEN expect($invalid->errors()->keys())->toContain('seo_title', 'seo_description', 'content') ->and($valid->passes())->toBeTrue(); }); it('maps request data into UpdatePageInput', function (): void { // GIVEN $authService = \Mockery::mock(AppAdminAuthService::class); $page = new Page(); $request = new UpdatePageRequest($authService); $request->initialize( request: [ 'seo_title' => str_repeat('T', 50), 'seo_description' => str_repeat('D', 80), 'title' => 'Mentions légales', 'content' => 'Texte légal
', ], server: ['REQUEST_METHOD' => 'PUT'], ); // WHEN $input = $request->toUpdatePageInput($page); // THEN 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('Texte légal
'); }); });