Skip to content

Commit

Permalink
8437:Silent error when an email template is not found
Browse files Browse the repository at this point in the history
  • Loading branch information
RomaKis committed Dec 6, 2017
1 parent 276c690 commit 5e93220
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/code/Magento/Customer/Model/AccountManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,8 @@ protected function sendEmailConfirmation(CustomerInterface $customer, $redirectU
} catch (MailException $e) {
// If we are not able to send a new account email, this should be ignored
$this->logger->critical($e);
} catch (\UnexpectedValueException $e) {
$this->logger->error($e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1721,4 +1721,102 @@ private function prepareDateTimeFactory()

return $dateTime;
}

public function testCreateAccountUnexpectedValueException()
{
$websiteId = 1;
$storeId = null;
$defaultStoreId = 1;
$customerId = 1;
$customerEmail = 'email@email.com';
$newLinkToken = '2jh43j5h2345jh23lh452h345hfuzasd96ofu';
$exception = new \UnexpectedValueException('Template file was not found');

$datetime = $this->prepareDateTimeFactory();

$address = $this->createMock(\Magento\Customer\Api\Data\AddressInterface::class);
$address->expects($this->once())
->method('setCustomerId')
->with($customerId);
$store = $this->createMock(\Magento\Store\Model\Store::class);
$store->expects($this->once())
->method('getId')
->willReturn($defaultStoreId);
$website = $this->createMock(\Magento\Store\Model\Website::class);
$website->expects($this->atLeastOnce())
->method('getStoreIds')
->willReturn([1, 2, 3]);
$website->expects($this->once())
->method('getDefaultStore')
->willReturn($store);
$customer = $this->createMock(\Magento\Customer\Api\Data\CustomerInterface::class);
$customer->expects($this->atLeastOnce())
->method('getId')
->willReturn($customerId);
$customer->expects($this->atLeastOnce())
->method('getEmail')
->willReturn($customerEmail);
$customer->expects($this->atLeastOnce())
->method('getWebsiteId')
->willReturn($websiteId);
$customer->expects($this->atLeastOnce())
->method('getStoreId')
->willReturn($storeId);
$customer->expects($this->once())
->method('setStoreId')
->with($defaultStoreId);
$customer->expects($this->once())
->method('getAddresses')
->willReturn([$address]);
$customer->expects($this->once())
->method('setAddresses')
->with(null);
$this->customerRepository->expects($this->once())
->method('get')
->with($customerEmail)
->willReturn($customer);
$this->share->expects($this->once())
->method('isWebsiteScope')
->willReturn(true);
$this->storeManager->expects($this->atLeastOnce())
->method('getWebsite')
->with($websiteId)
->willReturn($website);
$this->customerRepository->expects($this->atLeastOnce())
->method('save')
->willReturn($customer);
$this->addressRepository->expects($this->atLeastOnce())
->method('save')
->with($address);
$this->customerRepository->expects($this->once())
->method('getById')
->with($customerId)
->willReturn($customer);
$this->random->expects($this->once())
->method('getUniqueHash')
->willReturn($newLinkToken);
$customerSecure = $this->createPartialMock(
\Magento\Customer\Model\Data\CustomerSecure::class,
['setRpToken', 'setRpTokenCreatedAt', 'getPasswordHash']
);
$customerSecure->expects($this->any())
->method('setRpToken')
->with($newLinkToken);
$customerSecure->expects($this->any())
->method('setRpTokenCreatedAt')
->with($datetime)
->willReturnSelf();
$customerSecure->expects($this->any())
->method('getPasswordHash')
->willReturn(null);
$this->customerRegistry->expects($this->atLeastOnce())
->method('retrieveSecureData')
->willReturn($customerSecure);
$this->emailNotificationMock->expects($this->once())
->method('newAccount')
->willThrowException($exception);
$this->logger->expects($this->once())->method('error')->with($exception);

$this->accountManagement->createAccount($customer);
}
}
23 changes: 22 additions & 1 deletion app/code/Magento/Email/Model/Template/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,9 @@ public function getTemplateFilename($templateId, $designParams = [])
$designParams['module'] = $module;

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

return $this->viewFileSystem->getEmailTemplateFileName($file, $designParams, $module);
return $filename;
}

/**
Expand All @@ -230,4 +231,24 @@ protected function _getInfo($templateId, $fieldName)
}
return $data[$templateId][$fieldName];
}

/**
* @param string $file
* @param array $designParams
* @param string $module
*
* @return string
*
* @throws \UnexpectedValueException
*/
private function getFilename($file, array $designParams, $module)
{
$filename = $this->viewFileSystem->getEmailTemplateFileName($file, $designParams, $module);

if ($filename === false) {
throw new \UnexpectedValueException("Template file '{$file}' is not found.");
}

return $filename;
}
}
13 changes: 13 additions & 0 deletions app/code/Magento/Email/Test/Unit/Model/Template/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,19 @@ public function testGetTemplateFilenameWithNoParams()
$this->assertEquals('_files/Fixture/ModuleOne/view/frontend/email/one.html', $actualResult);
}

/**
* @expectedException \UnexpectedValueException
* @expectedExceptionMessage Template file 'one.html' is not found
*/
public function testGetTemplateFilenameWrongFileName()
{
$this->viewFileSystem->expects($this->once())->method('getEmailTemplateFileName')
->with('one.html', $this->designParams, 'Fixture_ModuleOne')
->willReturn(false);

$this->model->getTemplateFilename('template_one', $this->designParams);
}

/**
* @param string $getterMethod
* @param $argument
Expand Down

0 comments on commit 5e93220

Please sign in to comment.