Skip to content

Commit 53371bd

Browse files
authored
Merge pull request #4217 from magento-tango/PR-22-17
[tango] PR 22 #17
2 parents eef6a04 + 3149fda commit 53371bd

File tree

9 files changed

+482
-28
lines changed

9 files changed

+482
-28
lines changed

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

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,53 +6,74 @@
66

77
namespace Magento\Customer\Model;
88

9+
use Magento\Customer\Model\ResourceModel\Customer as CustomerResourceModel;
10+
use Magento\Framework\App\ObjectManager;
11+
use Magento\Framework\Exception\NoSuchEntityException;
12+
913
/**
1014
* Customer Authentication update model.
1115
*/
1216
class CustomerAuthUpdate
1317
{
1418
/**
15-
* @var \Magento\Customer\Model\CustomerRegistry
19+
* @var CustomerRegistry
1620
*/
1721
protected $customerRegistry;
1822

1923
/**
20-
* @var \Magento\Customer\Model\ResourceModel\Customer
24+
* @var CustomerResourceModel
2125
*/
2226
protected $customerResourceModel;
2327

2428
/**
25-
* @param \Magento\Customer\Model\CustomerRegistry $customerRegistry
26-
* @param \Magento\Customer\Model\ResourceModel\Customer $customerResourceModel
29+
* @var Customer
30+
*/
31+
private $customerModel;
32+
33+
/**
34+
* @param CustomerRegistry $customerRegistry
35+
* @param CustomerResourceModel $customerResourceModel
36+
* @param Customer|null $customerModel
2737
*/
2838
public function __construct(
29-
\Magento\Customer\Model\CustomerRegistry $customerRegistry,
30-
\Magento\Customer\Model\ResourceModel\Customer $customerResourceModel
39+
CustomerRegistry $customerRegistry,
40+
CustomerResourceModel $customerResourceModel,
41+
Customer $customerModel = null
3142
) {
3243
$this->customerRegistry = $customerRegistry;
3344
$this->customerResourceModel = $customerResourceModel;
45+
$this->customerModel = $customerModel ?: ObjectManager::getInstance()->get(Customer::class);
3446
}
3547

3648
/**
3749
* Reset Authentication data for customer.
3850
*
3951
* @param int $customerId
4052
* @return $this
53+
* @throws NoSuchEntityException
4154
*/
4255
public function saveAuth($customerId)
4356
{
4457
$customerSecure = $this->customerRegistry->retrieveSecureData($customerId);
4558

59+
$this->customerResourceModel->load($this->customerModel, $customerId);
60+
$currentLockExpiresVal = $this->customerModel->getData('lock_expires');
61+
$newLockExpiresVal = $customerSecure->getData('lock_expires');
62+
4663
$this->customerResourceModel->getConnection()->update(
4764
$this->customerResourceModel->getTable('customer_entity'),
4865
[
4966
'failures_num' => $customerSecure->getData('failures_num'),
5067
'first_failure' => $customerSecure->getData('first_failure'),
51-
'lock_expires' => $customerSecure->getData('lock_expires'),
68+
'lock_expires' => $newLockExpiresVal,
5269
],
5370
$this->customerResourceModel->getConnection()->quoteInto('entity_id = ?', $customerId)
5471
);
5572

73+
if ($currentLockExpiresVal !== $newLockExpiresVal) {
74+
$this->customerModel->reindex();
75+
}
76+
5677
return $this;
5778
}
5879
}

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

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@
55
*/
66
namespace Magento\Customer\Test\Unit\Model;
77

8+
use Magento\Customer\Model\Customer as CustomerModel;
89
use Magento\Customer\Model\CustomerAuthUpdate;
10+
use Magento\Customer\Model\CustomerRegistry;
11+
use Magento\Customer\Model\Data\CustomerSecure;
12+
use Magento\Customer\Model\ResourceModel\Customer as CustomerResourceModel;
13+
use Magento\Framework\DB\Adapter\AdapterInterface;
14+
use Magento\Framework\Exception\NoSuchEntityException;
15+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
916

1017
/**
1118
* Class CustomerAuthUpdateTest
@@ -18,17 +25,22 @@ class CustomerAuthUpdateTest extends \PHPUnit\Framework\TestCase
1825
protected $model;
1926

2027
/**
21-
* @var \Magento\Customer\Model\CustomerRegistry|\PHPUnit_Framework_MockObject_MockObject
28+
* @var CustomerRegistry|\PHPUnit_Framework_MockObject_MockObject
2229
*/
2330
protected $customerRegistry;
2431

