public function testSendMail() { $defaultEmail = '*****@*****.**'; $event = new MailerEvent(); $event->addUser(User::create('Ma27', '123456', '*****@*****.**')); $event->addUser(User::create('benbieler', '123456', '*****@*****.**')); $event->setTemplateSource('AppBundle:emails:test'); $mailer = $this->getMockWithoutInvokingTheOriginalConstructor(\Swift_Mailer::class); $templatingEngine = $this->getMockWithoutInvokingTheOriginalConstructor(TwigEngine::class); $templatingEngine->expects($this->at(0))->method('render')->with('AppBundle:emails:test.txt.twig', [])->willReturn('Notifications'); $templatingEngine->expects($this->at(1))->method('render')->with('AppBundle:emails:test.html.twig', [])->willReturn('<b>Notifications</b>'); $translator = $this->getMock(TranslatorInterface::class); $translator->expects($this->once())->method('trans')->with('NOTIFICATIONS_SUBJECT', [], 'notifications')->willReturn('Sententiaregum Notifications'); $listener = new MailListener($mailer, $translator, $templatingEngine, $defaultEmail); $listener->onMailEvent($event); }
/** * Sends the activation email. * * @param User $persistentUser */ private function sendActivationEmail(User $persistentUser) { $mailerEvent = new MailerEvent(); $mailerEvent->setTemplateSource('AppBundle:Email/Activation:activation')->addUser($persistentUser)->addParameter('activation_key', $persistentUser->getActivationKey())->addParameter('username', $persistentUser->getUsername()); $this->eventDispatcher->dispatch(MailerEvent::EVENT_NAME, $mailerEvent); }
/** * Renders a mailing part. * * @param MailerEvent $event * @param string $extension * * @return string */ private function renderMailPart(MailerEvent $event, $extension) { return $this->engine->render(sprintf('%s.%s', $event->getTemplateSource(), (string) $extension), $event->getParameters()); }
/** * Dispatches the mailer event. * * @param User $user * @param string $templateName * @param string $eventName */ private function dispatchNotificationEvent(User $user, $templateName, $eventName) { $event = new MailerEvent(); $event->addUser($user)->addParameter('notification_target', $user)->addParameter('tracing_data', $this->ipTracer->getIpLocationData($this->requestStack->getMasterRequest()->getClientIp(), $user->getLocale()))->setTemplateSource(sprintf('AppBundle:Email/AuthAttempt:%s', (string) $templateName)); $this->eventDispatcher->dispatch($eventName, $event); }