-
Notifications
You must be signed in to change notification settings - Fork 222
Expand file tree
/
Copy pathAdyenGenericConfigProviderTest.php
More file actions
151 lines (130 loc) · 5.98 KB
/
AdyenGenericConfigProviderTest.php
File metadata and controls
151 lines (130 loc) · 5.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?php
/**
*
* Adyen Payment module (https://www.adyen.com/)
*
* Copyright (c) 2025 Adyen N.V. (https://www.adyen.com/)
* See LICENSE.txt for license details.
*
* Author: Adyen <magento@adyen.com>
*/
namespace Adyen\Payment\Model\Ui;
use Adyen\Payment\Helper\Config;
use Adyen\Payment\Helper\Data;
use Adyen\Payment\Test\Unit\AbstractAdyenTestCase;
use Magento\CheckoutAgreements\Model\AgreementsConfigProvider;
use Magento\Csp\Helper\CspNonceProvider;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\UrlInterface;
use Magento\Store\Api\Data\StoreInterface;
use Magento\Store\Model\StoreManagerInterface;
use PHPUnit\Framework\MockObject\MockObject;
class AdyenGenericConfigProviderTest extends AbstractAdyenTestCase
{
protected AdyenGenericConfigProvider $provider;
protected Data|MockObject $adyenHelperMock;
protected Config|MockObject $adyenConfigHelperMock;
protected StoreManagerInterface|MockObject $storeManagerMock;
protected RequestInterface|MockObject $requestMock;
protected UrlInterface|MockObject $urlMock;
protected AgreementsConfigProvider|MockObject $agreementsConfigProviderMock;
protected CspNonceProvider|MockObject $cspNonceProviderMock;
protected array $txVariants = [];
protected array $customMethodRenderers = [];
protected function setUp(): void
{
$this->adyenHelperMock = $this->createMock(Data::class);
$this->adyenConfigHelperMock = $this->createMock(Config::class);
$this->storeManagerMock = $this->createMock(StoreManagerInterface::class);
$this->requestMock = $this->createMock(RequestInterface::class);
$this->urlMock = $this->createMock(UrlInterface::class);
$this->agreementsConfigProviderMock = $this->createMock(AgreementsConfigProvider::class);
$this->cspNonceProviderMock = $this->createMock(CspNonceProvider::class);
$this->provider = new AdyenGenericConfigProvider(
$this->adyenHelperMock,
$this->adyenConfigHelperMock,
$this->storeManagerMock,
$this->requestMock,
$this->urlMock,
$this->agreementsConfigProviderMock,
$this->cspNonceProviderMock,
$this->txVariants,
$this->customMethodRenderers
);
}
public function testGetConfig(): void
{
$storeId = 1;
$clientKeyMock = 'CLIENT_KEY';
$merchantAccountMock = 'MERCHANT_ACCOUNT';
$isDemo = true;
$environment = 'test';
$nonceMock = 'NONCE';
$checkoutEnvironment = 'test';
$storeLocale = 'nl_NL';
$chargedCurrency = 'display';
$hasHolderName = true;
$holderNameRequired = true;
$storeMock = $this->createMock(StoreInterface::class);
$storeMock->expects($this->once())
->method('getId')
->willReturn($storeId);
$this->storeManagerMock->expects($this->once())
->method('getStore')
->willReturn($storeMock);
$this->adyenConfigHelperMock->expects($this->once())
->method('isDemoMode')
->willReturn($isDemo);
$this->adyenConfigHelperMock->expects($this->once())
->method('getClientKey')
->with($environment)
->willReturn($clientKeyMock);
$this->adyenConfigHelperMock->expects($this->once())
->method('getMerchantAccount')
->with($storeId)
->willReturn($merchantAccountMock);
$this->adyenHelperMock->expects($this->once())
->method('getCheckoutEnvironment')
->with($storeId)
->willReturn($checkoutEnvironment);
$this->adyenHelperMock->expects($this->once())
->method('getStoreLocale')
->with($storeId)
->willReturn($storeLocale);
$this->adyenConfigHelperMock->expects($this->once())
->method('getChargedCurrency')
->with($storeId)
->willReturn($chargedCurrency);
$this->adyenConfigHelperMock->expects($this->once())
->method('getHasHolderName')
->with($storeId)
->willReturn($hasHolderName);
$this->adyenConfigHelperMock->expects($this->once())
->method('getHolderNameRequired')
->with($storeId)
->willReturn($holderNameRequired);
$this->cspNonceProviderMock->expects($this->once())
->method('generateNonce')
->willReturn($nonceMock);
$config = $this->provider->getConfig();
$this->assertIsArray($config);
$this->assertArrayHasKey('payment', $config);
$this->assertArrayHasKey('adyen', $config['payment']);
$this->assertArrayHasKey('clientKey', $config['payment']['adyen']);
$this->assertArrayHasKey('merchantAccount', $config['payment']['adyen']);
$this->assertArrayHasKey('checkoutEnvironment', $config['payment']['adyen']);
$this->assertArrayHasKey('locale', $config['payment']['adyen']);
$this->assertArrayHasKey('chargedCurrency', $config['payment']['adyen']);
$this->assertArrayHasKey('hasHolderName', $config['payment']['adyen']);
$this->assertArrayHasKey('holderNameRequired', $config['payment']['adyen']);
$this->assertArrayHasKey('cspNonce', $config['payment']['adyen']);
$this->assertEquals($clientKeyMock, $config['payment']['adyen']['clientKey']);
$this->assertEquals($merchantAccountMock, $config['payment']['adyen']['merchantAccount']);
$this->assertEquals($checkoutEnvironment, $config['payment']['adyen']['checkoutEnvironment']);
$this->assertEquals($storeLocale, $config['payment']['adyen']['locale']);
$this->assertEquals($chargedCurrency, $config['payment']['adyen']['chargedCurrency']);
$this->assertEquals($hasHolderName, $config['payment']['adyen']['hasHolderName']);
$this->assertEquals($holderNameRequired, $config['payment']['adyen']['holderNameRequired']);
$this->assertEquals($nonceMock, $config['payment']['adyen']['cspNonce']);
}
}