2532
/**
26-
* @var \Magento\Customer\Model\ResourceModel\Customer|\PHPUnit_Framework_MockObject_MockObject
33+
* @var CustomerResourceModel|\PHPUnit_Framework_MockObject_MockObject
2734
*/
2835
protected $customerResourceModel;
2936

3037
/**
31-
* @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
38+
* @var CustomerModel|\PHPUnit_Framework_MockObject_MockObject
39+
*/
40+
protected $customerModel;
41+
42+
/**
43+
* @var ObjectManager
3244
*/
3345
protected $objectManager;
3446

@@ -37,32 +49,36 @@ class CustomerAuthUpdateTest extends \PHPUnit\Framework\TestCase
3749
*/
3850
protected function setUp()
3951
{
40-
$this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
52+
$this->objectManager = new ObjectManager($this);
4153

4254
$this->customerRegistry =
43-
$this->createMock(\Magento\Customer\Model\CustomerRegistry::class);
55+
$this->createMock(CustomerRegistry::class);
4456
$this->customerResourceModel =
45-
$this->createMock(\Magento\Customer\Model\ResourceModel\Customer::class);
57+
$this->createMock(CustomerResourceModel::class);
58+
$this->customerModel =
59+
$this->createMock(CustomerModel::class);
4660

4761
$this->model = $this->objectManager->getObject(
48-
\Magento\Customer\Model\CustomerAuthUpdate::class,
62+
CustomerAuthUpdate::class,
4963
[
5064
'customerRegistry' => $this->customerRegistry,
5165
'customerResourceModel' => $this->customerResourceModel,
66+
'customerModel' => $this->customerModel
5267
]
5368
);
5469
}
5570

5671
/**
5772
* test SaveAuth
73+
* @throws NoSuchEntityException
5874
*/
5975
public function testSaveAuth()
6076
{
6177
$customerId = 1;
6278

63-
$customerSecureMock = $this->createMock(\Magento\Customer\Model\Data\CustomerSecure::class);
79+
$customerSecureMock = $this->createMock(CustomerSecure::class);
6480

65-
$dbAdapter = $this->createMock(\Magento\Framework\DB\Adapter\AdapterInterface::class);
81+
$dbAdapter = $this->createMock(AdapterInterface::class);
6682

6783
$this->customerRegistry->expects($this->once())
6884
->method('retrieveSecureData')
@@ -98,6 +114,9 @@ public function testSaveAuth()
98114
$customerId
99115
);
100116

117+
$this->customerModel->expects($this->once())
118+
->method('reindex');
119+
101120
$this->model->saveAuth($customerId);
102121
}
103122
}

app/code/Magento/Sales/Block/Adminhtml/Order/Create/Form/Address.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
use Magento\Framework\App\ObjectManager;
1010
use Magento\Framework\Data\Form\Element\AbstractElement;
1111
use Magento\Framework\Pricing\PriceCurrencyInterface;
12+
use Magento\Customer\Api\Data\AddressInterface;
13+
use Magento\Eav\Model\AttributeDataFactory;
1214

1315
/**
1416
* Order create address form
@@ -190,17 +192,19 @@ public function getAddressCollectionJson()
190192
$emptyAddressForm = $this->_customerFormFactory->create(
191193
'customer_address',
192194
'adminhtml_customer_address',
193-
[\Magento\Customer\Api\Data\AddressInterface::COUNTRY_ID => $defaultCountryId]
195+
[AddressInterface::COUNTRY_ID => $defaultCountryId]
194196
);
195-
$data = [0 => $emptyAddressForm->outputData(\Magento\Eav\Model\AttributeDataFactory::OUTPUT_FORMAT_JSON)];
197+
$data = [0 => $emptyAddressForm->outputData(AttributeDataFactory::OUTPUT_FORMAT_JSON)];
196198
foreach ($this->getAddressCollection() as $address) {
197199
$addressForm = $this->_customerFormFactory->create(
198200
'customer_address',
199201
'adminhtml_customer_address',
200-
$this->addressMapper->toFlatArray($address)
202+
$this->addressMapper->toFlatArray($address),
203+
false,
204+
false
201205
);
202206
$data[$address->getId()] = $addressForm->outputData(
203-
\Magento\Eav\Model\AttributeDataFactory::OUTPUT_FORMAT_JSON
207+
AttributeDataFactory::OUTPUT_FORMAT_JSON
204208
);
205209
}
206210

0 commit comments

Comments
 (0)