Skip to content

Commit e91b9ff

Browse files
ENGCOM-7961: Fix for #29315: \Magento\Config\Model\Config\Source\Email\Tem… #29316
- Merge Pull Request #29316 from willwright/magento2:issue-29315 - Merged commits: 1. e786d51 2. e0972bf
2 parents 18da36b + e0972bf commit e91b9ff

File tree

2 files changed

+55
-4
lines changed

2 files changed

+55
-4
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,12 @@ public function toOptionArray()
6060
$this->_coreRegistry->register('config_system_email_template', $collection);
6161
}
6262
$options = $collection->toOptionArray();
63-
$templateId = str_replace('/', '_', $this->getPath());
64-
$templateLabel = $this->_emailConfig->getTemplateLabel($templateId);
65-
$templateLabel = __('%1 (Default)', $templateLabel);
66-
array_unshift($options, ['value' => $templateId, 'label' => $templateLabel]);
63+
if (!empty($this->getPath())) {
64+
$templateId = str_replace('/', '_', $this->getPath());
65+
$templateLabel = $this->_emailConfig->getTemplateLabel($templateId);
66+
$templateLabel = __('%1 (Default)', $templateLabel);
67+
array_unshift($options, ['value' => $templateId, 'label' => $templateLabel]);
68+
}
6769
return $options;
6870
}
6971
}

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

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,53 @@ public function testToOptionArray()
102102
$this->_model->setPath('template/new');
103103
$this->assertEquals($expectedResult, $this->_model->toOptionArray());
104104
}
105+
106+
public function testToOptionArrayWithoutPath()
107+
{
108+
$collection = $this->createMock(Collection::class);
109+
$collection->expects(
110+
$this->once()
111+
)->method(
112+
'toOptionArray'
113+
)->willReturn(
114+
[
115+
['value' => 'template_one', 'label' => 'Template One'],
116+
['value' => 'template_two', 'label' => 'Template Two'],
117+
]
118+
);
119+
120+
$this->_coreRegistry->expects(
121+
$this->once()
122+
)->method(
123+
'registry'
124+
)->with(
125+
'config_system_email_template'
126+
)->willReturn(
127+
$collection
128+
);
129+
130+
$this->_emailConfig->expects(
131+
$this->never()
132+
)->method(
133+
'getTemplateLabel'
134+
)->with(
135+
''
136+
)
137+
->willThrowException(
138+
new \UnexpectedValueException("Email template '' is not defined.")
139+
);
140+
141+
$expectedResult = [
142+
[
143+
'value' => 'template_one',
144+
'label' => 'Template One',
145+
],
146+
[
147+
'value' => 'template_two',
148+
'label' => 'Template Two',
149+
],
150+
];
151+
152+
$this->assertEquals($expectedResult, $this->_model->toOptionArray());
153+
}
105154
}

0 commit comments

Comments
 (0)