Working on more email sender stuff

remotes/upstream/api-rewrite
Mike Koch 7 years ago
parent 9832ca58ba
commit e7eeac9f34

@ -25,8 +25,9 @@ class EmailSenderHelper {
$this->mailgunEmailSender = $mailgunEmailSender; $this->mailgunEmailSender = $mailgunEmailSender;
} }
function sendEmailForTicket($emailTemplateName, $ticket, $heskSettings, $modsForHeskSettings) { function sendEmailForTicket($templateId, $languageCode, $ticket, $heskSettings, $modsForHeskSettings) {
//-- parse template $parsedTemplate = $this->emailTemplateParser->getFormattedEmailForLanguage($templateId, $languageCode,
$ticket, $heskSettings, $modsForHeskSettings);
//-- if no mailgun, use basic sender //-- if no mailgun, use basic sender

@ -43,27 +43,27 @@ class EmailTemplateParser {
/** /**
* @param $templateId int * @param $templateId int
* @param $language string * @param $languageCode string
* @param $ticket Ticket * @param $ticket Ticket
* @param $heskSettings array * @param $heskSettings array
* @param $modsForHeskSettings array * @param $modsForHeskSettings array
* @return ParsedEmailProperties * @return ParsedEmailProperties
* @throws InvalidEmailTemplateException * @throws InvalidEmailTemplateException
*/ */
function getFormattedEmailForLanguage($templateId, $language, $ticket, $heskSettings, $modsForHeskSettings) { function getFormattedEmailForLanguage($templateId, $languageCode, $ticket, $heskSettings, $modsForHeskSettings) {
$emailTemplate = $this->emailTemplateRetriever->getTemplate($templateId); $emailTemplate = $this->emailTemplateRetriever->getTemplate($templateId);
if ($emailTemplate === null) { if ($emailTemplate === null) {
throw new InvalidEmailTemplateException($templateId); throw new InvalidEmailTemplateException($templateId);
} }
$template = self::getFromFileSystem($emailTemplate->fileName, $language, false); $template = self::getFromFileSystem($emailTemplate->fileName, $languageCode, false);
$htmlTemplate = self::getFromFileSystem($emailTemplate->fileName, $language, true); $htmlTemplate = self::getFromFileSystem($emailTemplate->fileName, $languageCode, true);
$subject = $emailTemplate->languageKey; $subject = $emailTemplate->languageKey;
$subject = $this->parseSubject($subject, $ticket, $language, $heskSettings); $subject = $this->parseSubject($subject, $ticket, $languageCode, $heskSettings);
$message = $this->parseMessage($template, $ticket, $language, $emailTemplate->forStaff, $heskSettings, $modsForHeskSettings, false); $message = $this->parseMessage($template, $ticket, $languageCode, $emailTemplate->forStaff, $heskSettings, $modsForHeskSettings, false);
$htmlMessage = $this->parseMessage($htmlTemplate, $ticket, $language, $emailTemplate->forStaff, $heskSettings, $modsForHeskSettings, true); $htmlMessage = $this->parseMessage($htmlTemplate, $ticket, $languageCode, $emailTemplate->forStaff, $heskSettings, $modsForHeskSettings, true);
return new ParsedEmailProperties($subject, $message, $htmlMessage); return new ParsedEmailProperties($subject, $message, $htmlMessage);
} }

@ -3,6 +3,7 @@
namespace BusinessLogic\Emails; namespace BusinessLogic\Emails;
use BusinessLogic\Tickets\Ticket;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class EmailSenderHelperTest extends TestCase { class EmailSenderHelperTest extends TestCase {
@ -26,16 +27,38 @@ class EmailSenderHelperTest extends TestCase {
*/ */
private $emailSenderHelper; private $emailSenderHelper;
/**
* @var $heskSettings array
*/
private $heskSettings;
/**
* @var $modsForHeskSettings array
*/
private $modsForHeskSettings;
protected function setUp() { protected function setUp() {
$this->emailTemplateParser = $this->createMock(EmailTemplateParser::class); $this->emailTemplateParser = $this->createMock(EmailTemplateParser::class);
$this->basicEmailSender = $this->createMock(BasicEmailSender::class); $this->basicEmailSender = $this->createMock(BasicEmailSender::class);
$this->mailgunEmailSender = $this->createMock(MailgunEmailSender::class); $this->mailgunEmailSender = $this->createMock(MailgunEmailSender::class);
$this->heskSettings = array();
$this->emailSenderHelper = new EmailSenderHelper($this->emailTemplateParser, $this->basicEmailSender, $this->emailSenderHelper = new EmailSenderHelper($this->emailTemplateParser, $this->basicEmailSender,
$this->mailgunEmailSender); $this->mailgunEmailSender);
} }
function testItParsesTheTemplateForTheTicket() { function testItParsesTheTemplateForTheTicket() {
//-- Arrange
$templateId = EmailTemplateRetriever::NEW_NOTE;
$languageCode = 'en';
$ticket = new Ticket();
//-- Assert
$this->emailTemplateParser->expects($this->once())
->method('getFormattedEmailForLanguage')
->with($templateId, $languageCode, $ticket, $this->heskSettings, $this->modsForHeskSettings);
//-- Act
$this->emailSenderHelper->sendEmailForTicket($templateId, $languageCode, $ticket, $this->heskSettings, $this->modsForHeskSettings);
} }
} }

Loading…
Cancel
Save