public function testSetTemplateData()
 {
     // mailchimp
     $this->assertInstanceOf('\\nickcv\\mandrill\\Message', $this->_message->setTemplateData('viewName', ['money' => 300]));
     $this->assertEquals('viewName', $this->_message->getTemplateName());
     $this->assertEquals([['name' => 'money', 'content' => 300]], $this->_message->getTemplateContent());
     // handlebars
     $this->assertInstanceOf('\\nickcv\\mandrill\\Message', $this->_message->setTemplateData('viewName', ['money' => 300], \nickcv\mandrill\Message::LANGUAGE_HANDLEBARS));
     $this->assertEquals('viewName', $this->_message->getTemplateName());
     $this->assertEquals([['name' => 'money', 'content' => 300]], $this->_message->getGlobalMergeVars());
     $this->assertEquals(\nickcv\mandrill\Message::LANGUAGE_HANDLEBARS, $this->_message->getMandrillMessageArray()['merge_language']);
 }
Exemple #2
0
 /**
  * Sends the specified message.
  *
  * @param Message $message the message to be sent
  * @return boolean whether the message is sent successfully
  */
 protected function sendMessage($message)
 {
     \Yii::info('Sending email "' . $message->getSubject() . '" to "' . implode(', ', $message->getTo()) . '"', self::LOG_CATEGORY);
     try {
         if ($this->useMandrillTemplates) {
             return $this->wasMessageSentSuccesfully($this->_mandrill->messages->sendTemplate($message->getTemplateName(), $message->getTemplateContent(), $message->getMandrillMessageArray(), $message->isAsync()));
         } else {
             return $this->wasMessageSentSuccesfully($this->_mandrill->messages->send($message->getMandrillMessageArray(), $message->isAsync()));
         }
     } catch (Mandrill_Error $e) {
         \Yii::error('A mandrill error occurred: ' . get_class($e) . ' - ' . $e->getMessage(), self::LOG_CATEGORY);
         return false;
     }
 }