Skip to content

Commit 50f1f4e

Browse files
mahesh-rajawatengcom-Foxtrot
authored andcommitted
Fixed issue #23135 Insert Variable popup missing template variables for new email templates
1 parent 9473b31 commit 50f1f4e

File tree

4 files changed

+77
-73
lines changed

4 files changed

+77
-73
lines changed

app/code/Magento/Email/Block/Adminhtml/Template/Edit/Form.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
*/
1010
namespace Magento\Email\Block\Adminhtml\Template\Edit;
1111

12+
/**
13+
* Adminhtml email template edit form block
14+
*/
1215
class Form extends \Magento\Backend\Block\Widget\Form\Generic
1316
{
1417
/**
@@ -191,7 +194,7 @@ public function getVariables()
191194
}
192195
$template = $this->getEmailTemplate();
193196
if ($template->getId() && ($templateVariables = $template->getVariablesOptionArray(true))) {
194-
$variables = array_merge_recursive($variables, $templateVariables);
197+
$variables = array_merge_recursive($variables, [$templateVariables]);
195198
}
196199
return $variables;
197200
}

app/code/Magento/Email/Model/Template.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ public function getVariablesOptionArray($withGroup = false)
326326
$optionArray[] = ['value' => '{{' . $value . '}}', 'label' => __('%1', $label)];
327327
}
328328
if ($withGroup) {
329-
$optionArray = [['label' => __('Template Variables'), 'value' => $optionArray]];
329+
$optionArray = ['label' => __('Template Variables'), 'value' => $optionArray];
330330
}
331331
}
332332
return $optionArray;

app/code/Magento/Email/Test/Unit/Block/Adminhtml/Template/Edit/FormTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function testGetVariables()
7575
->method('getVariablesOptionArray')
7676
->willReturn(['template var 1', 'template var 2']);
7777
$this->assertEquals(
78-
['var1', 'var2', 'var3', 'custom var 1', 'custom var 2', 'template var 1', 'template var 2'],
78+
['var1', 'var2', 'var3', 'custom var 1', 'custom var 2', ['template var 1', 'template var 2']],
7979
$this->form->getVariables()
8080
);
8181
}

app/code/Magento/Email/Test/Unit/Model/TemplateTest.php

Lines changed: 71 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -173,23 +173,25 @@ protected function getModelMock(array $mockedMethods = [])
173173
{
174174
return $this->getMockBuilder(Template::class)
175175
->setMethods(array_merge($mockedMethods, ['__wakeup', '__sleep', '_init']))
176-
->setConstructorArgs([
177-
$this->context,
178-
$this->design,
179-
$this->registry,
180-
$this->appEmulation,
181-
$this->storeManager,
182-
$this->assetRepo,
183-
$this->filesystem,
184-
$this->scopeConfig,
185-
$this->emailConfig,
186-
$this->templateFactory,
187-
$this->filterManager,
188-
$this->urlModel,
189-
$this->filterFactory,
190-
[],
191-
$this->serializerMock
192-
])
176+
->setConstructorArgs(
177+
[
178+
$this->context,
179+
$this->design,
180+
$this->registry,
181+
$this->appEmulation,
182+
$this->storeManager,
183+
$this->assetRepo,
184+
$this->filesystem,
185+
$this->scopeConfig,
186+
$this->emailConfig,
187+
$this->templateFactory,
188+
$this->filterManager,
189+
$this->urlModel,
190+
$this->filterFactory,
191+
[],
192+
$this->serializerMock
193+
]
194+
)
193195
->getMock();
194196
}
195197

@@ -257,9 +259,7 @@ public function testLoadDefault(
257259
$expectedOrigTemplateVariables,
258260
$expectedTemplateStyles
259261
) {
260-
$model = $this->getModelMock([
261-
'getDesignParams'
262-
]);
262+
$model = $this->getModelMock(['getDesignParams']);
263263

264264
$designParams = [
265265
'area' => Area::AREA_FRONTEND,
@@ -382,13 +382,15 @@ public function loadDefaultDataProvider()
382382
public function testLoadByConfigPath($loadFromDatabase)
383383
{
384384
$configPath = 'design/email/header_template';
385-
$model = $this->getModelMock([
386-
'getDesignConfig',
387-
'loadDefault',
388-
'load',
389-
'getTemplateText',
390-
'setTemplateText',
391-
]);
385+
$model = $this->getModelMock(
386+
[
387+
'getDesignConfig',
388+
'loadDefault',
389+
'load',
390+
'getTemplateText',
391+
'setTemplateText',
392+
]
393+
);
392394

393395
$designConfig = $this->getMockBuilder(\Magento\Framework\DataObject::class)
394396
->setMethods(['getStore'])
@@ -611,21 +613,19 @@ public function getVariablesOptionArrayDataProvider()
611613
'templateVariables' => '{"store url=\"\"":"Store Url","var logo_url":"Email Logo Image Url",'
612614
. '"var customer.name":"Customer Name"}',
613615
'expectedResult' => [
614-
[
615-
'label' => __('Template Variables'),
616-
'value' => [
617-
[
618-
'value' => '{{store url=""}}',
619-
'label' => __('%1', 'Store Url'),
620-
],
621-
[
622-
'value' => '{{var logo_url}}',
623-
'label' => __('%1', 'Email Logo Image Url'),
624-
],
625-
[
626-
'value' => '{{var customer.name}}',
627-
'label' => __('%1', 'Customer Name'),
628-
],
616+
'label' => __('Template Variables'),
617+
'value' => [
618+
[
619+
'value' => '{{store url=""}}',
620+
'label' => __('%1', 'Store Url'),
621+
],
622+
[
623+
'value' => '{{var logo_url}}',
624+
'label' => __('%1', 'Email Logo Image Url'),
625+
],
626+
[
627+
'value' => '{{var customer.name}}',
628+
'label' => __('%1', 'Customer Name'),
629629
],
630630
],
631631
],
@@ -640,13 +640,15 @@ public function getVariablesOptionArrayDataProvider()
640640
*/
641641
public function testProcessTemplate($templateId, $expectedResult)
642642
{
643-
$model = $this->getModelMock([
644-
'load',
645-
'loadDefault',
646-
'getProcessedTemplate',
647-
'applyDesignConfig',
648-
'cancelDesignConfig',
649-
]);
643+
$model = $this->getModelMock(
644+
[
645+
'load',
646+
'loadDefault',
647+
'getProcessedTemplate',
648+
'applyDesignConfig',
649+
'cancelDesignConfig',
650+
]
651+
);
650652
$model->setId($templateId);
651653
if (is_numeric($templateId)) {
652654
$model->expects($this->once())
@@ -698,10 +700,7 @@ public function processTemplateVariable()
698700
*/
699701
public function testProcessTemplateThrowsExceptionNonExistentTemplate()
700702
{
701-
$model = $this->getModelMock([
702-
'loadDefault',
703-
'applyDesignConfig',
704-
]);
703+
$model = $this->getModelMock(['loadDefault', 'applyDesignConfig',]);
705704
$model->expects($this->once())
706705
->method('loadDefault')
707706
->willReturn(true);
@@ -753,23 +752,25 @@ public function testGetType($templateType, $expectedResult)
753752
/** @var Template $model */
754753
$model = $this->getMockBuilder(Template::class)
755754
->setMethods(['_init'])
756-
->setConstructorArgs([
757-
$this->createMock(Context::class),
758-
$this->createMock(Design::class),
759-
$this->createMock(Registry::class),
760-
$this->createMock(Emulation::class),
761-
$this->createMock(StoreManager::class),
762-
$this->createMock(Repository::class),
763-
$this->createMock(Filesystem::class),
764-
$this->createMock(ScopeConfigInterface::class),
765-
$emailConfig,
766-
$this->createMock(TemplateFactory::class),
767-
$this->createMock(FilterManager::class),
768-
$this->createMock(Url::class),
769-
$this->createMock(FilterFactory::class),
770-
[],
771-
$this->createMock(Json::class)
772-
])
755+
->setConstructorArgs(
756+
[
757+
$this->createMock(Context::class),
758+
$this->createMock(Design::class),
759+
$this->createMock(Registry::class),
760+
$this->createMock(Emulation::class),
761+
$this->createMock(StoreManager::class),
762+
$this->createMock(Repository::class),
763+
$this->createMock(Filesystem::class),
764+
$this->createMock(ScopeConfigInterface::class),
765+
$emailConfig,
766+
$this->createMock(TemplateFactory::class),
767+
$this->createMock(FilterManager::class),
768+
$this->createMock(Url::class),
769+
$this->createMock(FilterFactory::class),
770+
[],
771+
$this->createMock(Json::class)
772+
]
773+
)
773774
->getMock();
774775

775776
$model->setTemplateId(10);

0 commit comments

Comments
 (0)