Skip to content

Commit b045791

Browse files
committed
MC-33392: Customer configuration: Password options
1 parent 6b3b90b commit b045791

15 files changed

+824
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Customer\Block\Account;
9+
10+
use Magento\Framework\ObjectManagerInterface;
11+
use Magento\Framework\View\LayoutInterface;
12+
use Magento\TestFramework\Helper\Bootstrap;
13+
use PHPUnit\Framework\TestCase;
14+
15+
/**
16+
* Tests for authentication popup block.
17+
*
18+
* @see \Magento\Customer\Block\Account\AuthenticationPopup
19+
* @magentoAppArea frontend
20+
*/
21+
class AuthenticationPopupTest extends TestCase
22+
{
23+
/** @var ObjectManagerInterface */
24+
private $objectManager;
25+
26+
/** @var AuthenticationPopup */
27+
private $block;
28+
29+
/**
30+
* @inheritdoc
31+
*/
32+
protected function setUp(): void
33+
{
34+
parent::setUp();
35+
36+
$this->objectManager = Bootstrap::getObjectManager();
37+
$this->block = $this->objectManager->get(LayoutInterface::class)->createBlock(AuthenticationPopup::class);
38+
}
39+
40+
/**
41+
* @magentoConfigFixture current_store customer/password/autocomplete_on_storefront 1
42+
*
43+
* @return void
44+
*/
45+
public function testAutocompletePasswordEnabled(): void
46+
{
47+
$this->assertEquals('on', $this->block->getConfig()['autocomplete']);
48+
}
49+
50+
/**
51+
* @magentoConfigFixture current_store customer/password/autocomplete_on_storefront 0
52+
*
53+
* @return void
54+
*/
55+
public function testAutocompletePasswordDisabled(): void
56+
{
57+
$this->assertEquals('off', $this->block->getConfig()['autocomplete']);
58+
}
59+
}

dev/tests/integration/testsuite/Magento/Customer/Block/Account/ResetPasswordTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,24 @@ public function testResetPasswordForm(): void
8383
'Set password button was not found on the page'
8484
);
8585
}
86+
87+
/**
88+
* @magentoConfigFixture current_store customer/password/autocomplete_on_storefront 1
89+
*
90+
* @return void
91+
*/
92+
public function testAutocompletePasswordEnabled(): void
93+
{
94+
$this->assertFalse($this->block->isAutocompleteDisabled());
95+
}
96+
97+
/**
98+
* @magentoConfigFixture current_store customer/password/autocomplete_on_storefront 0
99+
*
100+
* @return void
101+
*/
102+
public function testAutocompletePasswordDisabled(): void
103+
{
104+
$this->assertTrue($this->block->isAutocompleteDisabled());
105+
}
86106
}

