Skip to content

Commit 784ac79

Browse files
committed
AC-12397: Email template exception message
1 parent f1e2f5f commit 784ac79

File tree

6 files changed

+73
-11
lines changed

6 files changed

+73
-11
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Email\Model\Template;
77

8+
use Magento\Email\Model\Template\Config\UnexpectedTemplateFieldNameValueException;
9+
use Magento\Email\Model\Template\Config\UnexpectedTemplateIdValueException;
810
use Magento\Framework\Filesystem\Directory\ReadFactory;
911
use Magento\Framework\View\Design\Theme\ThemePackageList;
1012

@@ -218,17 +220,17 @@ public function getTemplateFilename($templateId, $designParams = [])
218220
* @param string $templateId Name of an email template
219221
* @param string $fieldName Name of a field value of which to return
220222
* @return string
221-
* @throws \UnexpectedValueException
223+
* @throws UnexpectedTemplateIdValueException|UnexpectedTemplateFieldNameValueException
222224
*/
223225
protected function _getInfo($templateId, $fieldName)
224226
{
225227
$data = $this->_dataStorage->get();
226228
if (!isset($data[$templateId])) {
227-
throw new \UnexpectedValueException("Email template '{$templateId}' is not defined.");
229+
throw new UnexpectedTemplateIdValueException(__("Email template is not defined."));
228230
}
229231
if (!isset($data[$templateId][$fieldName])) {
230-
throw new \UnexpectedValueException(
231-
"Field '{$fieldName}' is not defined for email template '{$templateId}'."
232+
throw new UnexpectedTemplateFieldNameValueException(
233+
"Field '{$fieldName}' is not defined for email template."
232234
);
233235
}
234236
return $data[$templateId][$fieldName];
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Email\Model\Template\Config;
9+
10+
/**
11+
* Throw exception if email template has unexpected field name value
12+
*/
13+
class UnexpectedTemplateFieldNameValueException extends \UnexpectedValueException
14+
{
15+
/**
16+
* Exception trace
17+
*
18+
* @return string
19+
*/
20+
public function __toString(): string
21+
{
22+
return preg_replace(
23+
"/(Stack trace:).*$/s",
24+
"$1" . PHP_EOL . "#0 {main}",
25+
parent::__toString()
26+
);
27+
}
28+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Email\Model\Template\Config;
9+
10+
/**
11+
* Throw exception if email template has unexpected template id value
12+
*/
13+
class UnexpectedTemplateIdValueException extends \UnexpectedValueException
14+
{
15+
/**
16+
* Exception trace
17+
*
18+
* @return string
19+
*/
20+
public function __toString(): string
21+
{
22+
return preg_replace(
23+
"/(Stack trace:).*$/s",
24+
"$1" . PHP_EOL . "#0 {main}",
25+
parent::__toString()
26+
);
27+
}
28+
}

app/code/Magento/Email/Test/Unit/Model/Template/ConfigTest.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222

2323
class ConfigTest extends TestCase
2424
{
25+
/**
26+
* @var array
27+
*/
2528
private $designParams = [
2629
'area' => Area::AREA_FRONTEND,
2730
'theme' => 'Magento/blank',
@@ -310,7 +313,7 @@ public function testGetTemplateFilenameWrongFileName(): void
310313
public function testGetterMethodUnknownTemplate($getterMethod, $argument = null)
311314
{
312315
$this->expectException('UnexpectedValueException');
313-
$this->expectExceptionMessage('Email template \'unknown\' is not defined');
316+
$this->expectExceptionMessage('Email template is not defined');
314317
if (!$argument) {
315318
$this->model->{$getterMethod}('unknown');
316319
} else {
@@ -374,21 +377,21 @@ public function testGetterMethodUnknownField(
374377
public function getterMethodUnknownFieldDataProvider()
375378
{
376379
return [
377-
'label getter' => ['getTemplateLabel', "Field 'label' is not defined for email template 'fixture'."],
378-
'type getter' => ['getTemplateType', "Field 'type' is not defined for email template 'fixture'."],
380+
'label getter' => ['getTemplateLabel', "Field 'label' is not defined for email template."],
381+
'type getter' => ['getTemplateType', "Field 'type' is not defined for email template."],
379382
'module getter' => [
380383
'getTemplateModule',
381-
"Field 'module' is not defined for email template 'fixture'.",
384+
"Field 'module' is not defined for email template.",
382385
],
383386
'file getter, unknown module' => [
384387
'getTemplateFilename',
385-
"Field 'module' is not defined for email template 'fixture'.",
388+
"Field 'module' is not defined for email template.",
386389
[],
387390
$this->designParams,
388391
],
389392
'file getter, unknown file' => [
390393
'getTemplateFilename',
391-
"Field 'file' is not defined for email template 'fixture'.",
394+
"Field 'file' is not defined for email template.",
392395
['module' => 'Fixture_Module'],
393396
$this->designParams,
394397
],

app/code/Magento/Email/i18n/en_US.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,4 @@ Action,Action
9999
"Header Template","Header Template"
100100
"Footer Template","Footer Template"
101101
"Unable to send mail. Please try again later.","Unable to send mail. Please try again later."
102+
"Email template is not defined.","Email template is not defined."

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ public function testIsValidForSend()
757757
public function testGetTypeNonExistentType()
758758
{
759759
$this->expectException(\UnexpectedValueException::class);
760-
$this->expectExceptionMessage('Email template \'foo\' is not defined.');
760+
$this->expectExceptionMessage('Email template is not defined.');
761761

762762
$this->mockModel();
763763
$this->model->setId('foo');

0 commit comments

Comments
 (0)