Skip to content

Commit 6047576

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-52782' into BUGS
2 parents c91f643 + e710652 commit 6047576

File tree

3 files changed

+82
-14
lines changed

3 files changed

+82
-14
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,4 +1328,24 @@ public function isCustomerLocked()
13281328
}
13291329
return false;
13301330
}
1331+
1332+
/**
1333+
* Return Password Confirmation
1334+
*
1335+
* @return string
1336+
*/
1337+
public function getPasswordConfirm()
1338+
{
1339+
return (string) $this->getData('password_confirm');
1340+
}
1341+
1342+
/**
1343+
* Return Password Confirmation
1344+
*
1345+
* @return string
1346+
*/
1347+
public function getPassword()
1348+
{
1349+
return (string) $this->getData('password');
1350+
}
13311351
}

app/code/Magento/Customer/Model/Customer/Attribute/Backend/Password.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function beforeSave($object)
5353
);
5454
}
5555

56-
if (trim($password) != $password) {
56+
if (trim($password) !== $password) {
5757
throw new LocalizedException(__('The password can not begin or end with a space.'));
5858
}
5959

@@ -68,7 +68,7 @@ public function beforeSave($object)
6868
public function validate($object)
6969
{
7070
$password = $object->getPassword();
71-
if ($password && $password == $object->getPasswordConfirm()) {
71+
if ($password && $password === $object->getPasswordConfirm()) {
7272
return true;
7373
}
7474

app/code/Magento/Customer/Test/Unit/Model/Customer/Attribute/Backend/PasswordTest.php

Lines changed: 60 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
namespace Magento\Customer\Test\Unit\Model\Customer\Attribute\Backend;
88

9+
use Magento\Framework\DataObject;
910
use Magento\Framework\Stdlib\StringUtils;
1011
use Magento\Customer\Model\Customer\Attribute\Backend\Password;
1112

@@ -25,14 +26,15 @@ protected function setUp()
2526
public function testValidatePositive()
2627
{
2728
$password = 'password';
28-
$object = $this->getMockBuilder('Magento\Framework\DataObject')
29+
30+
/** @var DataObject|\PHPUnit_Framework_MockObject_MockObject $object */
31+
$object = $this->getMockBuilder(DataObject::class)
2932
->disableOriginalConstructor()
3033
->setMethods(['getPassword', 'getPasswordConfirm'])
3134
->getMock();
3235

33-
$object->expects($this->once())->method('getPassword')->will($this->returnValue($password));
34-
$object->expects($this->once())->method('getPasswordConfirm')->will($this->returnValue($password));
35-
/** @var \Magento\Framework\DataObject $object */
36+
$object->expects($this->once())->method('getPassword')->willReturn($password);
37+
$object->expects($this->once())->method('getPasswordConfirm')->willReturn($password);
3638

3739
$this->assertTrue($this->testable->validate($object));
3840
}
@@ -52,13 +54,13 @@ public function passwordNegativeDataProvider()
5254
*/
5355
public function testBeforeSaveNegative($password)
5456
{
55-
$object = $this->getMockBuilder('Magento\Framework\DataObject')
57+
/** @var DataObject|\PHPUnit_Framework_MockObject_MockObject $object */
58+
$object = $this->getMockBuilder(DataObject::class)
5659
->disableOriginalConstructor()
5760
->setMethods(['getPassword'])
5861
->getMock();
5962

60-
$object->expects($this->once())->method('getPassword')->will($this->returnValue($password));
61-
/** @var \Magento\Framework\DataObject $object */
63+
$object->expects($this->once())->method('getPassword')->willReturn($password);
6264

6365
$this->testable->beforeSave($object);
6466
}
@@ -67,16 +69,62 @@ public function testBeforeSavePositive()
6769
{
6870
$password = 'more-then-6';
6971
$passwordHash = 'password-hash';
70-
$object = $this->getMockBuilder('Magento\Framework\DataObject')
72+
73+
/** @var DataObject|\PHPUnit_Framework_MockObject_MockObject $object */
74+
$object = $this->getMockBuilder(DataObject::class)
7175
->disableOriginalConstructor()
7276
->setMethods(['getPassword', 'setPasswordHash', 'hashPassword'])
7377
->getMock();
7478

75-
$object->expects($this->once())->method('getPassword')->will($this->returnValue($password));
76-
$object->expects($this->once())->method('hashPassword')->will($this->returnValue($passwordHash));
77-
$object->expects($this->once())->method('setPasswordHash')->with($passwordHash)->will($this->returnSelf());
78-
/** @var \Magento\Framework\DataObject $object */
79+
$object->expects($this->once())->method('getPassword')->willReturn($password);
80+
$object->expects($this->once())->method('hashPassword')->willReturn($passwordHash);
81+
$object->expects($this->once())->method('setPasswordHash')->with($passwordHash)->willReturnSelf();
7982

8083
$this->testable->beforeSave($object);
8184
}
85+
86+
/**
87+
* @return array
88+
*/
89+
public function randomValuesProvider()
90+
{
91+
return [
92+
[false],
93+
[1],
94+
["23"],
95+
[null],
96+
[""],
97+
[-1],
98+
[12.3],
99+
[true],
100+
[0],
101+
];
102+
}
103+
104+
/**
105+
* @dataProvider randomValuesProvider
106+
* @param mixed $randomValue
107+
*/
108+
public function testCustomerGetPasswordAndGetPasswordConfirmAlwaysReturnsAString($randomValue)
109+
{
110+
/** @var \Magento\Customer\Model\Customer|\PHPUnit_Framework_MockObject_MockObject $customer */
111+
$customer = $this->getMockBuilder(\Magento\Customer\Model\Customer::class)
112+
->disableOriginalConstructor()
113+
->setMethods(['getData'])
114+
->getMock();
115+
116+
$customer->expects($this->exactly(2))->method('getData')->willReturn($randomValue);
117+
118+
$this->assertInternalType(
119+
'string',
120+
$customer->getPassword(),
121+
'Customer password should always return a string'
122+
);
123+
124+
$this->assertInternalType(
125+
'string',
126+
$customer->getPasswordConfirm(),
127+
'Customer password-confirm should always return a string'
128+
);
129+
}
82130
}

0 commit comments

Comments
 (0)