public function testValidateErrors()
 {
     $trans = new EmailTemplateTranslation();
     $trans->setField('subject')->setContent(self::TEST_TRANS_SUBJECT);
     $this->template->setContent(self::TEST_CONTENT)->setSubject(self::TEST_SUBJECT)->getTranslations()->add($trans);
     $this->twig->expects($this->at(0))->method('render')->with(self::TEST_SUBJECT);
     $this->twig->expects($this->at(1))->method('render')->with(self::TEST_CONTENT);
     $this->twig->expects($this->at(2))->method('render')->with(self::TEST_TRANS_SUBJECT)->will($this->throwException(new \Exception()));
     $this->context->expects($this->once())->method('addViolation')->with($this->variablesConstraint->message);
     $this->validator->validate($this->template, $this->variablesConstraint);
 }
 /**
  * @param string $className
  * @return EmailTemplateSyntaxValidator
  */
 protected function getValidator($className)
 {
     $this->template->setContent(self::TEST_CONTENT)->setSubject(self::TEST_SUBJECT)->setEntityName($className);
     $sandbox = $this->getMockBuilder('\\Twig_Extension_Sandbox')->disableOriginalConstructor()->getMock();
     $sandbox->expects($this->once())->method('enableSandbox');
     $sandbox->expects($this->once())->method('disableSandbox');
     $this->twig->expects($this->once())->method('getExtension')->with($this->equalTo('sandbox'))->will($this->returnValue($sandbox));
     $translator = $this->getMockBuilder('Symfony\\Component\\Translation\\Translator')->disableOriginalConstructor()->getMock();
     $translator->expects($this->any())->method('trans')->will($this->returnArgument(0));
     $validator = new EmailTemplateSyntaxValidator($this->twig, $this->localeSettings, $this->userConfig, $this->entityConfigProvider, $translator);
     $validator->initialize($this->context);
     return $validator;
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->add('entityName', 'hidden', ['attr' => ['data-default-value' => Email::ENTITY_CLASS], 'constraints' => [new Assert\Choice(['choices' => ['', Email::ENTITY_CLASS]])]])->add('type', 'choice', ['label' => 'oro.email.emailtemplate.type.label', 'multiple' => false, 'expanded' => true, 'choices' => ['html' => 'oro.email.datagrid.emailtemplate.filter.type.html', 'txt' => 'oro.email.datagrid.emailtemplate.filter.type.txt'], 'required' => true])->add('translations', 'oro_email_emailtemplate_translatation', ['label' => 'oro.email.emailtemplate.translations.label', 'locales' => $this->getLanguages(), 'labels' => $this->getLocaleLabels(), 'content_options' => ['constraints' => [new Assert\NotBlank()], 'attr' => ['data-default-value' => $this->cm->get('oro_email.signature', '')]], 'subject_options' => ['constraints' => [new Assert\NotBlank()]]])->add('visible', 'checkbox', ['label' => 'oro.email.autoresponserule.form.template.visible.label', 'required' => false]);
     $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
         $form = $event->getForm();
         if ($form->has('owner')) {
             $form->remove('owner');
         }
         if (!$event->getData()) {
             $emailTemplate = new EmailTemplate();
             $emailTemplate->setContent($this->cm->get('oro_email.signature', ''));
             $emailTemplate->setEntityName(Email::ENTITY_CLASS);
             $event->setData($emailTemplate);
         }
     });
     $builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) {
         $template = $event->getData();
         if (!$template || $template->getName()) {
             return;
         }
         $proposedName = $template->getSubject();
         while ($this->templateExists($proposedName)) {
             $proposedName .= rand(0, 10);
         }
         $template->setName($proposedName);
     });
 }