/** * @return EmailTemplate */ protected function createTemplate() { $template = new EmailTemplate(); $translation = new EmailTemplateTranslation(); $translation->setLocale(self::LOCALE)->setField('type'); $translations = new ArrayCollection([$translation]); $template->setTranslations($translations); return $template; }
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); }
public function testValidateSandboxErrors() { $trans = new EmailTemplateTranslation(); $trans->setField('subject')->setLocale('fr')->setContent(self::TEST_TRANS_SUBJECT); $this->template->getTranslations()->add($trans); $subjectTokenStream = $this->getMockBuilder('\\Twig_TokenStream')->disableOriginalConstructor()->getMock(); $contentTokenStream = $this->getMockBuilder('\\Twig_TokenStream')->disableOriginalConstructor()->getMock(); $transSubjectTokenStream = $this->getMockBuilder('\\Twig_TokenStream')->disableOriginalConstructor()->getMock(); $tokenizeMap = [[self::TEST_SUBJECT, null, $subjectTokenStream], [self::TEST_CONTENT, null, $contentTokenStream], [self::TEST_TRANS_SUBJECT, null, $transSubjectTokenStream]]; $this->twig->expects($this->exactly(count($tokenizeMap)))->method('tokenize')->will($this->returnValueMap($tokenizeMap)); $this->twig->expects($this->exactly(count($tokenizeMap)))->method('parse')->will($this->throwException(new \Twig_Error_Syntax('message'))); $this->entityConfigProvider->expects($this->exactly(3))->method('hasConfig')->will($this->returnValueMap([[get_class($this->template), 'subject', true], [get_class($this->template), 'content', false]])); $subjectConfig = new Config(new FieldConfigId('entity', get_class($this->template), 'subject', 'string')); $subjectConfig->set('label', 'subject.label'); $this->entityConfigProvider->expects($this->exactly(2))->method('getConfig')->with(get_class($this->template), 'subject')->will($this->returnValue($subjectConfig)); $this->localeSettings->expects($this->exactly(3))->method('getLanguage')->will($this->returnValue('en')); $this->localeSettings->expects($this->exactly(3))->method('getLocalesByCodes')->will($this->returnValueMap([[['en'], 'en', ['en' => 'English']], [['fr'], 'en', ['fr' => 'French']]])); $this->context->expects($this->at(0))->method('addViolation')->with($this->constraint->message, ['{{ field }}' => 'subject.label', '{{ locale }}' => 'English', '{{ error }}' => 'message']); $this->context->expects($this->at(1))->method('addViolation')->with($this->constraint->message, ['{{ field }}' => 'content', '{{ locale }}' => 'English', '{{ error }}' => 'message']); $this->context->expects($this->at(2))->method('addViolation')->with($this->constraint->message, ['{{ field }}' => 'subject.label', '{{ locale }}' => 'French', '{{ error }}' => 'message']); $validator = $this->getValidator(self::ENTITY_CLASS); $validator->validate($this->template, $this->constraint); }