replace($input); $method = new ReflectionMethod(CheckoutController::class, 'validateCheckoutData'); return $method->invoke(app(CheckoutController::class)); } /** * @return array */ function cosvBaseCheckoutInput(array $overrides = []): array { return array_merge([ 'is_from' => 'shopping', 'billing_salutation' => 'Frau', 'billing_firstname' => 'Erika', 'billing_lastname' => 'Muster', 'billing_email' => 'erika@example.com', 'billing_address' => 'Musterweg 1', 'billing_zipcode' => '12345', 'billing_city' => 'Berlin', 'accepted_data_checkbox' => '1', ], $overrides); } it('verlangt den Herkunfts-Freitext bei Shop-Kundenbestellungen', function () { $validator = cosvValidateCheckout(cosvBaseCheckoutInput()); expect($validator->fails())->toBeTrue(); expect($validator->errors()->has('customer_order_source_comment'))->toBeTrue(); expect($validator->errors()->first('customer_order_source_comment'))->toContain('aufmerksam geworden'); }); it('akzeptiert den Checkout ohne das frühere Herkunfts-Dropdown', function () { $validator = cosvValidateCheckout(cosvBaseCheckoutInput([ 'customer_order_source_comment' => 'Empfehlung von Maria Mustermann', ])); expect($validator->fails())->toBeFalse(); expect($validator->errors()->has('customer_order_source'))->toBeFalse(); }); it('begrenzt den Herkunfts-Freitext auf 500 Zeichen', function () { $validator = cosvValidateCheckout(cosvBaseCheckoutInput([ 'customer_order_source_comment' => str_repeat('a', 501), ])); expect($validator->fails())->toBeTrue(); expect($validator->errors()->has('customer_order_source_comment'))->toBeTrue(); }); it('verlangt keinen Herkunfts-Freitext außerhalb des Shop-Checkouts', function () { $validator = cosvValidateCheckout(cosvBaseCheckoutInput([ 'is_from' => 'user', ])); expect($validator->fails())->toBeFalse(); });