Skip to content

Commit 729765c

Browse files
committed
Merge remote-tracking branch 'trigger/MC-41654' into MC-41701
2 parents 2ae8844 + d474bd4 commit 729765c

File tree

2 files changed

+67
-20
lines changed
  • app/code/Magento/Paypal/Block/PayLater
  • dev/tests/integration/testsuite/Magento/Paypal/Block/PayLater

2 files changed

+67
-20
lines changed

app/code/Magento/Paypal/Block/PayLater/Banner.php

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -68,30 +68,27 @@ protected function _toHtml(): string
6868
*/
6969
public function getJsLayout()
7070
{
71-
$jsLayout = [
71+
$jsComponent = $this->jsLayout['components']['payLater']['component'] ?? 'Magento_Paypal/js/view/paylater';
72+
73+
//Extend block component config with defaults
74+
$componentConfig = $this->jsLayout['components']['payLater']['config'] ?? [];
75+
$defaultConfig = ['sdkUrl' => $this->getPayPalSdkUrl()];
76+
$config = array_replace($defaultConfig, $componentConfig);
77+
78+
//Extend block component attributes with defaults
79+
$componentAttributes = $this->jsLayout['components']['payLater']['config']['attributes'] ?? [];
80+
$config['attributes'] = array_replace($this->getStyleAttributesConfig(), $componentAttributes);
81+
$config['attributes']['data-pp-placement'] = $this->placement;
82+
83+
$this->jsLayout = [
7284
'components' => [
7385
'payLater' => [
74-
'component' =>
75-
$this->jsLayout['components']['payLater']['component'] ?? 'Magento_Paypal/js/view/paylater',
76-
'config' => [
77-
'sdkUrl' => $this->getPayPalSdkUrl(),
78-
]
86+
'component' => $jsComponent,
87+
'config' => $config
7988
]
8089
]
8190
];
8291

83-
//Merge config
84-
$config = $this->jsLayout['components']['payLater']['config'] ?? [];
85-
$config = array_replace($jsLayout['components']['payLater']['config'], $config);
86-
87-
//Merge attributes
88-
$attributes = $this->jsLayout['components']['payLater']['config']['attributes'] ?? [];
89-
$config['attributes'] = array_replace($this->getStyleAttributesConfig(), $attributes);
90-
$config['attributes']['data-pp-placement'] = $this->placement;
91-
$jsLayout['components']['payLater']['config'] = $config;
92-
93-
$this->jsLayout = $jsLayout;
94-
9592
return parent::getJsLayout();
9693
}
9794

dev/tests/integration/testsuite/Magento/Paypal/Block/PayLater/BannerTest.php

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public function testGetJsLayout($systemConfig, $blockConfig, $expectedConfig)
3535

3636
$jsConfig = json_decode($block->getJsLayout(), true);
3737
$this->assertArrayHasKey('config', $jsConfig['components']['payLater']);
38+
$this->assertArrayHasKey('component', $jsConfig['components']['payLater']);
3839

3940
$optionsConfig = $jsConfig['components']['payLater']['config'];
4041
$this->assertEquals($expectedConfig, array_intersect_key($optionsConfig, $expectedConfig));
@@ -120,17 +121,66 @@ public function getJsLayoutDataProvider()
120121

121122
/**
122123
* @magentoAppArea frontend
124+
* @dataProvider sdkUrlDataProvider
123125
* @covers \Magento\Paypal\Block\PayLater\Banner::getJsLayout()
124126
* @covers \Magento\Paypal\Block\PayLater\Banner::getPayPalSdkUrl()
125127
*/
126-
public function testSdkUrl()
128+
public function testSdkUrl($blockConfig, $expectedUrl)
127129
{
128130
$layout = Bootstrap::getObjectManager()->get(LayoutInterface::class);
129-
$block = $layout->createBlock(Banner::class, '', []);
131+
$block = $layout->createBlock(Banner::class, '', ['data' => $blockConfig]);
130132

131133
$jsConfig = json_decode($block->getJsLayout(), true);
132134
$this->assertArrayHasKey('config', $jsConfig['components']['payLater']);
133135
$this->assertArrayHasKey('sdkUrl', $jsConfig['components']['payLater']['config']);
136+
$this->assertStringContainsString($expectedUrl, $jsConfig['components']['payLater']['config']['sdkUrl']);
137+
}
138+
139+
public function sdkUrlDataProvider()
140+
{
141+
return [
142+
[
143+
'blockConfig' => [
144+
'jsLayout' => [
145+
'components' => [
146+
'payLater' => [
147+
'config' => [
148+
]
149+
]
150+
]
151+
]
152+
],
153+
'expectedUrl' => 'paypal.com/sdk'
154+
],
155+
[
156+
'blockConfig' => [
157+
'jsLayout' => [
158+
'components' => [
159+
'payLater' => [
160+
'config' => [
161+
'attributes' => ['test1' => 'value1']
162+
]
163+
]
164+
]
165+
]
166+
],
167+
'expectedUrl' => 'paypal.com/sdk'
168+
],
169+
[
170+
'blockConfig' => [
171+
'jsLayout' => [
172+
'components' => [
173+
'payLater' => [
174+
'config' => [
175+
'sdkUrl' => 'http://mock.url'
176+
]
177+
]
178+
]
179+
]
180+
],
181+
'expectedUrl' => 'mock.url'
182+
]
183+
];
134184
}
135185

136186
/**

0 commit comments

Comments
 (0)