diff --git a/app/code/Magento/Config/Model/Config/Source/Email/Template.php b/app/code/Magento/Config/Model/Config/Source/Email/Template.php index ac168f16ca182..182faa53e5288 100644 --- a/app/code/Magento/Config/Model/Config/Source/Email/Template.php +++ b/app/code/Magento/Config/Model/Config/Source/Email/Template.php @@ -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; } } diff --git a/app/code/Magento/Config/Test/Unit/Model/Config/Source/Email/TemplateTest.php b/app/code/Magento/Config/Test/Unit/Model/Config/Source/Email/TemplateTest.php index 356d1133aca81..9b531280f66c6 100644 --- a/app/code/Magento/Config/Test/Unit/Model/Config/Source/Email/TemplateTest.php +++ b/app/code/Magento/Config/Test/Unit/Model/Config/Source/Email/TemplateTest.php @@ -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()); + } }