public function testThumbnailCanRenderHtmlAttributesGivenByTheProvider()
 {
     $mediaExtension = new MediaExtension($this->getMediaService(), $this->getMediaManager());
     $mediaExtension->initRuntime($this->getEnvironment());
     $media = $this->getMedia();
     $format = 'png';
     $options = array('title' => 'Test title');
     $provider = $this->getProvider();
     $provider->expects($this->once())->method('getHelperProperties')->with($media, $format, $options)->willReturn(array('title' => 'Test title', 'data-custom' => 'foo'));
     $template = $this->getTemplate();
     $template->expects($this->once())->method('render')->with($this->equalTo(array('media' => $media, 'options' => array('title' => 'Test title', 'data-custom' => 'foo'))));
     $mediaExtension->thumbnail($media, $format, $options);
 }
Beispiel #2
0
 /**
  * @param string $templateName
  * @param array  $context
  * @param string $fromEmail
  * @param string $senderName
  * @param string $toEmail
  * @param string $bccEmail
  */
 protected function sendMessage($templateName, $context, $fromEmail, $senderName, $toEmail, $bccEmail)
 {
     $message = \Swift_Message::newInstance();
     if (isset($context['media'])) {
         $path = sprintf('%s/../web%s', $this->rootDir, $this->sonataMediaTwigExtension->path($context['media'], 'cover'));
         $cid = $message->embed(\Swift_Image::fromPath($path));
         $context['cid'] = $cid;
     }
     $context = $this->twig->mergeGlobals($context);
     $template = $this->twig->loadTemplate($templateName);
     $subject = $template->renderBlock('subject', $context);
     $htmlBody = $template->renderBlock('body_html', $context);
     $message->setSubject($subject)->setFrom($fromEmail, $senderName)->setSender($fromEmail, $senderName)->setTo($toEmail)->setBcc($bccEmail)->setBody($htmlBody, 'text/html');
     $this->mailer->send($message);
 }