Skip to content

Commit 745d99d

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-90349' into 2.3-develop-pr21
2 parents 78e0d13 + 662a316 commit 745d99d

File tree

9 files changed

+306
-10
lines changed

9 files changed

+306
-10
lines changed

app/code/Magento/Customer/Model/AccountManagement.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -873,6 +873,8 @@ protected function sendEmailConfirmation(CustomerInterface $customer, $redirectU
873873
} catch (MailException $e) {
874874
// If we are not able to send a new account email, this should be ignored
875875
$this->logger->critical($e);
876+
} catch (\UnexpectedValueException $e) {
877+
$this->logger->error($e);
876878
}
877879
}
878880

app/code/Magento/Customer/Test/Unit/Model/AccountManagementTest.php

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1875,4 +1875,105 @@ private function prepareDateTimeFactory()
18751875

18761876
return $dateTime;
18771877
}
1878+
1879+
/**
1880+
* @return void
1881+
*/
1882+
public function testCreateAccountUnexpectedValueException(): void
1883+
{
1884+
$websiteId = 1;
1885+
$storeId = null;
1886+
$defaultStoreId = 1;
1887+
$customerId = 1;
1888+
$customerEmail = 'email@email.com';
1889+
$newLinkToken = '2jh43j5h2345jh23lh452h345hfuzasd96ofu';
1890+
$exception = new \UnexpectedValueException('Template file was not found');
1891+
1892+
$datetime = $this->prepareDateTimeFactory();
1893+
1894+
$address = $this->createMock(\Magento\Customer\Api\Data\AddressInterface::class);
1895+
$address->expects($this->once())
1896+
->method('setCustomerId')
1897+
->with($customerId);
1898+
$store = $this->createMock(\Magento\Store\Model\Store::class);
1899+
$store->expects($this->once())
1900+
->method('getId')
1901+
->willReturn($defaultStoreId);
1902+
$website = $this->createMock(\Magento\Store\Model\Website::class);
1903+
$website->expects($this->atLeastOnce())
1904+
->method('getStoreIds')
1905+
->willReturn([1, 2, 3]);
1906+
$website->expects($this->once())
1907+
->method('getDefaultStore')
1908+
->willReturn($store);
1909+
$customer = $this->createMock(\Magento\Customer\Api\Data\CustomerInterface::class);
1910+
$customer->expects($this->atLeastOnce())
1911+
->method('getId')
1912+
->willReturn($customerId);
1913+
$customer->expects($this->atLeastOnce())
1914+
->method('getEmail')
1915+
->willReturn($customerEmail);
1916+
$customer->expects($this->atLeastOnce())
1917+
->method('getWebsiteId')
1918+
->willReturn($websiteId);
1919+
$customer->expects($this->atLeastOnce())
1920+
->method('getStoreId')
1921+
->willReturn($storeId);
1922+
$customer->expects($this->once())
1923+
->method('setStoreId')
1924+
->with($defaultStoreId);
1925+
$customer->expects($this->once())
1926+
->method('getAddresses')
1927+
->willReturn([$address]);
1928+
$customer->expects($this->once())
1929+
->method('setAddresses')
1930+
->with(null);
1931+
$this->customerRepository->expects($this->once())
1932+
->method('get')
1933+
->with($customerEmail)
1934+
->willReturn($customer);
1935+
$this->share->expects($this->once())
1936+
->method('isWebsiteScope')
1937+
->willReturn(true);
1938+
$this->storeManager->expects($this->atLeastOnce())
1939+
->method('getWebsite')
1940+
->with($websiteId)
1941+
->willReturn($website);
1942+
$this->customerRepository->expects($this->atLeastOnce())
1943+
->method('save')
1944+
->willReturn($customer);
1945+
$this->addressRepository->expects($this->atLeastOnce())
1946+
->method('save')
1947+
->with($address);
1948+
$this->customerRepository->expects($this->once())
1949+
->method('getById')
1950+
->with($customerId)
1951+
->willReturn($customer);
1952+
$this->random->expects($this->once())
1953+
->method('getUniqueHash')
1954+
->willReturn($newLinkToken);
1955+
$customerSecure = $this->createPartialMock(
1956+
\Magento\Customer\Model\Data\CustomerSecure::class,
1957+
['setRpToken', 'setRpTokenCreatedAt', 'getPasswordHash']
1958+
);
1959+
$customerSecure->expects($this->any())
1960+
->method('setRpToken')
1961+
->with($newLinkToken);
1962+
$customerSecure->expects($this->any())
1963+
->method('setRpTokenCreatedAt')
1964+
->with($datetime)
1965+
->willReturnSelf();
1966+
$customerSecure->expects($this->any())
1967+
->method('getPasswordHash')
1968+
->willReturn(null);
1969+
$this->customerRegistry->expects($this->atLeastOnce())
1970+
->method('retrieveSecureData')
1971+
->willReturn($customerSecure);
1972+
$this->emailNotificationMock->expects($this->once())
1973+
->method('newAccount')
1974+
->willThrowException($exception);
1975+
$this->logger->expects($this->once())->method('error')->with($exception);
1976+
1977+
$this->accountManagement->createAccount($customer);
1978+
}
18781979
}

