Skip to content

Commit 3824b6f

Browse files
committed
Merge remote-tracking branch 'origin/MC-33110' into 2.4-develop-pr22
2 parents 639915b + 663c21b commit 3824b6f

File tree

3 files changed

+69
-27
lines changed

3 files changed

+69
-27
lines changed

app/code/Magento/Paypal/Model/SmartButtonConfig.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use Magento\Store\Model\ScopeInterface;
1414

1515
/**
16-
* Smart button config
16+
* Smart button configuration.
1717
*/
1818
class SmartButtonConfig
1919
{
@@ -96,7 +96,14 @@ public function getConfig(string $page): array
9696
private function getDisallowedFunding(): array
9797
{
9898
$disallowedFunding = $this->config->getValue('disable_funding_options');
99-
return $disallowedFunding ? explode(',', $disallowedFunding) : [];
99+
$result = $disallowedFunding ? explode(',', $disallowedFunding) : [];
100+
101+
// PayPal Guest Checkout Credit Card Icons only available when Guest Checkout option is enabled
102+
if ($this->isPaypalGuestCheckoutAllowed() === false && !in_array('CARD', $result)) {
103+
array_push($result, 'CARD');
104+
}
105+
106+
return $result;
100107
}
101108

102109
/**
@@ -168,4 +175,14 @@ private function updateStyles(array $styles, string $page): array
168175

169176
return $styles;
170177
}
178+
179+
/**
180+
* Returns if is allowed PayPal Guest Checkout.
181+
*
182+
* @return bool
183+
*/
184+
private function isPaypalGuestCheckoutAllowed(): bool
185+
{
186+
return $this->config->getValue('solution_type') === Config::EC_SOLUTION_TYPE_SOLE;
187+
}
171188
}

app/code/Magento/Paypal/Test/Unit/Model/SmartButtonConfigTest.php

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,40 +12,45 @@
1212
use Magento\Paypal\Model\SmartButtonConfig;
1313
use Magento\Framework\Locale\ResolverInterface;
1414
use Magento\Paypal\Model\ConfigFactory;
15+
use PHPUnit\Framework\MockObject\MockObject;
16+
use PHPUnit\Framework\TestCase;
1517

