Skip to content

Commit e146a7e

Browse files
authored
ENGCOM-5440: Fixed issue #23135: Insert Variable popup missing template variables for new templates #23173
2 parents 2874522 + 8301c17 commit e146a7e

File tree

5 files changed

+133
-116
lines changed

5 files changed

+133
-116
lines changed

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

Lines changed: 6 additions & 2 deletions
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
/**
@@ -54,7 +57,8 @@ public function __construct(
5457

5558
/**
5659
* Prepare layout.
57-
* Add files to use dialog windows
60+
*
61+
* Add files to use dialog windows.
5862
*
5963
* @return $this
6064
*/
@@ -191,7 +195,7 @@ public function getVariables()
191195
}
192196
$template = $this->getEmailTemplate();
193197
if ($template->getId() && ($templateVariables = $template->getVariablesOptionArray(true))) {
194-
$variables = array_merge_recursive($variables, $templateVariables);
198+
$variables = array_merge_recursive($variables, [$templateVariables]);
195199
}
196200
return $variables;
197201
}

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);

dev/tests/integration/testsuite/Magento/Email/Model/TemplateTest.php

Lines changed: 54 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,23 @@ protected function mockModel($filesystem = null)
5252

5353
$this->model = $this->getMockBuilder(\Magento\Email\Model\Template::class)
5454
->setMethods(['_getMail'])
55-
->setConstructorArgs([
56-
$this->objectManager->get(\Magento\Framework\Model\Context::class),
57-
$this->objectManager->get(\Magento\Framework\View\DesignInterface::class),
58-
$this->objectManager->get(\Magento\Framework\Registry::class),
59-
$this->objectManager->get(\Magento\Store\Model\App\Emulation::class),
60-
$this->objectManager->get(\Magento\Store\Model\StoreManager::class),
61-
$this->objectManager->create(\Magento\Framework\View\Asset\Repository::class),
62-
$filesystem,
63-
$this->objectManager->create(\Magento\Framework\App\Config\ScopeConfigInterface::class),
64-
$this->objectManager->get(\Magento\Email\Model\Template\Config::class),
65-
$this->objectManager->get(\Magento\Email\Model\TemplateFactory::class),
66-
$this->objectManager->get(\Magento\Framework\Filter\FilterManager::class),
67-
$this->objectManager->get(\Magento\Framework\UrlInterface::class),
68-
$this->objectManager->get(\Magento\Email\Model\Template\FilterFactory::class),
69-
])
55+
->setConstructorArgs(
56+
[
57+
$this->objectManager->get(\Magento\Framework\Model\Context::class),
58+
$this->objectManager->get(\Magento\Framework\View\DesignInterface::class),
59+
$this->objectManager->get(\Magento\Framework\Registry::class),
60+
$this->objectManager->get(\Magento\Store\Model\App\Emulation::class),
61+
$this->objectManager->get(\Magento\Store\Model\StoreManager::class),
62+
$this->objectManager->create(\Magento\Framework\View\Asset\Repository::class),
63+
$filesystem,
64+
$this->objectManager->create(\Magento\Framework\App\Config\ScopeConfigInterface::class),
65+
$this->objectManager->get(\Magento\Email\Model\Template\Config::class),
66+
$this->objectManager->get(\Magento\Email\Model\TemplateFactory::class),
67+
$this->objectManager->get(\Magento\Framework\Filter\FilterManager::class),
68+
$this->objectManager->get(\Magento\Framework\UrlInterface::class),
69+
$this->objectManager->get(\Magento\Email\Model\Template\FilterFactory::class),
70+
]
71+
)
7072
->getMock();
7173

7274
$this->objectManager->get(\Magento\Framework\App\State::class)->setAreaCode('frontend');
@@ -122,12 +124,14 @@ public function testGetProcessedTemplate()
122124
->load();
123125

