public function setUp()
 {
     $this->emailTemplate = new EmailTemplate('update_entity.html.twig', "@subject = sdfdsf\n abc");
     $this->assertEquals('abc', $this->emailTemplate->getContent());
     $this->assertFalse($this->emailTemplate->getIsSystem());
     $this->assertEquals('html', $this->emailTemplate->getType());
 }
 /**
  * @param EmailModel $emailModel
  * @param EmailTemplate $template
  * @param Email $email
  */
 protected function applyTemplate(EmailModel $emailModel, EmailTemplate $template, Email $email)
 {
     $locales = array_merge($email->getAcceptedLocales(), [$this->defaultLocale]);
     $flippedLocales = array_flip($locales);
     $translatedSubjects = [];
     $translatedContents = [];
     foreach ($template->getTranslations() as $translation) {
         switch ($translation->getField()) {
             case 'content':
                 $translatedContents[$translation->getLocale()] = $translation->getContent();
                 break;
             case 'subject':
                 $translatedSubjects[$translation->getLocale()] = $translation->getContent();
                 break;
         }
     }
     $comparator = ArrayUtil::createOrderedComparator($flippedLocales);
     uksort($translatedSubjects, $comparator);
     uksort($translatedContents, $comparator);
     $validContents = array_intersect_key($translatedContents, $flippedLocales);
     $validsubjects = array_intersect_key($translatedSubjects, $flippedLocales);
     $content = reset($validContents);
     $subject = reset($validsubjects);
     $emailModel->setSubject($subject === false ? $template->getSubject() : $subject)->setBody($content === false ? $template->getContent() : $content)->setType($template->getType());
 }
 /**
  * Compile preview content
  *
  * @param EmailTemplate $entity
  *
  * @return string
  */
 public function compilePreview(EmailTemplate $entity)
 {
     // ensure we have no html tags in txt template
     $content = $entity->getContent();
     $content = $entity->getType() == 'txt' ? strip_tags($content) : $content;
     $templateParams['user'] = $this->user;
     $templateRendered = $this->render('{% verbatim %}' . $content . '{% endverbatim %}', $templateParams);
     return $templateRendered;
 }