/** * Sends a message to the admin based on the given type * * @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event Event * @param \DERHANSEN\SfEventMgt\Domain\Model\Registration $registration Registration * @param array $settings Settings * @param int $type Type * * @return bool TRUE if successful, else FALSE */ public function sendAdminMessage($event, $registration, $settings, $type) { list($template, $subject) = $this->getAdminMessageTemplateSubject($settings, $type); if (is_null($event) || is_null($registration || !is_array($settings)) || $event->getNotifyAdmin() === false && $event->getNotifyOrganisator() === false) { return false; } $allEmailsSent = true; $body = $this->getNotificationBody($event, $registration, $template, $settings); $attachments = $this->attachmentService->getAttachments($settings, $registration, $type, MessageRecipient::ADMIN); if ($event->getNotifyAdmin()) { $adminEmailArr = GeneralUtility::trimExplode(',', $settings['notification']['adminEmail'], true); foreach ($adminEmailArr as $adminEmail) { $allEmailsSent = $allEmailsSent && $this->emailService->sendEmailMessage($settings['notification']['senderEmail'], $adminEmail, $subject, $body, $settings['notification']['senderName'], $attachments); } } if ($event->getNotifyOrganisator() && $event->getOrganisator()) { $allEmailsSent = $allEmailsSent && $this->emailService->sendEmailMessage($settings['notification']['senderEmail'], $event->getOrganisator()->getEmail(), $subject, $body, $settings['notification']['senderName'], $attachments); } return $allEmailsSent; }
/** * Test if e-mail-service adds attachment * * @test * @return void */ public function sendEmailMessageWithValidEmailsAddsAttachments() { $sender = '*****@*****.**'; $recipient = '*****@*****.**'; $subject = 'A subject'; $body = 'A body'; $senderName = 'Sender name'; $attachments = [GeneralUtility::getFileAbsFileName('EXT:sf_event_mgt/Tests/Unit/Fixtures/Attachment.txt')]; $mailer = $this->getMock('TYPO3\\CMS\\Core\\Mail\\MailMessage', [], [], '', false); $mailer->expects($this->once())->method('setFrom')->with($this->equalTo($sender), $this->equalTo($senderName)); $mailer->expects($this->once())->method('setSubject')->with($subject); $mailer->expects($this->once())->method('setBody')->with($this->equalTo($body), $this->equalTo('text/html')); $mailer->expects($this->once())->method('setTo')->with($recipient); $mailer->expects($this->once())->method('attach'); $mailer->expects($this->once())->method('send'); $mailer->expects($this->once())->method('isSent')->will($this->returnValue(true)); $this->subject->_set('mailer', $mailer); $result = $this->subject->sendEmailMessage($sender, $recipient, $subject, $body, $senderName, $attachments); $this->assertTrue($result); }
/** * Test if e-mail-service sends mails, if e-mails are valid * * @test * @return void */ public function sendEmailMessageWithValidEmailsTest() { $sender = '*****@*****.**'; $recipient = '*****@*****.**'; $subject = 'A subject'; $body = 'A body'; $senderName = 'Sender name'; $mailer = $this->getMock('TYPO3\\CMS\\Core\\Mail\\MailMessage', array(), array(), '', FALSE); $mailer->expects($this->once())->method('setFrom')->with($this->equalTo($sender), $this->equalTo($senderName)); $mailer->expects($this->once())->method('setSubject')->with($subject); $mailer->expects($this->once())->method('setBody')->with($this->equalTo($body), $this->equalTo('text/html')); $mailer->expects($this->once())->method('setTo')->with($recipient); $mailer->expects($this->once())->method('send'); $mailer->expects($this->once())->method('isSent')->will($this->returnValue(TRUE)); $this->subject->_set('mailer', $mailer); $result = $this->subject->sendEmailMessage($sender, $recipient, $subject, $body, $senderName); $this->assertTrue($result); }
/** * Sends a message to the admin based on the given type * * @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event Event * @param \DERHANSEN\SfEventMgt\Domain\Model\Registration $registration Registration * @param array $settings Settings * @param int $type Type * * @return bool TRUE if successful, else FALSE */ public function sendAdminMessage($event, $registration, $settings, $type) { $template = 'Notification/Admin/RegistrationNew.html'; $subject = $settings['notification']['registrationNew']['adminSubject']; switch ($type) { case MessageType::REGISTRATION_CONFIRMED: $template = 'Notification/Admin/RegistrationConfirmed.html'; $subject = $settings['notification']['registrationConfirmed']['adminSubject']; break; case MessageType::REGISTRATION_NEW: default: } if (is_null($event) || is_null($registration || !is_array($settings)) || $event->getNotifyAdmin() === FALSE && $event->getNotifyOrganisator() === FALSE) { return FALSE; } $allEmailsSent = TRUE; $body = $this->getNotificationBody($event, $registration, $template, $settings); if ($event->getNotifyAdmin()) { $adminEmailArr = GeneralUtility::trimExplode(',', $settings['notification']['adminEmail'], TRUE); foreach ($adminEmailArr as $adminEmail) { $allEmailsSent = $allEmailsSent && $this->emailService->sendEmailMessage($settings['notification']['senderEmail'], $adminEmail, $subject, $body, $settings['notification']['senderName']); } } if ($event->getNotifyOrganisator() && $event->getOrganisator()) { $allEmailsSent = $allEmailsSent && $this->emailService->sendEmailMessage($settings['notification']['senderEmail'], $event->getOrganisator()->getEmail(), $subject, $body, $settings['notification']['senderName']); } return $allEmailsSent; }