124126
$expectedViewUrl = '/frontend/Magento/blank/en_US/Magento_Theme/favicon.ico';
125-
$this->model->setDesignConfig([
126-
'area' => 'frontend',
127-
'store' => $this->objectManager->get(\Magento\Store\Model\StoreManagerInterface::class)
128-
->getStore('fixturestore')
129-
->getId(),
130-
]);
127+
$this->model->setDesignConfig(
128+
[
129+
'area' => 'frontend',
130+
'store' => $this->objectManager->get(\Magento\Store\Model\StoreManagerInterface::class)
131+
->getStore('fixturestore')
132+
->getId(),
133+
]
134+
);
131135
$this->model->setTemplateText('{{view url="Magento_Theme::favicon.ico"}}');
132136

133137
$this->setNotDefaultThemeForFixtureStore();
@@ -373,9 +377,11 @@ public function testTemplateStylesVariable($area, $expectedOutput, $unexpectedOu
373377
// @styles comments by default, it is necessary to mock an object to return testable contents
374378
$themeDirectory = $this->getMockBuilder(\Magento\Framework\Filesystem\Directory\ReadInterface::class)
375379
->disableOriginalConstructor()
376-
->setMethods([
377-
'readFile',
378-
])
380+
->setMethods(
381+
[
382+
'readFile',
383+
]
384+
)
379385
->getMockForAbstractClass();
380386

381387
$themeDirectory->expects($this->once())
@@ -478,10 +484,12 @@ protected function setUpAdminThemeFallback()
478484
$adminStore = $this->objectManager->create(\Magento\Store\Model\Store::class)
479485
->load(Store::ADMIN_CODE);
480486

481-
$this->model->setDesignConfig([
482-
'area' => 'adminhtml',
483-
'store' => $adminStore->getId(),
484-
]);
487+
$this->model->setDesignConfig(
488+
[
489+
'area' => 'adminhtml',
490+
'store' => $adminStore->getId(),
491+
]
492+
);
485493
}
486494

487495
/**
@@ -516,12 +524,14 @@ protected function setUpThemeFallback($area)
516524
'fixturestore'
517525
);
518526

519-
$this->model->setDesignConfig([
520-
'area' => 'frontend',
521-
'store' => $this->objectManager->get(\Magento\Store\Model\StoreManagerInterface::class)
522-
->getStore('fixturestore')
523-
->getId(),
524-
]);
527+
$this->model->setDesignConfig(
528+
[
529+
'area' => 'frontend',
530+
'store' => $this->objectManager->get(\Magento\Store\Model\StoreManagerInterface::class)
531+
->getStore('fixturestore')
532+
->getId(),
533+
]
534+
);
525535
}
526536

527537
/**
@@ -578,12 +588,14 @@ public function testGetProcessedTemplateSubject()
578588
->load();
579589

580590
$this->model->setTemplateSubject('{{view url="Magento_Theme::favicon.ico"}}');
581-
$this->model->setDesignConfig([
582-
'area' => 'frontend',
583-
'store' => $this->objectManager->get(\Magento\Store\Model\StoreManagerInterface::class)
584-
->getStore('fixturestore')
585-
->getId(),
586-
]);
591+
$this->model->setDesignConfig(
592+
[
593+
'area' => 'frontend',
594+
'store' => $this->objectManager->get(\Magento\Store\Model\StoreManagerInterface::class)
595+
->getStore('fixturestore')
596+
->getId(),
597+
]
598+
);
587599

588600
$this->setNotDefaultThemeForFixtureStore();
589601
$this->assertStringMatchesFormat(
@@ -703,8 +715,8 @@ public function testGetVariablesOptionArrayInGroup()
703715
$testTemplateVariables = '{"var data.name":"Sender Name","var data.email":"Sender Email"}';
704716
$this->model->setOrigTemplateVariables($testTemplateVariables);
705717
$variablesOptionArray = $this->model->getVariablesOptionArray(true);
706-
$this->assertEquals('Template Variables', $variablesOptionArray[0]['label']->getText());
707-
$this->assertEquals($this->model->getVariablesOptionArray(), $variablesOptionArray[0]['value']);
718+
$this->assertEquals('Template Variables', $variablesOptionArray['label']->getText());
719+
$this->assertEquals($this->model->getVariablesOptionArray(), $variablesOptionArray['value']);
708720
}
709721

710722
/**

0 commit comments

Comments
 (0)