35 $this->model = $this->objectManager->create(
47 $url = $this->model->viewDirective(
48 [
'{{view url="Magento_Theme::favicon.ico"}}',
'view',
' url="Magento_Theme::favicon.ico"']
50 $this->assertStringEndsWith(
'favicon.ico',
$url);
62 "{{block class='$class' name='test.block' template='Magento_Theme::html/footer.phtml'}}",
64 " class='$class' name='test.block' template='Magento_Theme::html/footer.phtml'",
66 $html = $this->model->blockDirective(
$data);
67 $this->assertContains(
'<div class="footer-container">', $html);
76 $url = $this->model->storeDirective(
77 [
'{{store direct_url="arbitrary_url/"}}',
'store',
' direct_url="arbitrary_url/"']
79 $this->assertStringMatchesFormat(
'http://example.com/%sarbitrary_url/',
$url);
81 $url = $this->model->storeDirective(
82 [
'{{store url="translation/ajax/index"}}',
'store',
' url="translation/ajax/index"']
84 $this->assertStringMatchesFormat(
'http://example.com/%stranslation/ajax/index/',
$url);
86 $this->model->setStoreId(0);
87 $backendUrlModel = $this->objectManager->create(\
Magento\Backend\Model\Url::class);
88 $this->model->setUrlModel($backendUrlModel);
89 $url = $this->model->storeDirective(
90 [
'{{store url="translation/ajax/index"}}',
'store',
' url="translation/ajax/index"']
92 $this->assertStringMatchesFormat(
'http://example.com/index.php/backend/translation/ajax/index/%A',
$url);
105 public function testLayoutDirective($area, $directiveParams, $expectedOutput)
108 $registration = $this->objectManager->get(\
Magento\Theme\Model\Theme\Registration::class);
109 $registration->register();
110 $this->model = $this->objectManager->create(\
Magento\Email\Model\
Template\Filter::class);
113 $layout = $this->objectManager->create(\
Magento\Framework\View\Layout::class);
114 $this->objectManager->addSharedInstance($layout, \
Magento\Framework\View\Layout::class);
115 $this->objectManager->get(\
Magento\Framework\View\DesignInterface::class)
116 ->setDesignTheme(
'Magento_EmailTest/default');
118 $actualOutput = $this->model->layoutDirective(
119 [
'{{layout ' . $directiveParams .
'}}',
'layout',
' ' . $directiveParams]
121 $this->assertEquals($expectedOutput, trim($actualOutput));
130 'area parameter - omitted' => [
132 'handle="email_template_test_handle"',
133 '<b>Email content for frontend/Magento/default theme</b>',
135 'area parameter - frontend' => [
137 'handle="email_template_test_handle" area="frontend"',
138 '<b>Email content for frontend/Magento/default theme</b>',
140 'area parameter - backend' => [
142 'handle="email_template_test_handle" area="adminhtml"',
143 '<b>Email content for adminhtml/Magento/default theme</b>',
145 'custom parameter' => [
147 'handle="email_template_test_handle" template="Magento_Email::sample_email_content_custom.phtml"',
148 '<b>Custom Email content for frontend/Magento/default theme</b>',
165 $translator = $this->getMockBuilder(\
Magento\Framework\Translate::class)
166 ->disableOriginalConstructor()
167 ->setMethods([
'getData'])
170 $translator->expects($this->atLeastOnce())
172 ->will($this->returnValue($translations));
174 $this->objectManager->addSharedInstance($translator, \
Magento\Framework\Translate::class);
175 $this->objectManager->removeSharedInstance(\
Magento\Framework\
Phrase\Renderer\Translate::class);
178 $this->assertEquals($expectedResult, $this->model->filter($directive));
190 '{{trans "foobar"}}',
195 '{{trans "foobar"}}',
196 [
'foobar' =>
'barfoo'],
216 public function testCssDirective(
$templateType, $directiveParams, $expectedOutput)
219 $registration = $this->objectManager->get(
220 \
Magento\Theme\Model\Theme\Registration::class
222 $registration->register();
224 $this->model->setStoreId(
'fixturestore')
227 $output = $this->model->cssDirective([
'{{css ' . $directiveParams .
'}}',
'css',
' ' . $directiveParams]);
229 if ($expectedOutput !==
'') {
230 $this->assertContains($expectedOutput,
$output);
232 $this->assertSame($expectedOutput,
$output);
242 'CSS from theme' => [
244 'file="css/email-1.css"',
247 'CSS from parent theme' => [
249 'file="css/email-2.css"',
252 'CSS from grandparent theme' => [
254 'file="css/email-3.css"',
257 'Missing file parameter' => [
260 '/* "file" parameter must be specified */' 262 'Plain-text template outputs nothing' => [
264 'file="css/email-1.css"',
267 'Empty or missing file' => [
269 'file="css/non-existent-file.css"',
270 '/* Contents of css/non-existent-file.css could not be loaded or is empty */' 272 'File with compilation error results in error message' => [
274 'file="css/file-with-error.css"',
275 'variable @non-existent-variable is undefined',
297 public function testInlinecssDirective(
300 $productionMode =
false,
301 $plainTemplateMode =
false,
302 $isChildTemplateMode =
false 305 $registration = $this->objectManager->get(
306 \
Magento\Theme\Model\Theme\Registration::class
308 $registration->register();
311 $this->model->setPlainTemplateMode($plainTemplateMode);
312 $this->model->setIsChildTemplate($isChildTemplateMode);
314 $appMode = $productionMode ? State::MODE_PRODUCTION : State::MODE_DEVELOPER;
315 $this->objectManager->get(\
Magento\Framework\
App\State::class)->setMode($appMode);
317 $this->assertContains($expectedOutput, $this->model->filter($templateText));
326 'CSS from theme' => [
327 '<html><p></p> {{inlinecss file="css/email-inline-1.css"}}</html>',
328 '<p style="color: #111; text-align: left;">',
330 'CSS from parent theme' => [
331 '<html><p></p> {{inlinecss file="css/email-inline-2.css"}}</html>',
332 '<p style="color: #222; text-align: left;">',
334 'CSS from grandparent theme' => [
335 '<html><p></p> {{inlinecss file="css/email-inline-3.css"}}',
336 '<p style="color: #333; text-align: left;">',
338 'Non-existent file results in unmodified markup' => [
339 '<html><p></p> {{inlinecss file="css/non-existent-file.css"}}</html>',
340 '<html><p></p> </html>',
342 'Plain template mode results in unmodified markup' => [
343 '<html><p></p> {{inlinecss file="css/email-inline-1.css"}}</html>',
344 '<html><p></p> </html>',
348 'Child template mode results in unmodified directive' => [
349 '<html><p></p> {{inlinecss file="css/email-inline-1.css"}}</html>',
350 '<html><p></p> {{inlinecss file="css/email-inline-1.css"}}</html>',
355 'Production mode - File with compilation error results in structurally unmodified markup' => [
356 '<html><p></p> {{inlinecss file="css/file-with-error.css"}}</html>',
360 'Developer mode - File with compilation error results in error message' => [
361 '<html><p></p> {{inlinecss file="css/file-with-error.css"}}</html>',
362 'CSS inlining error:',
377 public function testInlinecssDirectiveThrowsExceptionWhenMissingParameter($templateText)
380 $registration = $this->objectManager->get(
381 \
Magento\Theme\Model\Theme\Registration::class
383 $registration->register();
386 $this->model->filter($templateText);
395 'Missing "file" parameter' => [
398 'Missing "file" parameter value' => [
399 '{{inlinecss file=""}}',
409 $themeCode =
'Vendor_EmailTest/custom_theme';
410 $this->model->setDesignParams([
412 'theme' => $themeCode,
413 'locale' => Locale::DEFAULT_SYSTEM_LOCALE,
inlinecssDirectiveDataProvider()
cssDirectiveDataProvider()
testTransDirective($directive, $translations, $expectedResult)
transDirectiveDataProvider()
$_option $_optionId $class
inlinecssDirectiveThrowsExceptionWhenMissingParameterDataProvider()
static setRenderer(RendererInterface $renderer)
static getObjectManager()
layoutDirectiveDataProvider()