app/code/Magento/Email/Model/AbstractTemplate.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -531,14 +531,13 @@ protected function cancelDesignConfig()
531531
*
532532
* @param string $templateId
533533
* @return $this
534-
* @throws \Magento\Framework\Exception\MailException
535534
*/
536535
public function setForcedArea($templateId)
537536
{
538-
if ($this->area) {
539-
throw new \LogicException(__('The area is already set.'));
537+
if ($this->area === null) {
538+
$this->area = $this->emailConfig->getTemplateArea($templateId);
540539
}
541-
$this->area = $this->emailConfig->getTemplateArea($templateId);
540+
542541
return $this;
543542
}
544543

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,9 @@ public function getTemplateFilename($templateId, $designParams = [])
205205
$designParams['module'] = $module;
206206

207207
$file = $this->_getInfo($templateId, 'file');
208+
$filename = $this->getFilename($file, $designParams, $module);
208209

209-
return $this->viewFileSystem->getEmailTemplateFileName($file, $designParams, $module);
210+
return $filename;
210211
}
211212

212213
/**
@@ -230,4 +231,26 @@ protected function _getInfo($templateId, $fieldName)
230231
}
231232
return $data[$templateId][$fieldName];
232233
}
234+
235+
/**
236+
* Retrieve template file path.
237+
*
238+
* @param string $file
239+
* @param array $designParams
240+
* @param string $module
241+
*
242+
* @return string
243+
*
244+
* @throws \UnexpectedValueException
245+
*/
246+
private function getFilename(string $file, array $designParams, string $module): string
247+
{
248+
$filename = $this->viewFileSystem->getEmailTemplateFileName($file, $designParams, $module);
249+
250+
if ($filename === false) {
251+
throw new \UnexpectedValueException("Template file '{$file}' is not found.");
252+
}
253+
254+
return $filename;
255+
}
233256
}