1618
/**
17-
* Class SmartButtonConfigTest
19+
* Test for smart button config
1820
*/
19-
class SmartButtonConfigTest extends \PHPUnit\Framework\TestCase
21+
class SmartButtonConfigTest extends TestCase
2022
{
2123
/**
2224
* @var \Magento\Paypal\Model\SmartButtonConfig
2325
*/
2426
private $model;
2527

2628
/**
27-
* @var \PHPUnit_Framework_MockObject_MockObject
29+
* @var MockObject
2830
*/
2931
private $localeResolverMock;
3032

3133
/**
32-
* @var \PHPUnit_Framework_MockObject_MockObject
34+
* @var MockObject
3335
*/
3436
private $configMock;
3537

38+
/**
39+
* @inheritdoc
40+
*/
3641
protected function setUp()
3742
{
3843
$this->localeResolverMock = $this->getMockForAbstractClass(ResolverInterface::class);
3944
$this->configMock = $this->getMockBuilder(Config::class)
4045
->disableOriginalConstructor()
4146
->getMock();
4247

43-
/** @var ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject $scopeConfigMock */
48+
/** @var ScopeConfigInterface|MockObject $scopeConfigMock */
4449
$scopeConfigMock = $this->getMockForAbstractClass(ScopeConfigInterface::class);
4550
$scopeConfigMock->method('isSetFlag')
4651
->willReturn(true);
4752

48-
/** @var \PHPUnit_Framework_MockObject_MockObject $configFactoryMock */
53+
/** @var MockObject $configFactoryMock */
4954
$configFactoryMock = $this->getMockBuilder(ConfigFactory::class)
5055
->disableOriginalConstructor()
5156
->setMethods(['create'])
@@ -65,6 +70,7 @@ protected function setUp()
6570
*
6671
* @param string $page
6772
* @param string $locale
73+
* @param bool $isCustomize
6874
* @param string $disallowedFundings
6975
* @param string $layout
7076
* @param string $size
@@ -73,6 +79,7 @@ protected function setUp()
7379
* @param string $color
7480
* @param string $installmentPeriodLabel
7581
* @param string $installmentPeriodLocale
82+
* @param string $isPaypalGuestCheckoutEnabled
7683
* @param array $expected
7784
* @dataProvider getConfigDataProvider
7885
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
@@ -89,13 +96,19 @@ public function testGetConfig(
8996
string $color,
9097
string $installmentPeriodLabel,
9198
string $installmentPeriodLocale,
99+
string $isPaypalGuestCheckoutEnabled,
92100
array $expected = []
93101
) {
94-
$this->localeResolverMock->expects($this->any())->method('getLocale')->willReturn($locale);
102+
$this->localeResolverMock->method('getLocale')->willReturn($locale);
95103
$this->configMock->method('getValue')->will(
96104
$this->returnValueMap(
97105
[
98106
['merchant_id', null, 'merchant'],
107+
[
108+
'solution_type',
109+
null,
110+
$isPaypalGuestCheckoutEnabled ? Config::EC_SOLUTION_TYPE_SOLE : Config::EC_SOLUTION_TYPE_MARK
111+
],
99112
['sandbox_flag', null, true],
100113
['disable_funding_options', null, $disallowedFundings],
101114
["{$page}_page_button_customize", null, $isCustomize],
@@ -117,6 +130,8 @@ public function testGetConfig(
117130
}
118131

119132
/**
133+
* Get config data provider
134+
*
120135
* @return array
121136
*/
122137
public function getConfigDataProvider()
@@ -125,6 +140,8 @@ public function getConfigDataProvider()
125140
}
126141

127142
/**
143+
* Get default styles
144+
*
128145
* @return array
129146
*/
130147
private function getDefaultStyles()
@@ -133,6 +150,8 @@ private function getDefaultStyles()
133150
}
134151

135152
/**
153+
* Get allowed fundings
154+
*
136155
* @return array
137156
*/
138157
private function getAllowedFundings()

app/code/Magento/Paypal/Test/Unit/Model/_files/expected_config.php

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
'blue',
1919
'my_label',
2020
'mx',
21+
true,
2122
[
2223
'merchantId' => 'merchant',
2324
'environment' => 'sandbox',
@@ -48,6 +49,7 @@
4849
'blue',
4950
'my_label',
5051
'br',
52+
true,
5153
[
5254
'merchantId' => 'merchant',
5355
'environment' => 'sandbox',
@@ -78,6 +80,7 @@
7880
'blue',
7981
'my_label',
8082
'br',
83+
true,
8184
[
8285
'merchantId' => 'merchant',
8386
'environment' => 'sandbox',
@@ -95,62 +98,65 @@
9598
'isGuestCheckoutAllowed' => true
9699
]
97100
],
98-
'mini_cart' => [
101+
'product' => [
99102
'cart',
100103
'en',
101104
false,
102-
null,
105+
'CREDIT',
103106
'horizontal',
104107
'small',
105108
'pillow',
106109
'installment',
107110
'blue',
108111
'my_label',
109112
'br',
113+
true,
110114
[
111115
'merchantId' => 'merchant',
112116
'environment' => 'sandbox',
113117
'locale' => 'en',
114-
'allowedFunding' => ['CREDIT', 'ELV'],
115-
'disallowedFunding' => [],
118+
'allowedFunding' => ['ELV'],
119+
'disallowedFunding' => ['CREDIT'],
116120
'styles' => [
117121
'layout' => 'vertical',
118122
'size' => 'responsive',
119123
'color' => 'gold',
120124
'shape' => 'rect',
121-
'label' => 'paypal'
125+
'label' => 'paypal',
122126
],
123127
'isVisibleOnProductPage' => false,
124128
'isGuestCheckoutAllowed' => true
125129
]
126130
],
127-
'product' => [
131+
'checkout_with_paypal_guest_checkout_disabled' => [
128132
'cart',
129-
'en',
130-
false,
131-
'CREDIT',
133+
'en_BR',
134+
true,
135+
null,
132136
'horizontal',
133137
'small',
134138
'pillow',
135139
'installment',
136140
'blue',
137141
'my_label',
138142
'br',
143+
false,
139144
[
140145
'merchantId' => 'merchant',
141146
'environment' => 'sandbox',
142-
'locale' => 'en',
143-
'allowedFunding' => ['ELV'],
144-
'disallowedFunding' => ['CREDIT'],
147+
'locale' => 'en_BR',
148+
'allowedFunding' => ['CREDIT', 'ELV'],
149+
'disallowedFunding' => ['CARD'],
145150
'styles' => [
146-
'layout' => 'vertical',
147-
'size' => 'responsive',
148-
'color' => 'gold',
149-
'shape' => 'rect',
150-
'label' => 'paypal',
151+
'layout' => 'horizontal',
152+
'size' => 'small',
153+
'color' => 'blue',
154+
'shape' => 'pillow',
155+
'label' => 'installment',
156+
'installmentperiod' => 0
151157
],
152158
'isVisibleOnProductPage' => false,
153159
'isGuestCheckoutAllowed' => true
154160
]
155-
]
161+
],
156162
];

0 commit comments

Comments
 (0)