Skip to content

Commit d290dc7

Browse files
committed
MAGETWO-56126: Login failed after new custom attribute was added
- unit test for CustomerAuthUpdate
1 parent 91361c4 commit d290dc7

File tree

2 files changed

+117
-2
lines changed

2 files changed

+117
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ public function saveAuth($customerId)
4545

4646
$this->customerResourceModel->getConnection()->update(
4747
$this->customerResourceModel->getTable('customer_entity'),
48-
array(
48+
[
4949
'failures_num' => $customerSecure->getData('failures_num'),
5050
'first_failure' => $customerSecure->getData('first_failure'),
5151
'lock_expires' => $customerSecure->getData('lock_expires'),
52-
),
52+
],
5353
$this->customerResourceModel->getConnection()->quoteInto('entity_id = ?', $customerId)
5454
);
5555

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Test\Unit\Customer\Model;
7+
8+
use Magento\Customer\Model\CustomerAuthUpdate;
9+
10+
/**
11+
* Class CustomerAuthUpdateTest
12+
*/
13+
class CustomerAuthUpdateTest extends \PHPUnit_Framework_TestCase
14+
{
15+
/**
16+
* @var CustomerAuthUpdate
17+
*/
18+
protected $model;
19+
/**
20+
* @var \Magento\Customer\Model\CustomerRegistry|\PHPUnit_Framework_MockObject_MockObject
21+
*/
22+
protected $customerRegistry;
23+
24+
/**
25+
* @var \Magento\Customer\Model\ResourceModel\Customer|\PHPUnit_Framework_MockObject_MockObject
26+
*/
27+
protected $customerResourceModel;
28+
29+
/**
30+
* @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
31+
*/
32+
protected $objectManager;
33+
34+
/**
35+
* Setup the test
36+
*/
37+
protected function setUp()
38+
{
39+
$this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
40+
41+
$className = '\Magento\Customer\Model\CustomerRegistry';
42+
$this->customerRegistry = $this->getMock($className, [], [], '', false);
43+
44+
$className = '\Magento\Customer\Model\ResourceModel\Customer';
45+
$this->customerResourceModel = $this->getMock($className, [], [], '', false);
46+
47+
$this->model = $this->objectManager->getObject(
48+
'\Magento\Customer\Model\CustomerAuthUpdate',
49+
[
50+
'customerRegistry' => $this->customerRegistry,
51+
'customerResourceModel' => $this->customerResourceModel,
52+
]
53+
);
54+
}
55+
56+
/**
57+
* test SaveAuth
58+
*/
59+
public function testSaveAuth()
60+
{
61+
$customerId = 1;
62+
63+
$customerSecureMock = $this->getMock(
64+
\Magento\Customer\Model\Data\CustomerSecure::class,
65+
[],
66+
[],
67+
'',
68+
false
69+
);
70+
71+
$dbAdapter = $this->getMock(
72+
\Magento\Framework\DB\Adapter\AdapterInterface::class,
73+
[],
74+
[],
75+
'',
76+
false
77+
);
78+
79+
$this->customerRegistry->expects($this->once())
80+
->method('retrieveSecureData')
81+
->willReturn($customerSecureMock);
82+
83+
$customerSecureMock->expects($this->exactly(3))
84+
->method('getData')
85+
->willReturn(1);
86+
87+
$this->customerResourceModel->expects($this->any())
88+
->method('getConnection')
89+
->willReturn($dbAdapter);
90+
91+
$this->customerResourceModel->expects($this->any())
92+
->method('getTable')
93+
->willReturn('customer_entity');
94+
95+
$dbAdapter->expects($this->any())
96+
->method('update')
97+
->with(
98+
'customer_entity',
99+
[
100+
'failures_num' => 1,
101+
'first_failure' => 1,
102+
'lock_expires' => 1
103+
]
104+
);
105+
106+
$dbAdapter->expects($this->any())
107+
->method('quoteInto')
108+
->with(
109+
'entity_id = ?',
110+
$customerId
111+
);
112+
113+
$this->model->saveAuth($customerId);
114+
}
115+
}

0 commit comments

Comments
 (0)