|
| 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