app/code/Magento/Email/Test/Unit/Model/AbstractTemplateTest.php

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,11 @@ protected function setUp()
117117
/**
118118
* Return the model under test with additional methods mocked.
119119
*
120-
* @param $mockedMethods array
120+
* @param array $mockedMethods
121+
* @param array $data
121122
* @return \Magento\Email\Model\Template|\PHPUnit_Framework_MockObject_MockObject
122123
*/
123-
protected function getModelMock(array $mockedMethods = [])
124+
protected function getModelMock(array $mockedMethods = [], array $data = [])
124125
{
125126
$helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
126127
return $this->getMockForAbstractClass(
@@ -136,7 +137,8 @@ protected function getModelMock(array $mockedMethods = [])
136137
'scopeConfig' => $this->scopeConfig,
137138
'emailConfig' => $this->emailConfig,
138139
'filterFactory' => $this->filterFactory,
139-
'templateFactory' => $this->templateFactory
140+
'templateFactory' => $this->templateFactory,
141+
'data' => $data,
140142
]
141143
),
142144
'',
@@ -431,4 +433,33 @@ public function testGetDesignConfig()
431433
$expectedConfig = ['area' => 'test_area', 'store' => 2];
432434
$this->assertEquals($expectedConfig, $model->getDesignConfig()->getData());
433435
}
436+
437+
/**
438+
* @return void
439+
*/
440+
public function testSetForcedAreaWhenAreaIsNotSet(): void
441+
{
442+
$templateId = 'test_template';
443+
$model = $this->getModelMock([], ['area' => null]);
444+
445+
$this->emailConfig->expects($this->once())
446+
->method('getTemplateArea')
447+
->with($templateId);
448+
449+
$model->setForcedArea($templateId);
450+
}
451+
452+
/**
453+
* @return void
454+
*/
455+
public function testSetForcedAreaWhenAreaIsSet(): void
456+
{
457+
$templateId = 'test_template';
458+
$model = $this->getModelMock([], ['area' => 'frontend']);
459+
460+
$this->emailConfig->expects($this->never())
461+
->method('getTemplateArea');
462+
463+
$model->setForcedArea($templateId);
464+
}
434465
}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,20 @@ public function testGetTemplateFilenameWithNoParams()
272272
$this->assertEquals('_files/Fixture/ModuleOne/view/frontend/email/one.html', $actualResult);
273273
}
274274

275+
/**
276+
* @expectedException \UnexpectedValueException
277+
* @expectedExceptionMessage Template file 'one.html' is not found
278+
* @return void
279+
*/
280+
public function testGetTemplateFilenameWrongFileName(): void
281+
{
282+
$this->viewFileSystem->expects($this->once())->method('getEmailTemplateFileName')
283+
->with('one.html', $this->designParams, 'Fixture_ModuleOne')
284+
->willReturn(false);
285+
286+
$this->model->getTemplateFilename('template_one', $this->designParams);
287+
}
288+
275289
/**
276290
* @param string $getterMethod
277291
* @param $argument

app/code/Magento/Theme/Model/Design/Config/Validator.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ private function getTemplateText($templateId, DesignConfigInterface $designConfi
114114
if (is_numeric($templateId)) {
115115
$template->load($templateId);
116116
} else {
117+
$template->setForcedArea($templateId);
117118
$template->loadDefault($templateId);
118119
}
119120
$text = $template->getTemplateText();

app/code/Magento/Theme/Test/Unit/Model/Config/ValidatorTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function testValidateHasRecursiveReference()
7070
$designElementMock->expects($this->once())->method('getValue')->willReturn($fieldConfig['field']);
7171

7272
$templateMock = $this->getMockBuilder(\Magento\Email\Model\TemplateInterface::class)
73-
->setMethods(['getTemplateText', 'emulateDesign', 'loadDefault', 'revertDesign'])
73+
->setMethods(['getTemplateText', 'emulateDesign', 'loadDefault', 'revertDesign', 'setForcedArea'])
7474
->getMock();
7575

7676
$this->templateFactoryMock->expects($this->once())->method('create')->willReturn($templateMock);
@@ -115,7 +115,7 @@ public function testValidateNoRecursiveReference()
115115
$designElementMock->expects($this->once())->method('getValue')->willReturn($fieldConfig['field']);
116116

117117
$templateMock = $this->getMockBuilder(\Magento\Email\Model\TemplateInterface::class)
118-
->setMethods(['getTemplateText', 'emulateDesign', 'loadDefault', 'revertDesign'])
118+
->setMethods(['getTemplateText', 'emulateDesign', 'loadDefault', 'revertDesign', 'setForcedArea'])
119119
->getMock();
120120

121121
$this->templateFactoryMock->expects($this->once())->method('create')->willReturn($templateMock);

0 commit comments

Comments
 (0)