dev/tests/integration/testsuite/Magento/Customer/Block/Form/LoginTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,24 @@ public function testLoginForm(): void
8989
'Forgot password link does not exist on the page'
9090
);
9191
}
92+
93+
/**
94+
* @magentoConfigFixture current_store customer/password/autocomplete_on_storefront 1
95+
*
96+
* @return void
97+
*/
98+
public function testAutocompletePasswordEnabled(): void
99+
{
100+
$this->assertFalse($this->block->isAutocompleteDisabled());
101+
}
102+
103+
/**
104+
* @magentoConfigFixture current_store customer/password/autocomplete_on_storefront 0
105+
*
106+
* @return void
107+
*/
108+
public function testAutocompletePasswordDisabled(): void
109+
{
110+
$this->assertTrue($this->block->isAutocompleteDisabled());
111+
}
92112
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Customer\Model\AccountManagement;
9+
10+
use Magento\Customer\Api\AccountManagementInterface;
11+
use Magento\Customer\Model\CustomerRegistry;
12+
use Magento\Framework\Exception\State\UserLockedException;
13+
use Magento\Framework\ObjectManagerInterface;
14+
use Magento\TestFramework\Helper\Bootstrap;
15+
use PHPUnit\Framework\TestCase;
16+
17+
/**
18+
* Tests for customer authenticate via customer account management service.
19+
*
20+
* @magentoDbIsolation enabled
21+
*/
22+
class AuthenticateTest extends TestCase
23+
{
24+
/** @var ObjectManagerInterface */
25+
private $objectManager;
26+
27+
/** @var AccountManagementInterface */
28+
private $accountManagement;
29+
30+
/** @var CustomerRegistry */
31+
private $customerRegistry;
32+
33+
/**
34+
* @inheritdoc
35+
*/
36+
protected function setUp(): void
37+
{
38+
parent::setUp();
39+
40+
$this->objectManager = Bootstrap::getObjectManager();
41+
$this->accountManagement = $this->objectManager->get(AccountManagementInterface::class);
42+
$this->customerRegistry = $this->objectManager->get(CustomerRegistry::class);
43+
}
44+
45+
/**
46+
* @magentoDataFixture Magento/Customer/_files/locked_customer.php
47+
*
48+
* @return void
49+
*/
50+
public function testAuthenticateByLockedCustomer(): void
51+
{
52+
$this->expectExceptionObject(new UserLockedException(__('The account is locked.')));
53+
$this->accountManagement->authenticate('customer@example.com', 'password');
54+
}
55+
56+
/**
57+
* @magentoAppArea frontend
58+
* @magentoDataFixture Magento/Customer/_files/expired_lock_for_customer.php
59+
*
60+
* @return void
61+
*/
62+
public function testAuthenticateByCustomerExpiredLock(): void
63+
{
64+
$email = 'customer@example.com';
65+
$customer = $this->accountManagement->authenticate($email, 'password');
66+
$customerSecure = $this->customerRegistry->retrieveSecureData($customer->getId());
67+
$this->assertEquals(0, $customerSecure->getFailuresNum());
68+
$this->assertNull($customerSecure->getFirstFailure());
69+
$this->assertNull($customerSecure->getLockExpires());
70+
}
71+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Customer\Model;
9+
10+
use Magento\Framework\Exception\InvalidEmailOrPasswordException;
11+
use Magento\Framework\ObjectManagerInterface;
12+
use Magento\TestFramework\Helper\Bootstrap;
13+
use PHPUnit\Framework\TestCase;
14+
15+
/**
16+
* Tests for customer authentication model.
17+
*
18+
* @see \Magento\Customer\Model\Authentication
19+
* @magentoDbIsolation enabled
20+
*/
21+
class AuthenticationTest extends TestCase
22+
{
23+
/** @var ObjectManagerInterface */
24+
private $objectManager;
25+
26+
/** @var AuthenticationInterface */
27+
private $authentication;
28+
29+
/**
30+
* @inheritdoc
31+
*/
32+
protected function setUp(): void
33+
{
34+
parent::setUp();
35+
36+
$this->objectManager = Bootstrap::getObjectManager();
37+
$this->authentication = $this->objectManager->get(AuthenticationInterface::class);
38+
}
39+
40+
/**
41+
* @magentoDataFixture Magento/Customer/_files/expired_lock_for_customer.php
42+
*
43+
* @return void
44+
*/
45+
public function testCustomerAuthenticate(): void
46+
{
47+
$this->assertTrue($this->authentication->authenticate(1, 'password'));
48+
}
49+
50+
/**
51+
* @magentoDataFixture Magento/Customer/_files/expired_lock_for_customer.php
52+
*
53+
* @return void
54+
*/
55+
public function testCustomerAuthenticateWithWrongPassword(): void
56+
{
57+
$this->expectExceptionObject(new InvalidEmailOrPasswordException(__('Invalid login or password.')));
58+
$this->authentication->authenticate(1, 'password1');
59+
}
60+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Customer\Model\Checkout;
9+
10+
use Magento\Framework\ObjectManagerInterface;
11+
use Magento\TestFramework\Helper\Bootstrap;
12+
use PHPUnit\Framework\TestCase;
13+
14+
/**
15+
* Test for customer checkout config provider.
16+
*
17+
* @see \Magento\Customer\Model\Checkout\ConfigProvider
18+
*/
19+
class ConfigProviderTest extends TestCase
20+
{
21+
/** @var ObjectManagerInterface */
22+
private $objectManager;
23+
24+
/** @var ConfigProvider */
25+
private $configProvider;
26+
27+
/**
28+
* @inheritdoc
29+
*/
30+
protected function setUp(): void
31+
{
32+
parent::setUp();
33+
34+
$this->objectManager = Bootstrap::getObjectManager();
35+
$this->configProvider = $this->objectManager->get(ConfigProvider::class);
36+
}
37+
38+
/**
39+
* @magentoConfigFixture current_store customer/password/autocomplete_on_storefront 1
40+
*
41+
* @return void
42+
*/
43+
public function testAutocompletePasswordEnabled(): void
44+
{
45+
$this->assertEquals('on', $this->configProvider->getConfig()['autocomplete']);
46+
}
47+
48+
/**
49+
* @magentoConfigFixture current_store customer/password/autocomplete_on_storefront 0
50+
*
51+
* @return void
52+
*/
53+
public function testAutocompletePasswordDisabled(): void
54+
{
55+
$this->assertEquals('off', $this->configProvider->getConfig()['autocomplete']);
56+
}
57+
}

0 commit comments

Comments
 (0)