/**
  * Tests the sendMessage method with no body_html block.
  */
 public function testSendMessageWithNoBodyHtmlBlock()
 {
     $this->twig->expects($this->once())->method('loadTemplate')->will($this->returnValue($this->template));
     $contact = new Contact();
     $this->template->expects($this->exactly(3))->method('renderBlock')->withConsecutive(array($this->equalTo('subject'), $this->equalTo(array('contact' => $contact))), array($this->equalTo('body_text'), $this->equalTo(array('contact' => $contact))), array($this->equalTo('body_html'), $this->equalTo(array('contact' => $contact))))->willReturnOnConsecutiveCalls('', 'Body text', '');
     $message = $this->getMockBuilder('\\Swift_Message')->disableOriginalConstructor()->getMock();
     $message->expects($this->once())->method('setSubject')->willReturnSelf();
     $message->expects($this->once())->method('setFrom')->willReturnSelf();
     $message->expects($this->once())->method('setTo')->willReturnSelf();
     $message->expects($this->once())->method('setBody')->with($this->equalTo('Body text'));
     $message->expects($this->never())->method('addPart');
     $this->serviceMailer->expects($this->once())->method('createMessage')->will($this->returnValue($message));
     $this->mailer->expects($this->once())->method('send')->with($this->equalTo($message));
     $this->serviceMailer->sendMessage($contact);
 }
 public function testRenderWithTwig()
 {
     $this->templater->setLocale('fr');
     $layout = new TwigLayout(__DIR__ . '/../Fixtures/loaders/layout.html.twig');
     $layout->setName('test');
     $layoutTrans = new TwigLayoutTranslation($layout, __DIR__ . '/../Fixtures/loaders/layout.fr.html.twig');
     $layoutTrans->setLocale('fr');
     $mail = new TwigMail(__DIR__ . '/../Fixtures/loaders/mail.html.twig');
     $mailTrans = new TwigMailTranslation($mail, __DIR__ . '/../Fixtures/loaders/mail.fr.html.twig');
     $mailTrans->setLocale('fr');
     $mail->setLayout($layout);
     $trans = $mail->getTranslation('fr');
     $htmlRendered = $mail->getLayout()->getTranslation('fr')->getBody() . ' | ' . $trans->getHtmlBody();
     $twigVariables = array('_mail_type' => MailTypes::TYPE_ALL, '_layout' => 'test');
     $this->assertNull($mail->getTranslationDomain());
     $this->assertCount(1, $mail->getTranslations());
     $this->assertNotNull($mail->getLayout());
     $this->assertNull($mail->getLayout()->getTranslationDomain());
     $this->assertCount(1, $mail->getLayout()->getTranslations());
     $this->loader->expects($this->once())->method('load')->with('test', MailTypes::TYPE_ALL)->will($this->returnValue($mail));
     // render subject
     $this->twigTemplate->expects($this->at(0))->method('renderBlock')->with('subject', $twigVariables)->will($this->returnValue($trans->getSubject()));
     $twigVariables['_subject'] = $trans->getSubject();
     // render html body
     $this->twigTemplate->expects($this->at(1))->method('renderBlock')->with('html_body', $twigVariables)->will($this->returnValue($trans->getHtmlBody()));
     $twigVariables['_html_body'] = $trans->getHtmlBody();
     // render body
     $this->twigTemplate->expects($this->at(2))->method('renderBlock')->with('body', $twigVariables)->will($this->returnValue($trans->getBody()));
     $twigVariables['_body'] = $trans->getBody();
     // render layout
     $this->twigTemplate->expects($this->at(3))->method('renderBlock')->with('body', $twigVariables)->will($this->returnValue($htmlRendered));
     $rendered = $this->templater->render('test', array(), MailTypes::TYPE_ALL);
     $this->assertSame($trans->getSubject(), $rendered->getSubject());
     $this->assertSame($trans->getBody(), $rendered->getBody());
     $this->assertSame($htmlRendered, $rendered->getHtmlBody());
 }