/** * @param EmailTemplate $template * * @return ErrorTrace */ public function validate(EmailTemplate $template) { $this->errorTrace = new ErrorTrace(); $children = $template->getChildren(); $this->check($children); return $this->errorTrace; }
public function execute(EmailTemplate $template) { $header = $this->headerTemplate ? sprintf(static::INCLUDE_EXTENSION, $this->headerTemplate) : ''; $footer = $this->footerTemplate ? sprintf(static::INCLUDE_EXTENSION, $this->footerTemplate) : ''; $cssStyles = $this->stylesTemplate ? sprintf(static::INCLUDE_EXTENSION, $this->stylesTemplate) : ''; $template->setBody(sprintf(static::LAYOUT_EXTENSION, $this->baseEmailTemplate, $cssStyles, $header, $template->getBody(), $footer)); }
public function testValidationMultiDimensionalNotValid() { $emailTemplate = new EmailTemplate(); $emailTemplate->setChildren([new WhiteBlock([new Paragraph()]), new WhiteBlock([new WhiteBlock(), new WhiteBlock([new WhiteBlock([])])]), new WhiteBlock([new NormalText()]), new WhiteBlock([])]); $validator = new Validator([new Validator\Rule\CantBeEmpty(), new Validator\Rule\CheckAllowedChildren()]); $this->assertTrue($validator->validate($emailTemplate)->hasErrors()); $this->assertEquals("0[whiteBlock]0[paragraph] Element property 'children[]' can't be empty\n" . "1[whiteBlock] Element 'whiteBlock' can't have [whiteBlock, whiteBlock] as child. Only [paragraph, header, readOnly] allowed.\n" . "1[whiteBlock]0[whiteBlock] Element property 'children[]' can't be empty\n" . "1[whiteBlock]1[whiteBlock] Element 'whiteBlock' can't have [whiteBlock] as child. Only [paragraph, header, readOnly] allowed.\n" . "1[whiteBlock]1[whiteBlock]0[whiteBlock] Element property 'children[]' can't be empty\n" . "2[whiteBlock] Element 'whiteBlock' can't have [normalText] as child. Only [paragraph, header, readOnly] allowed.\n" . "2[whiteBlock]0[normalText] Element property 'content' can't be empty\n" . "3[whiteBlock] Element property 'children[]' can't be empty", $validator->validate($emailTemplate)->dump()); }
/** * @param $oldBody * @param $newBody * @dataProvider testExecuteDataProvider */ public function testExecute($oldBody, $newBody) { $template = new EmailTemplate(); $template->setBody($oldBody); $command = new EndOfLineFixer(); $command->execute($template); $this->assertEquals($template->getBody(), $newBody); }
/** * @param $base * @param $new * @dataProvider testEmbedBlocksDataProvider */ public function testExecute($base, $new) { $template = new EmailTemplate(); $template->setBody($base); $command = new BlockEmbedder(); $command->execute($template); $this->assertEquals($new, $template->getBody()); }
/** * @param $oldSubject * @param $newSubject * @dataProvider testSubjectVariablesDataProvider */ public function testExecuteOnSubject($oldSubject, $newSubject, $rawVariables) { $template = new EmailTemplate(); $template->setSubject($oldSubject); $command = new VariablesIncluder(); $command->setTemplateVariables($rawVariables); $command->execute($template); $this->assertEquals($template->getSubject(), $newSubject); }
/** * @param $oldBody * @param $newBody * @dataProvider testExecuteDataProvider */ public function testExecute($oldBody, $newBody) { $template = new EmailTemplate(); $template->setBody($oldBody); $template->setTags(['allowed tag']); $command = new NotAllowedTagsRemover(); $command->execute($template); $this->assertEquals($template->getBody(), $newBody); }
public function execute(EmailTemplate $template) { $body = $template->getBody(); $regex = "/{{\\s*(?<variable>.*?)\\s*}}/uis"; preg_match_all($regex, $body, $matches); $foundVariables = $matches['variable']; $availableTags = $template->getTags(); foreach ($foundVariables as $variable) { if (!in_array($variable, $availableTags)) { $search = "/({{\\s*" . preg_quote($variable) . "\\s*}})/ui"; $body = preg_replace($search, $variable, $body, 1); } } $template->setBody($body); }
public function execute(EmailTemplate $template) { $body = $template->getBody(); $regex = '/(?<instruction>{%.*?%})/uis'; preg_match_all($regex, $body, $matches); $foundInstructions = $matches['instruction']; foreach ($foundInstructions as $instruction) { // the only instructions we don't "escape" is "block" cause we need it :) if (strpos($instruction, 'block') || strpos($instruction, 'endblock')) { continue; } $search = "/{$instruction}/uis"; $body = preg_replace($search, '', $body, 1); } $template->setBody($body); }
public function testProcessTemplate() { $body = <<<'EOL' Welcome to Street Team, {{firstname}}! {% block default %} emphasized block {% endblock default %} block normal {% block default %} another emphasized block {% endblock default %} {{request_tickets_button}} {{application_name}} EOL; $expected = <<<'EOL' {% embed '::email_base.html.twig' %} {% block style %}{% endblock style %} {% block header %}{% endblock header %} {% block content %}Welcome to Street Team, {{firstname}}!<br /> {% embed "::EmailBlocks/default.html.twig" %}{% block default %}<br /> emphasized block<br /> {% endblock default %}{% endembed %}<br /> <br /> block normal<br /> <br /> {% embed "::EmailBlocks/default.html.twig" %}{% block default %}<br /> another emphasized block<br /> {% endblock default %}{% endembed %}<br /> <br /> {{request_tickets_button}}<br /> <br /> {{application_name}}{% endblock content %} {% block footer %}{% endblock footer %} {% endembed %} EOL; $template = new EmailTemplate(); $template->setBody($body); $template->setTags(['request_tickets_button', 'firstname', 'application_name']); $template->setBlocks(['default']); $enricher = $this->getEnricher(); $enricher->processTemplate($template); $this->assertEquals($expected, $template->getBody()); }
public function testExecute() { $templateName = '::someTestTemplate.html.twig'; $oldBody = 'Hi! This message is for you, {{ firstname }} {{ lastname }} how about {% embed "::EmailBlocks/miscBlock.html.twig" %}{% block miscBlock %}some misc info{% endblock miscBlock %}{% endembed %}'; $newBody = "{% embed '" . $templateName . "' %}\n{% block style %}{% include \"::test_styles.html.twig\" %}{% endblock style %}\n{% block header %}{% include \"::test_header.html.twig\" %}{% endblock header %}\n{% block content %}" . $oldBody . '{% endblock content %} {% block footer %}{% include "::test_footer.html.twig" %}{% endblock footer %} {% endembed %}'; $command = new TemplateExtender(); $command->setBaseEmailTemplate($templateName); $command->setHeaderTemplate('::test_header.html.twig'); $command->setFooterTemplate('::test_footer.html.twig'); $command->setStylesTemplate('::test_styles.html.twig'); $template = new EmailTemplate(); $template->setBody($oldBody); $command->execute($template); $this->assertEquals($newBody, $template->getBody()); }
/** * @param EmailTemplate $template */ public function execute(EmailTemplate $template) { $template->setSubject($this->process($template->getSubject())); $template->setBody($this->process($template->getBody())); }
public function execute(EmailTemplate $template) { $body = $template->getBody(); $body = nl2br($body); $template->setBody($body); }
public function execute(EmailTemplate $template) { $body = $template->getBody(); $updated = $this->replaceBlocksWithBlocksEmbed($body); $template->setBody($updated); }