Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions sources/AppBundle/Event/Form/PurchaseType.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
Expand Down Expand Up @@ -105,6 +107,25 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
'mapped' => false,
])
;

$builder->addEventListener(FormEvents::PRE_SUBMIT, static function (FormEvent $event): void {
$data = $event->getData();
if (!is_array($data) || !is_array($data['tickets'] ?? null)) {
return;
}

$nbPersonnes = filter_var($data['nbPersonnes'] ?? null, FILTER_VALIDATE_INT, ['options' => ['min_range' => 1]]);
if ($nbPersonnes === false) {
return;
}

$data['tickets'] = array_filter(
$data['tickets'],
static fn($index): bool => (int) $index < $nbPersonnes,
ARRAY_FILTER_USE_KEY,
);
$event->setData($data);
});
}

public function configureOptions(OptionsResolver $resolver): void
Expand Down
35 changes: 35 additions & 0 deletions tests/behat/features/EventPages/Ticketing.feature
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,41 @@ Feature: Event pages - Ticketing
Then I should see "Paiement de vos billets"
And I should see "Vous serez redirigé vers notre partenaire paybox afin de procéder au paiement d'un montant de 15€"

@reloadDbWithTestData
Scenario: Les billets masqués ne comptent pas dans le quota tarif membre d'une personne morale
# MyCorp : 3 places au tarif membre, aucune déjà prise
Given I am logged-in with the user "edmonddupont" and the password "edmonddupont"
And I am on "/event/forum/tickets"
Then I should see "Billetterie: forum"
And I select "3" from "purchase[nbPersonnes]"
# Formule Tarif membre pour les 3 personnes
And I select "0" from "purchase[tickets][0][ticketEventType]"
And I fill in "purchase[tickets][0][firstname]" with "Prénom personne 1"
And I fill in "purchase[tickets][0][lastname]" with "Nom personne 1"
And I fill in "purchase[tickets][0][email]" with "personne1@mycorp.fr"
And I select "0" from "purchase[tickets][1][ticketEventType]"
And I fill in "purchase[tickets][1][firstname]" with "Prénom personne 2"
And I fill in "purchase[tickets][1][lastname]" with "Nom personne 2"
And I fill in "purchase[tickets][1][email]" with "personne2@mycorp.fr"
And I select "0" from "purchase[tickets][2][ticketEventType]"
And I fill in "purchase[tickets][2][firstname]" with "Prénom personne 3"
And I fill in "purchase[tickets][2][lastname]" with "Nom personne 3"
And I fill in "purchase[tickets][2][email]" with "personne3@mycorp.fr"
# Section de la 4e personne masquée (passage de 4 à 3 personnes) : sa formule reste cochée et est envoyée
And I select "0" from "purchase[tickets][3][ticketEventType]"
And I select "2" from "purchase[paymentType]"
And I fill in "purchase[firstname]" with "Prénom facturation"
And I fill in "purchase[lastname]" with "Nom facturation"
And I fill in "purchase[address]" with "42 rue de Strasbourg"
And I fill in "purchase[zipcode]" with "75003"
And I fill in "purchase[city]" with "PARIS"
And I fill in "purchase[email]" with "facturation@mycorp.fr"
And I check "purchase[cgv]"
When I press "Confirmer & Payer"
Then I should not see "You cannot order as many tickets at the discounted rate."
And I should see "Paiement de vos billets"
And I should see "Pour les paiements par virement, merci d'envoyer le virement d'un montant de 45€ aux coordonnées suivantes :"

@reloadDbWithTestData
Scenario: Refus des emails sans TLD lors de l'achat de billets
Given I am on "/event/forum/tickets"
Expand Down
Loading