Skip to content

Commit 5607277

Browse files
Merge branch 'develop' into 2.4-bugfixes-013122
2 parents d3d1f13 + f617d34 commit 5607277

File tree

7 files changed

+219
-2
lines changed

7 files changed

+219
-2
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\CreateAccountButton;
13+
14+
/**
15+
* Disable button Create Account while captcha is loading
16+
*/
17+
class DisableCreateAccountButton
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 button Create Account while captcha is loading
35+
*
36+
* @param CreateAccountButton $subject
37+
* @return bool
38+
* @throws InputException
39+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
40+
*/
41+
public function afterDisabled(CreateAccountButton $subject): bool
42+
{
43+
$key = 'customer_create';
44+
return $this->isCaptchaEnabled->isCaptchaEnabledFor($key);
45+
}
46+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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\ReCaptchaUi\Model\UiConfigResolverInterface;
13+
use Magento\Customer\ViewModel\LoginButton;
14+
15+
/**
16+
* Disable Login button while captcha is loading
17+
*/
18+
class DisableLoginButton
19+
{
20+
/**
21+
* @var IsCaptchaEnabledInterface
22+
*/
23+
private $isCaptchaEnabled;
24+
25+
/**
26+
* @param IsCaptchaEnabledInterface $isCaptchaEnabled
27+
*/
28+
public function __construct(
29+
IsCaptchaEnabledInterface $isCaptchaEnabled
30+
) {
31+
$this->isCaptchaEnabled = $isCaptchaEnabled;
32+
}
33+
34+
/**
35+
* Temporally disable Login button while captcha is loading
36+
*
37+
* @param LoginButton $subject
38+
* @return bool
39+
* @throws InputException
40+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
41+
*/
42+
public function afterDisabled(LoginButton $subject): bool
43+
{
44+
$key = 'customer_login';
45+
return $this->isCaptchaEnabled->isCaptchaEnabledFor($key);
46+
}
47+
}
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\CreateAccountButton;
11+
use Magento\ReCaptchaCustomer\Plugin\Customer\DisableCreateAccountButton;
12+
use Magento\ReCaptchaUi\Model\IsCaptchaEnabledInterface;
13+
use PHPUnit\Framework\MockObject\MockObject;
14+
use PHPUnit\Framework\TestCase;
15+
16+
/**
17+
* Test disable Login button while captcha is loading
18+
*/
19+
class DisableCreateAccountButtonTest extends TestCase
20+
{
21+
/**
22+
* @var IsCaptchaEnabledInterface|MockObject
23+
*/
24+
protected $isCaptchaEnabled;
25+
26+
/**
27+
* @var CreateAccountButton|MockObject
28+
*/
29+
protected $subject;
30+
31+
/**
32+
* @var DisableCreateAccountButton
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(CreateAccountButton::class);
42+
43+
$this->plugin = new DisableCreateAccountButton(
44+
$this->isCaptchaEnabled
45+
);
46+
}
47+
48+
public function testAfterEnabled()
49+
{
50+
$key = 'customer_create';
51+
$this->isCaptchaEnabled->expects($this->once())
52+
->method('isCaptchaEnabledFor')->with($key)->willReturn(true);
53+
$this->assertEquals(true, $this->plugin->afterDisabled($this->subject));
54+
}
55+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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\LoginButton;
11+
use Magento\ReCaptchaCustomer\Plugin\Customer\DisableLoginButton;
12+
use Magento\ReCaptchaUi\Model\IsCaptchaEnabledInterface;
13+
use PHPUnit\Framework\MockObject\MockObject;
14+
use PHPUnit\Framework\TestCase;
15+
16+
/**
17+
* Test disable Login button while captcha is loading
18+
*/
19+
class DisableLoginButtonTest extends TestCase
20+
{
21+
/**
22+
* IsCaptcha Enabled mock
23+
*
24+
* @var IsCaptchaEnabledInterface|MockObject
25+
*/
26+
protected $isCaptchaEnabled;
27+
28+
/**
29+
* Subject LoginButton
30+
*
31+
* @var LoginButton|MockObject
32+
*/
33+
protected $subject;
34+
35+
/**
36+
* Tested plugin
37+
*
38+
* @var DisableLoginButtonTest
39+
*/
40+
protected $plugin;
41+
42+
protected function setUp(): void
43+
{
44+
$this->isCaptchaEnabled = $this->getMockForAbstractClass(
45+
IsCaptchaEnabledInterface::class
46+
);
47+
$this->subject = $this->createMock(LoginButton::class);
48+
49+
$this->plugin = new DisableLoginButton(
50+
$this->isCaptchaEnabled
51+
);
52+
}
53+
54+
public function testAfterEnabled()
55+
{
56+
$key = 'customer_login';
57+
$this->isCaptchaEnabled->expects($this->once())
58+
->method('isCaptchaEnabledFor')->with($key)->willReturn(true);
59+
$this->assertEquals(true, $this->plugin->afterDisabled($this->subject));
60+
}
61+
}

ReCaptchaCustomer/etc/frontend/di.xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,12 @@
2020
<plugin sortOrder="1" name="inject_recaptcha_in_authentication_popup"
2121
type="Magento\ReCaptchaCustomer\Plugin\Block\Account\InjectRecaptchaInAuthenticationPopup"/>
2222
</type>
23-
23+
<type name="Magento\Customer\ViewModel\LoginButton">
24+
<plugin sortOrder="1" name="recaptcha_disable_login_button"
25+
type="Magento\ReCaptchaCustomer\Plugin\Customer\DisableLoginButton"/>
26+
</type>
27+
<type name="Magento\Customer\ViewModel\CreateAccountButton">
28+
<plugin sortOrder="1" name="recaptcha_disable_create_account_button"
29+
type="Magento\ReCaptchaCustomer\Plugin\Customer\DisableCreateAccountButton"/>
30+
</type>
2431
</config>

ReCaptchaFrontendUi/view/frontend/web/js/reCaptcha.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ define(
174174
} else {
175175
this.tokenField = null;
176176
}
177+
if ($('#send2').length > 0) {$('#send2').prop('disabled', false);}
177178
},
178179

179180
/**

ReCaptchaFrontendUi/view/frontend/web/template/reCaptcha.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
class="required-captcha checkbox"
2121
name="recaptcha-validate-"
2222
data-validate="{required:true}"
23-
/>
23+
tabindex="-1">
2424
</div>
2525
</div>
2626
<!-- /ko -->

0 commit comments

Comments
 (0)