Skip to content

Commit 65af694

Browse files
committed
ACP2E-222: Magento forms can be submitted before the Google Recaptcha appears in the form
1 parent dc3d3be commit 65af694

File tree

3 files changed

+116
-3
lines changed

3 files changed

+116
-3
lines changed

ReCaptchaCustomer/Plugin/Customer/DisableLoginButton.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,11 @@ class DisableLoginButton
2323
private $isCaptchaEnabled;
2424

2525
/**
26-
* @param UiConfigResolverInterface $captchaUiConfigResolver
2726
* @param IsCaptchaEnabledInterface $isCaptchaEnabled
2827
*/
2928
public function __construct(
30-
UiConfigResolverInterface $captchaUiConfigResolver,
3129
IsCaptchaEnabledInterface $isCaptchaEnabled
3230
) {
33-
$this->captchaUiConfigResolver = $captchaUiConfigResolver;
3431
$this->isCaptchaEnabled = $isCaptchaEnabled;
3532
}
3633

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_login';
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+
}

0 commit comments

Comments
 (0)