Skip to content

Commit d3b0003

Browse files
authored
Merge pull request #75 from magento-l3/PR_19_May_2022_Odubovyk
L3 bugfix delivery
2 parents cabc5ff + b46294a commit d3b0003

File tree

3 files changed

+105
-0
lines changed

3 files changed

+105
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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\ReCaptchaCustomer\Plugin\Customer;
9+
10+
use Magento\Framework\Exception\InputException;
11+
use Magento\ReCaptchaUi\Model\IsCaptchaEnabledInterface;
12+
use Magento\Customer\ViewModel\ForgotPasswordButton;
13+
14+
/**
15+
* Disable Forgot password button while captcha is loading
16+
*/
17+
class DisableForgotPasswordButton
18+
{
19+
/**
20+
* @var IsCaptchaEnabledInterface
21+
*/
22+
private $isCaptchaEnabled;
23+
24+
/**
25+
* @param IsCaptchaEnabledInterface $isCaptchaEnabled
26+
*/
27+
public function __construct(
28+
IsCaptchaEnabledInterface $isCaptchaEnabled
29+
) {
30+
$this->isCaptchaEnabled = $isCaptchaEnabled;
31+
}
32+
33+
/**
34+
* Temporally disable Forgot password button while captcha is loading
35+
*
36+
* @param ForgotPasswordButton $subject
37+
* @return bool
38+
* @throws InputException
39+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
40+
*/
41+
public function afterDisabled(ForgotPasswordButton $subject): bool
42+
{
43+
$key = 'customer_forgot_password';
44+
return $this->isCaptchaEnabled->isCaptchaEnabledFor($key);
45+
}
46+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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\ReCaptchaCustomer\Test\Unit\Plugin\Customer;
9+
10+
use Magento\Customer\ViewModel\ForgotPasswordButton;
11+
use Magento\ReCaptchaCustomer\Plugin\Customer\DisableForgotPasswordButton;
12+
use Magento\ReCaptchaUi\Model\IsCaptchaEnabledInterface;
13+
use PHPUnit\Framework\MockObject\MockObject;
14+
use PHPUnit\Framework\TestCase;
15+
16+
/**
17+
* Test disable Forgot password button while captcha is loading
18+
*/
19+
class DisableForgotPasswordButtonTest extends TestCase
20+
{
21+
/**
22+
* @var IsCaptchaEnabledInterface|MockObject
23+
*/
24+
protected $isCaptchaEnabled;
25+
26+
/**
27+
* @var ForgotPasswordButton|MockObject
28+
*/
29+
protected $subject;
30+
31+
/**
32+
* @var DisableForgotPasswordButton
33+
*/
34+
protected $plugin;
35+
36+
protected function setUp(): void
37+
{
38+
$this->isCaptchaEnabled = $this->getMockForAbstractClass(
39+
IsCaptchaEnabledInterface::class
40+
);
41+
$this->subject = $this->createMock(ForgotPasswordButton::class);
42+
43+
$this->plugin = new DisableForgotPasswordButton(
44+
$this->isCaptchaEnabled
45+
);
46+
}
47+
48+
public function testAfterEnabled()
49+
{
50+
$key = 'customer_forgot_password';
51+
$this->isCaptchaEnabled->expects($this->once())
52+
->method('isCaptchaEnabledFor')->with($key)->willReturn(true);
53+
$this->assertEquals(true, $this->plugin->afterDisabled($this->subject));
54+
}
55+
}

ReCaptchaCustomer/etc/frontend/di.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,8 @@
2828
<plugin sortOrder="1" name="recaptcha_disable_create_account_button"
2929
type="Magento\ReCaptchaCustomer\Plugin\Customer\DisableCreateAccountButton"/>
3030
</type>
31+
<type name="Magento\Customer\ViewModel\ForgotPasswordButton">
32+
<plugin sortOrder="1" name="recaptcha_disable_forgot_password_button"
33+
type="Magento\ReCaptchaCustomer\Plugin\Customer\DisableForgotPasswordButton"/>
34+
</type>
3135
</config>

0 commit comments

Comments
 (0)