Skip to content

Commit 3798cb1

Browse files
committed
ACP2E-1338: Google reCaptcha in Incorrect position
1 parent 584a492 commit 3798cb1

File tree

2 files changed

+376
-0
lines changed

2 files changed

+376
-0
lines changed
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
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\ReCaptchaCheckout\Test\Unit\Block\LayoutProcessor\Checkout;
9+
10+
use Magento\Framework\DataObject;
11+
use Magento\ReCaptchaCheckout\Block\LayoutProcessor\Checkout\Onepage;
12+
use Magento\ReCaptchaUi\Model\IsCaptchaEnabledInterface;
13+
use Magento\ReCaptchaUi\Model\UiConfigResolverInterface;
14+
use PHPUnit\Framework\MockObject\MockObject;
15+
use PHPUnit\Framework\TestCase;
16+
17+
class OnepageTest extends TestCase
18+
{
19+
/**
20+
* @var UiConfigResolverInterface|MockObject
21+
*/
22+
private $uiConfigResolver;
23+
24+
/**
25+
* @var IsCaptchaEnabledInterface|MockObject
26+
*/
27+
private $isCaptchEnabled;
28+
29+
/**
30+
* @var Onepage
31+
*/
32+
private $model;
33+
34+
/**
35+
* @var array
36+
*/
37+
private $jsLayout = [
38+
'components' => [
39+
'checkout' => [
40+
'children' => [
41+
'steps' => [
42+
'children' => [
43+
'shipping-step' => [
44+
'children' => [
45+
'shippingAddress' => [
46+
'children' => [
47+
'customer-email' => [
48+
'children' => [
49+
'recaptcha' => []
50+
]
51+
]
52+
]
53+
]
54+
]
55+
],
56+
'billing-step' => [
57+
'children' => [
58+
'payment' => [
59+
'children' => [
60+
'customer-email' => [
61+
'children' => [
62+
'recaptcha' => []
63+
]
64+
],
65+
'payments-list' => [
66+
'children' => [
67+
'before-place-order' => [
68+
'children' => [
69+
'place-order-recaptcha' => []
70+
]
71+
]
72+
]
73+
]
74+
]
75+
]
76+
]
77+
]
78+
]
79+
],
80+
'authentication' => [
81+
'children' => [
82+
'recaptcha' => []
83+
]
84+
]
85+
]
86+
]
87+
]
88+
];
89+
90+
/**
91+
* @inheritdoc
92+
*/
93+
protected function setUp(): void
94+
{
95+
parent::setUp();
96+
$this->uiConfigResolver = $this->getMockForAbstractClass(UiConfigResolverInterface::class);
97+
$this->isCaptchEnabled = $this->getMockForAbstractClass(IsCaptchaEnabledInterface::class);
98+
$this->model = new Onepage(
99+
$this->uiConfigResolver,
100+
$this->isCaptchEnabled
101+
);
102+
}
103+
104+
/**
105+
* @dataProvider processDataProvider
106+
*/
107+
public function testProcess(array $mocks, array $expected): void
108+
{
109+
$this->uiConfigResolver->method('get')
110+
->willReturnMap($mocks['uiConfigResolver']);
111+
$this->isCaptchEnabled->method('isCaptchaEnabledFor')
112+
->willReturnMap($mocks['isCaptchaEnabled']);
113+
$prefix = 'components/checkout/children/';
114+
$config = new DataObject($this->model->process($this->jsLayout));
115+
$actual = [];
116+
foreach (array_keys($expected) as $path) {
117+
$actual[$path] = $config->getDataByPath($prefix.$path);
118+
}
119+
$this->assertSame($expected, $actual);
120+
}
121+
122+
public function processDataProvider(): array
123+
{
124+
return [
125+
[
126+
[
127+
'isCaptchaEnabled' => [
128+
['customer_login', false],
129+
['place_order', false],
130+
],
131+
'uiConfigResolver' => [
132+
['customer_login', ['type' => 'invisible']],
133+
['place_order', ['type' => 'robot']],
134+
],
135+
],
136+
[
137+
'steps/children/shipping-step/children/shippingAddress/children/customer-email/children' => [],
138+
'steps/children/billing-step/children/payment/children/customer-email/children' => [],
139+
'authentication/children' => [],
140+
'steps/children/billing-step/children/payment/children/payments-list/children/before-place-order/' .
141+
'children' => [],
142+
]
143+
],
144+
[
145+
[
146+
'isCaptchaEnabled' => [
147+
['customer_login', true],
148+
['place_order', true],
149+
],
150+
'uiConfigResolver' => [
151+
['customer_login', ['type' => 'invisible']],
152+
['place_order', ['type' => 'robot']],
153+
],
154+
],
155+
[
156+
'steps/children/shipping-step/children/shippingAddress/children/' .
157+
'customer-email/children' => ['recaptcha' => ['settings' => ['type' => 'invisible']]],
158+
'steps/children/billing-step/children/payment/children/' .
159+
'customer-email/children' => ['recaptcha' => ['settings' => ['type' => 'invisible']]],
160+
'authentication/children' => ['recaptcha' => ['settings' => ['type' => 'invisible']]],
161+
'steps/children/billing-step/children/payment/children/payments-list/children/before-place-order/' .
162+
'children' => ['place-order-recaptcha' => ['settings' => ['type' => 'robot']]],
163+
]
164+
]
165+
];
166+
}
167+
}
Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
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\ReCaptchaPaypal\Test\Unit\Block\LayoutProcessor\Checkout;
9+
10+
use Magento\Framework\DataObject;
11+
use Magento\Paypal\Model\Config;
12+
use Magento\ReCaptchaPaypal\Block\LayoutProcessor\Checkout\Onepage;
13+
use Magento\ReCaptchaUi\Model\IsCaptchaEnabledInterface;
14+
use Magento\ReCaptchaUi\Model\UiConfigResolverInterface;
15+
use PHPUnit\Framework\MockObject\MockObject;
16+
use PHPUnit\Framework\TestCase;
17+
18+
class OnepageTest extends TestCase
19+
{
20+
/**
21+
* @var UiConfigResolverInterface|MockObject
22+
*/
23+
private $uiConfigResolver;
24+
25+
/**
26+
* @var IsCaptchaEnabledInterface|MockObject
27+
*/
28+
private $isCaptchEnabled;
29+
30+
/**
31+
* @var Onepage
32+
*/
33+
private $model;
34+
35+
/**
36+
* @var array
37+
*/
38+
private $jsLayout = [
39+
'components' => [
40+
'checkout' => [
41+
'children' => [
42+
'steps' => [
43+
'children' => [
44+
'billing-step' => [
45+
'children' => [
46+
'payment' => [
47+
'children' => [
48+
'payments-list' => [
49+
'children' => [
50+
'before-place-order' => [
51+
'children' => [
52+
'place-order-recaptcha' => [
53+
'skipPayments' => []
54+
]
55+
]
56+
],
57+
'paypal-captcha' => [
58+
'children' => [
59+
'recaptcha' => []
60+
]
61+
]
62+
]
63+
]
64+
]
65+
]
66+
]
67+
]
68+
]
69+
]
70+
]
71+
]
72+
]
73+
];
74+
75+
/**
76+
* @inheritdoc
77+
*/
78+
protected function setUp(): void
79+
{
80+
parent::setUp();
81+
$this->uiConfigResolver = $this->getMockForAbstractClass(UiConfigResolverInterface::class);
82+
$this->isCaptchEnabled = $this->getMockForAbstractClass(IsCaptchaEnabledInterface::class);
83+
$this->model = new Onepage(
84+
$this->uiConfigResolver,
85+
$this->isCaptchEnabled
86+
);
87+
}
88+
89+
/**
90+
* @dataProvider processDataProvider
91+
*/
92+
public function testProcess(array $mocks, array $expected): void
93+
{
94+
$this->uiConfigResolver->method('get')
95+
->willReturnMap($mocks['uiConfigResolver']);
96+
$this->isCaptchEnabled->method('isCaptchaEnabledFor')
97+
->willReturnMap($mocks['isCaptchaEnabled']);
98+
$prefix = 'components/checkout/children/';
99+
$config = new DataObject($this->model->process($this->jsLayout));
100+
$actual = [];
101+
foreach (array_keys($expected) as $path) {
102+
$actual[$path] = $config->getDataByPath($prefix . $path);
103+
}
104+
$this->assertSame($expected, $actual);
105+
}
106+
107+
public function processDataProvider(): array
108+
{
109+
return [
110+
[
111+
[
112+
'isCaptchaEnabled' => [
113+
['paypal_payflowpro', false],
114+
['place_order', false],
115+
],
116+
'uiConfigResolver' => [
117+
['paypal_payflowpro', ['type' => 'invisible']],
118+
['place_order', ['type' => 'robot']],
119+
],
120+
],
121+
[
122+
'steps/children/billing-step/children/payment/children/payments-list/children/paypal-captcha/' .
123+
'children' => [],
124+
'steps/children/billing-step/children/payment/children/payments-list/children/before-place-order/' .
125+
'children' => [
126+
'place-order-recaptcha' => [
127+
'skipPayments' => []
128+
]
129+
],
130+
]
131+
],
132+
[
133+
[
134+
'isCaptchaEnabled' => [
135+
['paypal_payflowpro', false],
136+
['place_order', true],
137+
],
138+
'uiConfigResolver' => [
139+
['paypal_payflowpro', ['type' => 'invisible']],
140+
['place_order', ['type' => 'robot']],
141+
],
142+
],
143+
[
144+
'steps/children/billing-step/children/payment/children/payments-list/children/paypal-captcha/' .
145+
'children' => [],
146+
'steps/children/billing-step/children/payment/children/payments-list/children/before-place-order/' .
147+
'children' => [
148+
'place-order-recaptcha' => [
149+
'skipPayments' => [
150+
Config::METHOD_EXPRESS => true,
151+
Config::METHOD_WPP_PE_EXPRESS => true,
152+
Config::METHOD_WPP_PE_BML => true,
153+
]
154+
]
155+
],
156+
]
157+
],
158+
[
159+
[
160+
'isCaptchaEnabled' => [
161+
['paypal_payflowpro', true],
162+
['place_order', false],
163+
],
164+
'uiConfigResolver' => [
165+
['paypal_payflowpro', ['type' => 'invisible']],
166+
['place_order', ['type' => 'robot']],
167+
],
168+
],
169+
[
170+
'steps/children/billing-step/children/payment/children/payments-list/children/paypal-captcha/' .
171+
'children' => ['recaptcha' => ['settings' => ['type' => 'invisible']]],
172+
'steps/children/billing-step/children/payment/children/payments-list/children/before-place-order/' .
173+
'children' => [
174+
'place-order-recaptcha' => [
175+
'skipPayments' => []
176+
]
177+
],
178+
]
179+
],
180+
[
181+
[
182+
'isCaptchaEnabled' => [
183+
['paypal_payflowpro', true],
184+
['place_order', true],
185+
],
186+
'uiConfigResolver' => [
187+
['paypal_payflowpro', ['type' => 'invisible']],
188+
['place_order', ['type' => 'robot']],
189+
],
190+
],
191+
[
192+
'steps/children/billing-step/children/payment/children/payments-list/children/paypal-captcha/' .
193+
'children' => ['recaptcha' => ['settings' => ['type' => 'invisible']]],
194+
'steps/children/billing-step/children/payment/children/payments-list/children/before-place-order/' .
195+
'children' => [
196+
'place-order-recaptcha' => [
197+
'skipPayments' => [
198+
Config::METHOD_EXPRESS => true,
199+
Config::METHOD_WPP_PE_EXPRESS => true,
200+
Config::METHOD_WPP_PE_BML => true,
201+
Config::METHOD_PAYFLOWPRO => true
202+
]
203+
]
204+
],
205+
]
206+
]
207+
];
208+
}
209+
}

0 commit comments

Comments
 (0)