Skip to content

Commit

Permalink
ENGCOM-7961: Fix for #29315: \Magento\Config\Model\Config\Source\Emai…
Browse files Browse the repository at this point in the history
…l\Tem… #29316
  • Loading branch information
sidolov authored Aug 20, 2020
2 parents c86883b + e91b9ff commit fe4f3e0
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 4 deletions.
10 changes: 6 additions & 4 deletions app/code/Magento/Config/Model/Config/Source/Email/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,12 @@ public function toOptionArray()
$this->_coreRegistry->register('config_system_email_template', $collection);
}
$options = $collection->toOptionArray();
$templateId = str_replace('/', '_', $this->getPath());
$templateLabel = $this->_emailConfig->getTemplateLabel($templateId);
$templateLabel = __('%1 (Default)', $templateLabel);
array_unshift($options, ['value' => $templateId, 'label' => $templateLabel]);
if (!empty($this->getPath())) {
$templateId = str_replace('/', '_', $this->getPath());
$templateLabel = $this->_emailConfig->getTemplateLabel($templateId);
$templateLabel = __('%1 (Default)', $templateLabel);
array_unshift($options, ['value' => $templateId, 'label' => $templateLabel]);
}
return $options;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,53 @@ public function testToOptionArray()
$this->_model->setPath('template/new');
$this->assertEquals($expectedResult, $this->_model->toOptionArray());
}

public function testToOptionArrayWithoutPath()
{
$collection = $this->createMock(Collection::class);
$collection->expects(
$this->once()
)->method(
'toOptionArray'
)->willReturn(
[
['value' => 'template_one', 'label' => 'Template One'],
['value' => 'template_two', 'label' => 'Template Two'],
]
);

$this->_coreRegistry->expects(
$this->once()
)->method(
'registry'
)->with(
'config_system_email_template'
)->willReturn(
$collection
);

$this->_emailConfig->expects(
$this->never()
)->method(
'getTemplateLabel'
)->with(
''
)
->willThrowException(
new \UnexpectedValueException("Email template '' is not defined.")
);

$expectedResult = [
[
'value' => 'template_one',
'label' => 'Template One',
],
[
'value' => 'template_two',
'label' => 'Template Two',
],
];

$this->assertEquals($expectedResult, $this->_model->toOptionArray());
}
}

0 comments on commit fe4f3e0

Please sign in to comment.