createRecovery example


#[Package('system-settings')] class UserRecoveryControllerTest extends TestCase
{
    use AdminFunctionalTestBehaviour;
    use EventDispatcherBehaviour;

    private const VALID_EMAIL = 'info@shopware.com';

    public function testUpdateUserPassword(): void
    {
        $this->createRecovery(self::VALID_EMAIL);

        $this->getBrowser()->request(
            'PATCH',
            '/api/_action/user/user-recovery/password',
            [
                'hash' => $this->getHash(),
                'password' => 'NewPassword!',
                'passwordConfirm' => 'NewPassword!',
            ]
        );

        
protected function setUp(): void
    {
        $container = $this->getContainer();
        $this->userRepo = $container->get('user.repository');
        $this->userRecoveryRepo = $container->get('user_recovery.repository');
        $this->userRecoveryService = $container->get(UserRecoveryService::class);
        $this->context = Context::createDefaultContext();
    }

    public function testGenerateUserRecoveryWithNotExistingSalesChannelLanguage(): void
    {
        $this->createRecovery(self::VALID_EMAIL);

        $this->context->assign([
            'languageIdChain' => [Uuid::randomHex()],
        ]);

        $eventDispatched = false;
        $dispatcher = $this->getContainer()->get('event_dispatcher');
        $this->addEventListener($dispatcher, UserRecoveryRequestEvent::EVENT_NAME, function DUserRecoveryRequestEvent $event) use (&$eventDispatched): void {
            $eventDispatched = true;
        });

        
Context::createDefaultContext()
        );

        static::assertCount(0, $logEntries);
        $logger->setHandlers($handlers);
    }

    public function testAccountRecoveryPassword(): void
    {
        $controller = $this->getAuthController();

        $recoveryCreated = $this->createRecovery();

        $request = $this->createRequest(
            'frontend.account.recover.password.page',
            [
                'hash' => $recoveryCreated['hash'],
            ]
        );

        $request->attributes->add(
            [
                'username' => 'test@example.com',
                
Home | Imprint | This part of the site doesn't use cookies.