Skip to content

Commit a518a12

Browse files
Merge pull request #1640 from magento-engcom/2.1-develop-prs
[EngCom] Public Pull Requests - 2.1-develop - MAGETWO-82980: [Backport 2.1-develop] Fix AcountManagementTest unit test fail randomly #11606 - MAGETWO-82959: Fix #11729 - negative value in excel export[M2.1] #11758
2 parents d4ab99b + 998792c commit a518a12

File tree

3 files changed

+101
-48
lines changed

3 files changed

+101
-48
lines changed

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

Lines changed: 46 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use Magento\Customer\Api\Data\AddressInterface;
1313
use Magento\Customer\Api\Data\CustomerInterface;
1414
use Magento\Customer\Api\Data\ValidationResultsInterfaceFactory;
15-
use Magento\Customer\Model\EmailNotificationInterface;
1615
use Magento\Customer\Helper\View as CustomerViewHelper;
1716
use Magento\Customer\Model\Config\Share as ConfigShare;
1817
use Magento\Customer\Model\Customer as CustomerModel;
@@ -22,6 +21,7 @@
2221
use Magento\Framework\App\Area;
2322
use Magento\Framework\App\Config\ScopeConfigInterface;
2423
use Magento\Framework\App\ObjectManager;
24+
use Magento\Framework\DataObjectFactory as ObjectFactory;
2525
use Magento\Framework\Encryption\EncryptorInterface as Encryptor;
2626
use Magento\Framework\Encryption\Helper\Security;
2727
use Magento\Framework\Event\ManagerInterface;
@@ -30,22 +30,22 @@
3030
use Magento\Framework\Exception\InputException;
3131
use Magento\Framework\Exception\InvalidEmailOrPasswordException;
3232
use Magento\Framework\Exception\LocalizedException;
33+
use Magento\Framework\Exception\MailException;
3334
use Magento\Framework\Exception\NoSuchEntityException;
3435
use Magento\Framework\Exception\State\ExpiredException;
3536
use Magento\Framework\Exception\State\InputMismatchException;
3637
use Magento\Framework\Exception\State\InvalidTransitionException;
37-
use Magento\Framework\DataObjectFactory as ObjectFactory;
3838
use Magento\Framework\Exception\State\UserLockedException;
39-
use Magento\Framework\Registry;
40-
use Magento\Store\Model\ScopeInterface;
41-
use Psr\Log\LoggerInterface as PsrLogger;
42-
use Magento\Framework\Exception\MailException;
39+
use Magento\Framework\Intl\DateTimeFactory;
4340
use Magento\Framework\Mail\Template\TransportBuilder;
4441
use Magento\Framework\Math\Random;
4542
use Magento\Framework\Reflection\DataObjectProcessor;
43+
use Magento\Framework\Registry;
4644
use Magento\Framework\Stdlib\DateTime;
4745
use Magento\Framework\Stdlib\StringUtils as StringHelper;
46+
use Magento\Store\Model\ScopeInterface;
4847
use Magento\Store\Model\StoreManagerInterface;
48+
use Psr\Log\LoggerInterface as PsrLogger;
4949

5050
/**
5151
* Handle various customer account actions
@@ -287,6 +287,11 @@ class AccountManagement implements AccountManagementInterface
287287
*/
288288
private $eavValidator;
289289

