mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 17:10:53 +00:00
124 lines
4.6 KiB
PHP
124 lines
4.6 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of the Sylius package.
|
|
*
|
|
* (c) Paweł Jędrzejewski
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Sylius\Tests\Functional\Bundles\ApiBundle\CommandHandler;
|
|
|
|
use Prophecy\Prophecy\ObjectProphecy;
|
|
use Sylius\Bundle\ApiBundle\Command\Account\SendResetPasswordEmail;
|
|
use Sylius\Bundle\ApiBundle\CommandHandler\Account\SendResetPasswordEmailHandler;
|
|
use Sylius\Component\Channel\Repository\ChannelRepositoryInterface;
|
|
use Sylius\Component\Core\Model\ChannelInterface;
|
|
use Sylius\Component\User\Model\UserInterface;
|
|
use Sylius\Component\User\Repository\UserRepositoryInterface;
|
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
|
use Symfony\Component\Filesystem\Filesystem;
|
|
use Symfony\Contracts\Translation\TranslatorInterface;
|
|
|
|
final class SendResetPasswordEmailHandlerTest extends KernelTestCase
|
|
{
|
|
/**
|
|
* @test
|
|
*/
|
|
public function it_sends_password_reset_token_email_without_hostname(): void
|
|
{
|
|
$container = self::getContainer();
|
|
|
|
/** @var TranslatorInterface $translator */
|
|
$translator = $container->get('translator');
|
|
|
|
$emailSender = $container->get('sylius.email_sender');
|
|
|
|
/** @var ChannelRepositoryInterface|ObjectProphecy $channelRepository */
|
|
$channelRepository = $this->prophesize(ChannelRepositoryInterface::class);
|
|
/** @var UserRepositoryInterface|ObjectProphecy $userRepository */
|
|
$userRepository = $this->prophesize(UserRepositoryInterface::class);
|
|
/** @var ChannelInterface|ObjectProphecy $channel */
|
|
$channel = $this->prophesize(ChannelInterface::class);
|
|
/** @var UserInterface|ObjectProphecy $user */
|
|
$user = $this->prophesize(UserInterface::class);
|
|
|
|
$user->getUsername()->willReturn('username');
|
|
$user->getPasswordResetToken()->willReturn('token');
|
|
|
|
$channelRepository->findOneByCode('CHANNEL_CODE')->willReturn($channel->reveal());
|
|
$userRepository->findOneByEmail('user@example.com')->willReturn($user->reveal());
|
|
|
|
$resetPasswordEmailHandler = new SendResetPasswordEmailHandler(
|
|
$emailSender,
|
|
$channelRepository->reveal(),
|
|
$userRepository->reveal()
|
|
);
|
|
|
|
$resetPasswordEmailHandler(new SendResetPasswordEmail(
|
|
'user@example.com',
|
|
'CHANNEL_CODE',
|
|
'en_US'
|
|
));
|
|
|
|
self::assertEmailCount(1);
|
|
$email = self::getMailerMessage();
|
|
self::assertEmailAddressContains($email, 'To', 'user@example.com');
|
|
self::assertEmailHtmlBodyContains(
|
|
$email,
|
|
$translator->trans('sylius.email.password_reset.to_reset_your_password', [], null, 'en_US'),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @test
|
|
*/
|
|
public function it_sends_password_reset_token_email_with_hostname(): void
|
|
{
|
|
$container = self::getContainer();
|
|
|
|
/** @var TranslatorInterface $translator */
|
|
$translator = $container->get('translator');
|
|
|
|
$emailSender = $container->get('sylius.email_sender');
|
|
|
|
/** @var ChannelRepositoryInterface|ObjectProphecy $channelRepository */
|
|
$channelRepository = $this->prophesize(ChannelRepositoryInterface::class);
|
|
/** @var UserRepositoryInterface|ObjectProphecy $userRepository */
|
|
$userRepository = $this->prophesize(UserRepositoryInterface::class);
|
|
/** @var ChannelInterface|ObjectProphecy $channel */
|
|
$channel = $this->prophesize(ChannelInterface::class);
|
|
/** @var UserInterface|ObjectProphecy $user */
|
|
$user = $this->prophesize(UserInterface::class);
|
|
|
|
$user->getUsername()->willReturn('username');
|
|
$user->getPasswordResetToken()->willReturn('token');
|
|
|
|
$channelRepository->findOneByCode('CHANNEL_CODE')->willReturn($channel->reveal());
|
|
$userRepository->findOneByEmail('user@example.com')->willReturn($user->reveal());
|
|
|
|
$resetPasswordEmailHandler = new SendResetPasswordEmailHandler(
|
|
$emailSender,
|
|
$channelRepository->reveal(),
|
|
$userRepository->reveal()
|
|
);
|
|
|
|
$resetPasswordEmailHandler(new SendResetPasswordEmail(
|
|
'user@example.com',
|
|
'CHANNEL_CODE',
|
|
'en_US'
|
|
));
|
|
|
|
self::assertEmailCount(1);
|
|
$email = self::getMailerMessage();
|
|
self::assertEmailAddressContains($email, 'To', 'user@example.com');
|
|
self::assertEmailHtmlBodyContains(
|
|
$email,
|
|
$translator->trans('sylius.email.password_reset.to_reset_your_password', [], null, 'en_US'),
|
|
);
|
|
}
|
|
}
|