Skip to content

Commit

Permalink
Merge pull request #27 from thomas-vermot-synolia/features/use-fake-p…
Browse files Browse the repository at this point in the history
…assword-reset-token

Features/use fake password reset token
  • Loading branch information
oallain authored Jul 1, 2022
2 parents 2b853f3 + 9cf32fa commit 120c7dc
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 21 deletions.
6 changes: 3 additions & 3 deletions features/ui/admin/send_every_mails_in_one.feature
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ Feature: Send every mails in one form
And I write "test" in the field "mail_tester[contact_request][data][message]"
And I write "test@test.com" in the field "mail_tester[my_dummy_form_type][data][email]"
And I write "test" in the field "mail_tester[my_dummy_form_type][data][message]"
And change value for "resettable-password@example.com" in select "mail_tester[password_reset][user]"
And change value for "resettable-password@example.com" in select "mail_tester[user_registration][user]"
And change value for "resettable-password@example.com" in select "mail_tester[verification_token][user]"
And change value for "shop@example.com" in select "mail_tester[password_reset][user]"
And change value for "shop@example.com" in select "mail_tester[user_registration][user]"
And change value for "shop@example.com" in select "mail_tester[verification_token][user]"
Then I submit the email
And the email has been successfully send
1 change: 1 addition & 0 deletions grumphp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ grumphp:
phpstan:
level: ~
configuration: 'ruleset/phpstan.neon'
use_grumphp_paths: false
yamllint:
parse_custom_tags: true
ecs:
Expand Down
4 changes: 3 additions & 1 deletion src/Form/Type/LimitedEntityType.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

class LimitedEntityType extends EntityType
{
private const NUMBER_OF_ITEMS = 25;

public function configureOptions(OptionsResolver $resolver): void
{
parent::configureOptions($resolver);
Expand All @@ -37,7 +39,7 @@ public function configureOptions(OptionsResolver $resolver): void
$resolver
->setNormalizer('query_builder', $queryBuilderNormalizer)
->setDefined('limit')
->setDefault('limit', 20)
->setDefault('limit', self::NUMBER_OF_ITEMS)
->setAllowedTypes('limit', 'int')
;
}
Expand Down
17 changes: 14 additions & 3 deletions src/Form/Type/PasswordTokenResetType.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@

use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\QueryBuilder;
use Sylius\Component\User\Model\UserInterface;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;

final class PasswordTokenResetType extends AbstractMultipleKeysType
{
Expand All @@ -33,10 +36,18 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
->add('user', EntityType::class, [
'class' => $this->syliusShopUserClass,
'query_builder' => function (EntityRepository $entityRepository): QueryBuilder {
return $entityRepository->createQueryBuilder('shop_user')
->where('shop_user.passwordResetToken IS NOT NULL');
return $entityRepository->createQueryBuilder('shop_user');
},
])
;
->addEventListener(
FormEvents::POST_SUBMIT,
function (FormEvent $event) {
/** @var UserInterface $user */
$user = $event->getForm()->get('user')->getData();
if ($user instanceof $this->syliusShopUserClass) {
$user->setPasswordResetToken('TEST_RESET_TOKEN');
}
}
);
}
}
16 changes: 14 additions & 2 deletions src/Form/Type/VerificationTokenType.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@

use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\QueryBuilder;
use Sylius\Component\User\Model\UserInterface;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;

final class VerificationTokenType extends AbstractType
{
Expand All @@ -30,10 +33,19 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
->add('user', EntityType::class, [
'class' => $this->syliusShopUserClass,
'query_builder' => function (EntityRepository $entityRepository): QueryBuilder {
return $entityRepository->createQueryBuilder('shop_user')
->where('shop_user.emailVerificationToken IS NOT NULL');
return $entityRepository->createQueryBuilder('shop_user');
},
])
->addEventListener(
FormEvents::POST_SUBMIT,
function (FormEvent $event) {
/** @var UserInterface $user */
$user = $event->getForm()->get('user')->getData();
if ($user instanceof $this->syliusShopUserClass) {
$user->setEmailVerificationToken('TEST_VERIFICATION_TOKEN');
}
}
)
;
}
}
12 changes: 0 additions & 12 deletions tests/data/config/packages/test/sylius_fixtures.yaml

This file was deleted.

0 comments on commit 120c7dc

Please sign in to comment.