290+
/**
291+
* @var DateTimeFactory
292+
*/
293+
private $dateTimeFactory;
294+
290295
/**
291296
* @param CustomerFactory $customerFactory
292297
* @param ManagerInterface $eventManager
@@ -311,6 +316,7 @@ class AccountManagement implements AccountManagementInterface
311316
* @param CustomerModel $customerModel
312317
* @param ObjectFactory $objectFactory
313318
* @param ExtensibleDataObjectConverter $extensibleDataObjectConverter
319+
* @param DateTimeFactory $dateTimeFactory
314320
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
315321
*/
316322
public function __construct(
@@ -336,7 +342,8 @@ public function __construct(
336342
DateTime $dateTime,
337343
CustomerModel $customerModel,
338344
ObjectFactory $objectFactory,
339-
ExtensibleDataObjectConverter $extensibleDataObjectConverter
345+
ExtensibleDataObjectConverter $extensibleDataObjectConverter,
346+
DateTimeFactory $dateTimeFactory = null
340347
) {
341348
$this->customerFactory = $customerFactory;
342349
$this->eventManager = $eventManager;
@@ -361,6 +368,7 @@ public function __construct(
361368
$this->customerModel = $customerModel;
362369
$this->objectFactory = $objectFactory;
363370
$this->extensibleDataObjectConverter = $extensibleDataObjectConverter;
371+
$this->dateTimeFactory = $dateTimeFactory ?: ObjectManager::getInstance()->get(DateTimeFactory::class);
364372
}
365373

366374
/**
@@ -370,7 +378,6 @@ public function __construct(
370378
*/
371379
private function getAuthentication()
372380
{
373-
374381
if (!($this->authentication instanceof AuthenticationInterface)) {
375382
return \Magento\Framework\App\ObjectManager::getInstance()->get(
376383
\Magento\Customer\Model\AuthenticationInterface::class
@@ -603,16 +610,16 @@ protected function makeRequiredCharactersCheck($password)
603610
$return = 0;
604611

605612
if (preg_match('/[0-9]+/', $password)) {
606-
$counter ++;
613+
$counter++;
607614
}
608615
if (preg_match('/[A-Z]+/', $password)) {
609-
$counter ++;
616+
$counter++;
610617
}
611618
if (preg_match('/[a-z]+/', $password)) {
612-
$counter ++;
619+
$counter++;
613620
}
614621
if (preg_match('/[^a-zA-Z0-9]+/', $password)) {
615-
$counter ++;
622+
$counter++;
616623
}
617624

618625
if ($counter < $requiredNumber) {
@@ -717,12 +724,12 @@ public function createAccountWithPasswordHash(CustomerInterface $customer, $hash
717724
}
718725
try {
719726
foreach ($customerAddresses as $address) {
720-
if ($address->getId()) {
727+
if ($address->getId()) {
721728
$newAddress = clone $address;
722729
$newAddress->setId(null);
723730
$newAddress->setCustomerId($customer->getId());
724731
$this->addressRepository->save($newAddress);
725-
} else {
732+
} else {
726733
$address->setCustomerId($customer->getId());
727734
$this->addressRepository->save($address);
728735
}
@@ -871,16 +878,14 @@ public function validate(CustomerInterface $customer)
871878

872879
$result = $this->getEavValidator()->isValid($customerModel);
873880
if ($result === false && is_array($this->getEavValidator()->getMessages())) {
874-
return $validationResults->setIsValid(false)
875-
->setMessages(
876-
call_user_func_array(
877-
'array_merge',
878-
$this->getEavValidator()->getMessages()
879-
)
880-
);
881+
return $validationResults->setIsValid(false)->setMessages(
882+
call_user_func_array(
883+
'array_merge',
884+
$this->getEavValidator()->getMessages()
885+
)
886+
);
881887
}
882-
return $validationResults->setIsValid(true)
883-
->setMessages([]);
888+
return $validationResults->setIsValid(true)->setMessages([]);
884889
}
885890

886891
/**
@@ -930,10 +935,12 @@ public function isCustomerInStore($customerWebsiteId, $storeId)
930935
private function validateResetPasswordToken($customerId, $resetPasswordLinkToken)
931936
{
932937
if (empty($customerId) || $customerId < 0) {
933-
throw new InputException(__(
934-
'Invalid value of "%value" provided for the %fieldName field.',
935-
['value' => $customerId, 'fieldName' => 'customerId']
936-
));
938+
throw new InputException(
939+
__(
940+
'Invalid value of "%value" provided for the %fieldName field.',
941+
['value' => $customerId, 'fieldName' => 'customerId']
942+
)
943+
);
937944
}
938945
if (!is_string($resetPasswordLinkToken) || empty($resetPasswordLinkToken)) {
939946
$params = ['fieldName' => 'resetPasswordLinkToken'];
@@ -1090,12 +1097,11 @@ protected function sendEmailTemplate(
10901097
$email = $customer->getEmail();
10911098
}
10921099

1093-
$transport = $this->transportBuilder->setTemplateIdentifier($templateId)
1094-
->setTemplateOptions(['area' => Area::AREA_FRONTEND, 'store' => $storeId])
1095-
->setTemplateVars($templateParams)
1096-
->setFrom($this->scopeConfig->getValue($sender, ScopeInterface::SCOPE_STORE, $storeId))
1097-
->addTo($email, $this->customerViewHelper->getCustomerName($customer))
1098-
->getTransport();
1100+
$transport = $this->transportBuilder->setTemplateIdentifier($templateId)->setTemplateOptions(
1101+
['area' => Area::AREA_FRONTEND, 'store' => $storeId]
1102+
)->setTemplateVars($templateParams)->setFrom(
1103+
$this->scopeConfig->getValue($sender, ScopeInterface::SCOPE_STORE, $storeId)
1104+
)->addTo($email, $this->customerViewHelper->getCustomerName($customer))->getTransport();
10991105

11001106
$transport->sendMessage();
11011107

@@ -1159,8 +1165,8 @@ public function isResetPasswordLinkTokenExpired($rpToken, $rpTokenCreatedAt)
11591165

11601166
$expirationPeriod = $this->customerModel->getResetPasswordLinkExpirationPeriod();
11611167

1162-
$currentTimestamp = (new \DateTime())->getTimestamp();
1163-
$tokenTimestamp = (new \DateTime($rpTokenCreatedAt))->getTimestamp();
1168+
$currentTimestamp = $this->dateTimeFactory->create()->getTimestamp();
1169+
$tokenTimestamp = $this->dateTimeFactory->create($rpTokenCreatedAt)->getTimestamp();
11641170
if ($tokenTimestamp > $currentTimestamp) {
11651171
return true;
11661172
}
@@ -1196,7 +1202,9 @@ public function changeResetPasswordLinkToken($customer, $passwordLinkToken)
11961202
if (is_string($passwordLinkToken) && !empty($passwordLinkToken)) {
11971203
$customerSecure = $this->customerRegistry->retrieveSecureData($customer->getId());
11981204
$customerSecure->setRpToken($passwordLinkToken);
1199-
$customerSecure->setRpTokenCreatedAt((new \DateTime())->format(DateTime::DATETIME_PHP_FORMAT));
1205+
$customerSecure->setRpTokenCreatedAt(
1206+
$this->dateTimeFactory->create()->format(DateTime::DATETIME_PHP_FORMAT)
1207+
);
12001208
$this->customerRepository->save($customer);
12011209
}
12021210
return true;
@@ -1285,8 +1293,8 @@ protected function getFullCustomerObject($customer)
12851293
// No need to flatten the custom attributes or nested objects since the only usage is for email templates and
12861294
// object passed for events
12871295
$mergedCustomerData = $this->customerRegistry->retrieveSecureData($customer->getId());
1288-
$customerData = $this->dataProcessor
1289-
->buildOutputDataArray($customer, '\Magento\Customer\Api\Data\CustomerInterface');
1296+
$customerData =
1297+
$this->dataProcessor->buildOutputDataArray($customer, '\Magento\Customer\Api\Data\CustomerInterface');
12901298
$mergedCustomerData->addData($customerData);
12911299
$mergedCustomerData->setData('name', $this->customerViewHelper->getCustomerName($customer));
12921300
return $mergedCustomerData;

0 commit comments

Comments
 (0)