feat: enable entering additional remarks in offer confirmation
This commit is contained in:
@@ -35,6 +35,14 @@ class SendAccessLinkController extends AbstractController
|
||||
throw $this->createAccessDeniedException('Invalid CSRF token.');
|
||||
}
|
||||
|
||||
// Older bookings can still be missing their contact data. Sending would be
|
||||
// silently skipped further down, so say so instead of reporting success.
|
||||
if (null === $booking->getEmail() || '' === trim($booking->getEmail())) {
|
||||
$this->addFlash('error', 'Für diese Buchung ist keine E-Mail-Adresse hinterlegt. Bitte ergänze sie, um den Zugangslink zu senden.');
|
||||
|
||||
return new HxRedirectResponse($this->generateUrl('app_admin_accommodationbooking_edit', ['id' => $booking->getId()]));
|
||||
}
|
||||
|
||||
$this->bookingService->sendCustomerConfirmationEmail($booking);
|
||||
|
||||
$this->addFlash('success', 'Der Zugangslink wurde dem Kunden per E-Mail zugestellt.');
|
||||
|
||||
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace App\Controller\Groups;
|
||||
|
||||
use App\Entity\Groups\AccommodationBooking;
|
||||
use App\Form\Model\OfferAcceptDto;
|
||||
use App\Form\OfferAcceptConfirmationType;
|
||||
use App\Htmx\HxTrait;
|
||||
use App\Model\AccommodationBookingContext;
|
||||
@@ -97,13 +98,16 @@ class OfferController extends AbstractController
|
||||
return $this->redirectToOfferPage($request, $uuid);
|
||||
}
|
||||
|
||||
$confirmationForm = $this->createForm(OfferAcceptConfirmationType::class, null, [
|
||||
$dto = new OfferAcceptDto(remarks: $booking->getRemarks());
|
||||
$confirmationForm = $this->createForm(OfferAcceptConfirmationType::class, $dto, [
|
||||
'terms_url' => $this->termsUrlProvider->forAccommodation($booking->getAccommodation()),
|
||||
]);
|
||||
$confirmationForm->handleRequest($request);
|
||||
|
||||
if ($confirmationForm->isSubmitted() && $confirmationForm->isValid()) {
|
||||
$this->bookingService->acceptBooking($booking);
|
||||
// The textarea is prefilled, so the submitted value is the complete remark —
|
||||
// an emptied field arrives as null and must clear the stored one, not keep it.
|
||||
$this->bookingService->acceptBooking($booking, $dto->remarks ?? '');
|
||||
$this->addFlash('success', 'Deine Buchung ist bestätigt.');
|
||||
|
||||
return $this->redirectToOfferPage($request, $uuid);
|
||||
|
||||
@@ -109,9 +109,15 @@ class AccommodationBooking implements BlameableEntityInterface, TimestampableEnt
|
||||
#[Assert\NotBlank(groups: ['edit'])]
|
||||
private ?string $lastName = null;
|
||||
|
||||
/**
|
||||
* The `offer` group covers the one field a customer-facing booking cannot do without:
|
||||
* the access link and every notification are addressed to it. It is enforced on
|
||||
* creation as soon as the booking is not a draft, while `edit` additionally demands
|
||||
* the rest of the contact data.
|
||||
*/
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
#[Assert\NotBlank(groups: ['edit'])]
|
||||
#[Assert\Email(groups: ['edit'])]
|
||||
#[Assert\NotBlank(groups: ['edit', 'offer'])]
|
||||
#[Assert\Email(groups: ['edit', 'offer'])]
|
||||
private ?string $email = null;
|
||||
|
||||
#[ORM\Column(length: 50, nullable: true)]
|
||||
|
||||
@@ -10,9 +10,11 @@ use App\Enum\Groups\AccommodationBookingStatus;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\DateType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\EmailType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\EnumType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
/**
|
||||
@@ -57,6 +59,13 @@ class AccommodationBookingCreateType extends AbstractType
|
||||
],
|
||||
'choice_label' => fn (AccommodationBookingStatus $status) => $status->label(),
|
||||
])
|
||||
// Not marked required in HTML: a draft may be saved without it, and the
|
||||
// validation group below enforces it for everything else.
|
||||
->add('email', EmailType::class, [
|
||||
'label' => 'E-Mail',
|
||||
'required' => false,
|
||||
'help' => 'Für ein Angebot erforderlich — der Zugangslink und alle Benachrichtigungen gehen an diese Adresse.',
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
@@ -64,6 +73,15 @@ class AccommodationBookingCreateType extends AbstractType
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'data_class' => AccommodationBooking::class,
|
||||
// A draft is a scratch record, but anything the customer can be pointed at
|
||||
// needs a reachable address — see the `offer` group on the entity. The rest of
|
||||
// the contact data is collected on the edit page, which validates `edit`.
|
||||
'validation_groups' => static function (FormInterface $form): array {
|
||||
/** @var AccommodationBooking $booking */
|
||||
$booking = $form->getData();
|
||||
|
||||
return $booking->isDraft() ? ['Default'] : ['Default', 'offer'];
|
||||
},
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Form\Model;
|
||||
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
/**
|
||||
* Carries what the offer acceptance modal submits: the AGB confirmation and an
|
||||
* optional remark. `remarks` is prefilled from the booking, so whatever comes back
|
||||
* is the full value the customer wants stored — an emptied textarea means "clear it".
|
||||
*/
|
||||
class OfferAcceptDto
|
||||
{
|
||||
public function __construct(
|
||||
#[Assert\IsTrue(message: 'Bitte akzeptiere die AGB, um die Buchung abzuschließen.')]
|
||||
public bool $termsAccepted = false,
|
||||
#[Assert\Length(max: 2000, maxMessage: 'Die Anmerkungen dürfen maximal {{ limit }} Zeichen lang sein.')]
|
||||
public ?string $remarks = null,
|
||||
) {
|
||||
}
|
||||
}
|
||||
@@ -4,14 +4,15 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Form;
|
||||
|
||||
use App\Form\Model\OfferAcceptDto;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Validator\Constraints\IsTrue;
|
||||
|
||||
/**
|
||||
* @extends AbstractType<null>
|
||||
* @extends AbstractType<OfferAcceptDto>
|
||||
*/
|
||||
class OfferAcceptConfirmationType extends AbstractType
|
||||
{
|
||||
@@ -22,19 +23,28 @@ class OfferAcceptConfirmationType extends AbstractType
|
||||
htmlspecialchars($options['terms_url'], ENT_QUOTES, 'UTF-8')
|
||||
);
|
||||
|
||||
$builder->add('termsAccepted', CheckboxType::class, [
|
||||
$builder
|
||||
->add('remarks', TextareaType::class, [
|
||||
'label' => 'Anmerkungen (optional)',
|
||||
'required' => false,
|
||||
'attr' => [
|
||||
'rows' => 4,
|
||||
'maxlength' => 2000,
|
||||
],
|
||||
])
|
||||
->add('termsAccepted', CheckboxType::class, [
|
||||
'label' => sprintf('Ich habe die %s gelesen und bin damit einverstanden, dass eine kostenpflichtige Buchung zustande kommt.', $termsLink),
|
||||
'label_html' => true,
|
||||
'mapped' => false,
|
||||
'required' => true,
|
||||
'constraints' => [
|
||||
new IsTrue(message: 'Bitte akzeptiere die AGB, um die Buchung abzuschließen.'),
|
||||
],
|
||||
]);
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'data_class' => OfferAcceptDto::class,
|
||||
]);
|
||||
$resolver->setRequired('terms_url');
|
||||
$resolver->setAllowedTypes('terms_url', 'string');
|
||||
}
|
||||
|
||||
@@ -387,14 +387,28 @@ class AccommodationBookingService
|
||||
/**
|
||||
* All accommodation mail is sent from the group desk address so customer replies
|
||||
* land there rather than in the general inbox.
|
||||
*
|
||||
* A booking can legitimately have no email yet (drafts, and offers created without
|
||||
* contact data), so a missing recipient is logged and skipped rather than thrown:
|
||||
* the caller's own work — accepting an offer, for instance — is already done and
|
||||
* must not fail over an undeliverable notification.
|
||||
*/
|
||||
private function sendBookingEmail(
|
||||
AccommodationBooking $booking,
|
||||
string $to,
|
||||
?string $to,
|
||||
string $subject,
|
||||
string $template,
|
||||
string $errorMessage,
|
||||
): void {
|
||||
if (null === $to || '' === trim($to)) {
|
||||
$this->logger->warning($errorMessage, [
|
||||
'booking_id' => $booking->getId(),
|
||||
'error' => 'No recipient email address on the booking.',
|
||||
]);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$this->mailer->createAndSendEmail(
|
||||
[
|
||||
@@ -486,13 +500,21 @@ class AccommodationBookingService
|
||||
* only the status moves to Bestätigt, so an offer-originated booking remains
|
||||
* distinguishable from a direct one.
|
||||
* Idempotent — a no-op (including no emails) if the offer is not open any more.
|
||||
*
|
||||
* @param ?string $remarks null leaves the stored remark untouched, a string replaces it,
|
||||
* an empty string clears it
|
||||
*/
|
||||
public function acceptBooking(AccommodationBooking $booking): void
|
||||
public function acceptBooking(AccommodationBooking $booking, ?string $remarks = null): void
|
||||
{
|
||||
if (!$booking->isInquiry() || !$booking->isOpen()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (null !== $remarks) {
|
||||
$trimmed = trim($remarks);
|
||||
$booking->setRemarks('' === $trimmed ? null : $trimmed);
|
||||
}
|
||||
|
||||
$booking->setStatus(AccommodationBookingStatus::Accepted);
|
||||
$booking->setAcceptedAt(new \DateTimeImmutable());
|
||||
$this->entityManager->flush();
|
||||
|
||||
@@ -18,6 +18,9 @@
|
||||
<div class="lg:col-span-2">
|
||||
{{ form_row(form.status) }}
|
||||
</div>
|
||||
<div class="lg:col-span-2">
|
||||
{{ form_row(form.email) }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex justify-end pt-8">
|
||||
<button type="submit" class="button button--primary button--small">
|
||||
|
||||
@@ -24,4 +24,9 @@
|
||||
<td>{{ booking.dateTo|date('d.m.Y') }}</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
{% if booking.remarks %}
|
||||
<h2>Anmerkungen</h2>
|
||||
<p>{{ booking.remarks|nl2br }}</p>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
@@ -46,6 +46,14 @@
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
{% if booking.remarks %}
|
||||
<h2>
|
||||
Anmerkungen
|
||||
</h2>
|
||||
|
||||
<p>{{ booking.remarks|nl2br }}</p>
|
||||
{% endif %}
|
||||
|
||||
<p>
|
||||
Bei Fragen antworte einfach auf diese E-Mail.
|
||||
</p>
|
||||
|
||||
@@ -4,7 +4,8 @@
|
||||
|
||||
{% block content %}
|
||||
{% from '_partials/_validation_errors.html.twig' import validation_alert %}
|
||||
{{ validation_alert(confirmationForm, 'Bitte akzeptiere die AGB, um die Buchung abzuschließen.', false) }}
|
||||
{# Generic title: both fields can fail, and each renders its own message inline. #}
|
||||
{{ validation_alert(confirmationForm, null, false) }}
|
||||
|
||||
<p class="mb-6">
|
||||
Möchtest du dieses Angebot jetzt verbindlich buchen?
|
||||
@@ -17,6 +18,7 @@
|
||||
'hx-swap': 'outerHTML',
|
||||
}
|
||||
}) }}
|
||||
{{ form_row(confirmationForm.remarks) }}
|
||||
{{ form_row(confirmationForm.termsAccepted) }}
|
||||
|
||||
<div class="mt-6 flex flex-col space-y-4 md:flex-row md:space-y-0 justify-between">
|
||||
|
||||
@@ -8,6 +8,7 @@ use App\Controller\Groups\OfferController;
|
||||
use App\Entity\Groups\Accommodation;
|
||||
use App\Entity\Groups\AccommodationBooking;
|
||||
use App\Enum\Groups\AccommodationBookingStatus;
|
||||
use App\Form\Model\OfferAcceptDto;
|
||||
use App\Repository\Groups\AccommodationBookingRepository;
|
||||
use App\Service\AccommodationBookingBreakdownCalculator;
|
||||
use App\Service\AccommodationBookingLinkSigner;
|
||||
@@ -208,6 +209,7 @@ class OfferControllerTest extends TestCase
|
||||
{
|
||||
$booking = new AccommodationBooking();
|
||||
$booking->setStatus(AccommodationBookingStatus::Open);
|
||||
$booking->setRemarks("Bitte Zimmer im EG\nDanke!");
|
||||
|
||||
$bookingRepository = $this->createMock(AccommodationBookingRepository::class);
|
||||
$bookingRepository->method('findOneBy')->with(['uuid' => $booking->getUuid()])->willReturn($booking);
|
||||
@@ -233,12 +235,17 @@ class OfferControllerTest extends TestCase
|
||||
self::assertSame('groups/booking/_offer_accept_confirmation_modal.html.twig', $controller->renderedView);
|
||||
self::assertSame($booking, $controller->renderedParameters['booking']);
|
||||
self::assertSame($confirmationForm, $controller->renderedParameters['confirmationForm']);
|
||||
|
||||
self::assertInstanceOf(OfferAcceptDto::class, $controller->formData);
|
||||
self::assertSame("Bitte Zimmer im EG\nDanke!", $controller->formData->remarks, 'the stored remark is prefilled into the modal');
|
||||
self::assertFalse($controller->formData->termsAccepted);
|
||||
}
|
||||
|
||||
public function testConfirmPostValidAcceptsBookingAndRedirects(): void
|
||||
{
|
||||
$booking = new AccommodationBooking();
|
||||
$booking->setStatus(AccommodationBookingStatus::Open);
|
||||
$booking->setRemarks('Bitte Zimmer im EG');
|
||||
|
||||
$bookingRepository = $this->createMock(AccommodationBookingRepository::class);
|
||||
$bookingRepository->method('findOneBy')->willReturn($booking);
|
||||
@@ -247,7 +254,7 @@ class OfferControllerTest extends TestCase
|
||||
$linkSigner->method('isSessionAuthorized')->willReturn(true);
|
||||
|
||||
$bookingService = $this->createMock(AccommodationBookingService::class);
|
||||
$bookingService->expects(self::once())->method('acceptBooking')->with($booking);
|
||||
$bookingService->expects(self::once())->method('acceptBooking')->with($booking, 'Bitte Zimmer im EG');
|
||||
|
||||
$confirmationForm = $this->createMock(FormInterface::class);
|
||||
$confirmationForm->method('handleRequest')->willReturnSelf();
|
||||
@@ -282,7 +289,8 @@ class OfferControllerTest extends TestCase
|
||||
$linkSigner->method('isSessionAuthorized')->willReturn(true);
|
||||
|
||||
$bookingService = $this->createMock(AccommodationBookingService::class);
|
||||
$bookingService->expects(self::once())->method('acceptBooking')->with($booking);
|
||||
// No remark on the booking and none submitted: the empty string clears rather than keeps.
|
||||
$bookingService->expects(self::once())->method('acceptBooking')->with($booking, '');
|
||||
|
||||
$confirmationForm = $this->createMock(FormInterface::class);
|
||||
$confirmationForm->method('handleRequest')->willReturnSelf();
|
||||
@@ -412,6 +420,8 @@ final class TestableOfferController extends OfferController
|
||||
/** @var array<string, mixed> */
|
||||
public array $renderedParameters = [];
|
||||
|
||||
public mixed $formData = null;
|
||||
|
||||
public function __construct(
|
||||
AccommodationBookingRepository $bookingRepository,
|
||||
AccommodationBookingLinkSigner $linkSigner,
|
||||
@@ -430,6 +440,8 @@ final class TestableOfferController extends OfferController
|
||||
|
||||
protected function createForm(string $type, mixed $data = null, array $options = []): FormInterface
|
||||
{
|
||||
$this->formData = $data;
|
||||
|
||||
return $this->confirmationForm ?? throw new \LogicException('No confirmation form mock configured for this test.');
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Form\Admin\Groups;
|
||||
|
||||
use App\Entity\Groups\AccommodationBooking;
|
||||
use App\Enum\Groups\AccommodationBookingStatus;
|
||||
use App\Form\Admin\Groups\AccommodationBookingCreateType;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Validator\Constraints\Email;
|
||||
use Symfony\Component\Validator\Constraints\EmailValidator;
|
||||
use Symfony\Component\Validator\ConstraintValidatorFactory;
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
class AccommodationBookingCreateTypeTest extends TestCase
|
||||
{
|
||||
public function testDraftsAreValidatedWithoutTheOfferGroup(): void
|
||||
{
|
||||
self::assertSame(['Default'], $this->resolveValidationGroups(AccommodationBookingStatus::Draft));
|
||||
}
|
||||
|
||||
public function testOffersAddTheOfferGroup(): void
|
||||
{
|
||||
self::assertSame(['Default', 'offer'], $this->resolveValidationGroups(AccommodationBookingStatus::Open));
|
||||
}
|
||||
|
||||
public function testDraftCanBeCreatedWithoutAnEmail(): void
|
||||
{
|
||||
$booking = new AccommodationBooking();
|
||||
$booking->setStatus(AccommodationBookingStatus::Draft);
|
||||
|
||||
$violations = $this->validate($booking, $this->resolveValidationGroups(AccommodationBookingStatus::Draft));
|
||||
|
||||
self::assertCount(0, $violations);
|
||||
}
|
||||
|
||||
public function testOfferCannotBeCreatedWithoutAnEmail(): void
|
||||
{
|
||||
$booking = new AccommodationBooking();
|
||||
$booking->setStatus(AccommodationBookingStatus::Open);
|
||||
|
||||
$violations = $this->validate($booking, $this->resolveValidationGroups(AccommodationBookingStatus::Open));
|
||||
|
||||
$properties = array_map(static fn ($violation) => $violation->getPropertyPath(), iterator_to_array($violations));
|
||||
|
||||
self::assertSame(['email'], $properties, 'only the address is enforced here — the rest of the contact data belongs to the edit form');
|
||||
}
|
||||
|
||||
public function testOfferRejectsAMalformedEmail(): void
|
||||
{
|
||||
$booking = new AccommodationBooking();
|
||||
$booking->setStatus(AccommodationBookingStatus::Open);
|
||||
$booking->setEmail('not-an-address');
|
||||
|
||||
$violations = $this->validate($booking, $this->resolveValidationGroups(AccommodationBookingStatus::Open));
|
||||
|
||||
self::assertCount(1, $violations);
|
||||
self::assertSame('email', $violations[0]->getPropertyPath());
|
||||
}
|
||||
|
||||
public function testOfferWithAnEmailIsValid(): void
|
||||
{
|
||||
$booking = new AccommodationBooking();
|
||||
$booking->setStatus(AccommodationBookingStatus::Open);
|
||||
$booking->setEmail('[email protected]');
|
||||
|
||||
$violations = $this->validate($booking, $this->resolveValidationGroups(AccommodationBookingStatus::Open));
|
||||
|
||||
self::assertCount(0, $violations);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
private function resolveValidationGroups(AccommodationBookingStatus $status): array
|
||||
{
|
||||
$resolver = new OptionsResolver();
|
||||
(new AccommodationBookingCreateType())->configureOptions($resolver);
|
||||
|
||||
$booking = new AccommodationBooking();
|
||||
$booking->setStatus($status);
|
||||
|
||||
$form = $this->createMock(FormInterface::class);
|
||||
$form->method('getData')->willReturn($booking);
|
||||
|
||||
return ($resolver->resolve()['validation_groups'])($form);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string[] $groups
|
||||
*/
|
||||
private function validate(AccommodationBooking $booking, array $groups): \Symfony\Component\Validator\ConstraintViolationListInterface
|
||||
{
|
||||
// The app configures email_validation_mode: html5 globally (config/packages/validator.yaml);
|
||||
// the standalone builder would otherwise fall back to the deprecated "loose" mode.
|
||||
$validatorFactory = new ConstraintValidatorFactory([
|
||||
EmailValidator::class => new EmailValidator(Email::VALIDATION_MODE_HTML5),
|
||||
]);
|
||||
|
||||
return Validation::createValidatorBuilder()
|
||||
->enableAttributeMapping()
|
||||
->setConstraintValidatorFactory($validatorFactory)
|
||||
->getValidator()
|
||||
->validate($booking, null, $groups);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Form\Model;
|
||||
|
||||
use App\Form\Model\OfferAcceptDto;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Validator\Validation;
|
||||
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||
|
||||
class OfferAcceptDtoTest extends TestCase
|
||||
{
|
||||
public function testAcceptedTermsWithoutRemarksIsValid(): void
|
||||
{
|
||||
$violations = $this->validator()->validate(new OfferAcceptDto(termsAccepted: true));
|
||||
|
||||
self::assertCount(0, $violations);
|
||||
}
|
||||
|
||||
public function testUncheckedTermsAreRejected(): void
|
||||
{
|
||||
$violations = $this->validator()->validate(new OfferAcceptDto(remarks: 'Bitte Zimmer im EG'));
|
||||
|
||||
self::assertCount(1, $violations);
|
||||
self::assertSame('termsAccepted', $violations[0]->getPropertyPath());
|
||||
self::assertSame('Bitte akzeptiere die AGB, um die Buchung abzuschließen.', $violations[0]->getMessage());
|
||||
}
|
||||
|
||||
public function testRemarksAreCappedAt2000Characters(): void
|
||||
{
|
||||
$dto = new OfferAcceptDto(termsAccepted: true, remarks: str_repeat('a', 2001));
|
||||
|
||||
$violations = $this->validator()->validate($dto);
|
||||
|
||||
self::assertCount(1, $violations);
|
||||
self::assertSame('remarks', $violations[0]->getPropertyPath());
|
||||
self::assertSame('Die Anmerkungen dürfen maximal 2000 Zeichen lang sein.', $violations[0]->getMessage());
|
||||
}
|
||||
|
||||
public function testRemarksAtTheLimitAreAccepted(): void
|
||||
{
|
||||
$dto = new OfferAcceptDto(termsAccepted: true, remarks: str_repeat('a', 2000));
|
||||
|
||||
self::assertCount(0, $this->validator()->validate($dto));
|
||||
}
|
||||
|
||||
private function validator(): ValidatorInterface
|
||||
{
|
||||
return Validation::createValidatorBuilder()
|
||||
->enableAttributeMapping()
|
||||
->getValidator();
|
||||
}
|
||||
}
|
||||
@@ -294,6 +294,89 @@ class AccommodationBookingServiceTest extends TestCase
|
||||
self::assertNotNull($booking->getAcceptedAt());
|
||||
}
|
||||
|
||||
public function testAcceptBookingStoresTrimmedRemarks(): void
|
||||
{
|
||||
$booking = new AccommodationBooking();
|
||||
$booking->setStatus(AccommodationBookingStatus::Open);
|
||||
$booking->setEmail('[email protected]');
|
||||
$booking->setRemarks('vom Telefonat');
|
||||
|
||||
$service = $this->createServiceWithAccommodation(mailer: $this->createMock(Mailer::class));
|
||||
|
||||
$service->acceptBooking($booking, " Bitte Zimmer im EG\nund Frühstück um 8 \n");
|
||||
|
||||
self::assertSame("Bitte Zimmer im EG\nund Frühstück um 8", $booking->getRemarks(), 'inner line breaks survive, outer whitespace does not');
|
||||
}
|
||||
|
||||
public function testAcceptBookingClearsRemarksForEmptySubmission(): void
|
||||
{
|
||||
$booking = new AccommodationBooking();
|
||||
$booking->setStatus(AccommodationBookingStatus::Open);
|
||||
$booking->setEmail('[email protected]');
|
||||
$booking->setRemarks('vom Telefonat');
|
||||
|
||||
$service = $this->createServiceWithAccommodation(mailer: $this->createMock(Mailer::class));
|
||||
|
||||
$service->acceptBooking($booking, ' ');
|
||||
|
||||
self::assertNull($booking->getRemarks(), 'an emptied textarea clears the stored remark');
|
||||
}
|
||||
|
||||
public function testAcceptBookingLeavesRemarksUntouchedWithoutSubmission(): void
|
||||
{
|
||||
$booking = new AccommodationBooking();
|
||||
$booking->setStatus(AccommodationBookingStatus::Open);
|
||||
$booking->setEmail('[email protected]');
|
||||
$booking->setRemarks('vom Telefonat');
|
||||
|
||||
$service = $this->createServiceWithAccommodation(mailer: $this->createMock(Mailer::class));
|
||||
|
||||
$service->acceptBooking($booking);
|
||||
|
||||
self::assertSame('vom Telefonat', $booking->getRemarks(), 'the API path must not wipe the remark');
|
||||
}
|
||||
|
||||
public function testAcceptBookingDoesNotStoreRemarksWhenOfferIsNotOpen(): void
|
||||
{
|
||||
$booking = new AccommodationBooking();
|
||||
$booking->setStatus(AccommodationBookingStatus::Accepted);
|
||||
$booking->setRemarks('vom Telefonat');
|
||||
|
||||
$service = $this->createServiceWithAccommodation(mailer: $this->createMock(Mailer::class));
|
||||
|
||||
$service->acceptBooking($booking, 'zu spät');
|
||||
|
||||
self::assertSame('vom Telefonat', $booking->getRemarks());
|
||||
}
|
||||
|
||||
public function testAcceptBookingSkipsTheCustomerEmailWhenNoAddressIsStored(): void
|
||||
{
|
||||
$booking = new AccommodationBooking();
|
||||
$booking->setStatus(AccommodationBookingStatus::Open);
|
||||
|
||||
// Only the office notification goes out — the customer copy has no recipient.
|
||||
$mailer = $this->createMock(Mailer::class);
|
||||
$mailer
|
||||
->expects(self::once())
|
||||
->method('createAndSendEmail')
|
||||
->with(
|
||||
self::anything(),
|
||||
self::callback(static fn (array $options) => '[email protected]' === $options['to']),
|
||||
);
|
||||
|
||||
$logger = $this->createMock(LoggerInterface::class);
|
||||
$logger
|
||||
->expects(self::once())
|
||||
->method('warning')
|
||||
->with('Failed to send offer accepted customer email', self::anything());
|
||||
|
||||
$service = $this->createServiceWithAccommodation(mailer: $mailer, logger: $logger);
|
||||
|
||||
$service->acceptBooking($booking);
|
||||
|
||||
self::assertSame(AccommodationBookingStatus::Accepted, $booking->getStatus(), 'the acceptance itself must not fail');
|
||||
}
|
||||
|
||||
public function testAcceptBookingIsIdempotentAndSendsNoNotifications(): void
|
||||
{
|
||||
$entityManager = $this->createMock(EntityManagerInterface::class);
|
||||
|
||||
Reference in New Issue
Block a user