Skip to content

Commit

Permalink
Merge branch 'MC-19008' of https://github.com/magento-mpi/magento2ce
Browse files Browse the repository at this point in the history
…into PR-16-08-2019
  • Loading branch information
Spandana Chittimala committed Aug 16, 2019
2 parents feda92e + 77ca314 commit e6132df
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,6 @@ public function __construct(
parent::__construct($context, $data);
}

/**
* Render country field considering request parameter
*
* @param AbstractElement $element
* @return string
*/
public function render(AbstractElement $element)
{
if (!$this->isSelectedMerchantCountry('US')) {
$fundingOptions = $element->getValues();
$element->setValues($this->filterValuesForPaypalCredit($fundingOptions));
}
return parent::render($element);
}

/**
* Getting the name of a UI attribute
*
Expand All @@ -62,30 +47,4 @@ protected function getDataAttributeName(): string
{
return 'disable-funding-options';
}

/**
* Filters array for CREDIT
*
* @param array $options
* @return array
*/
private function filterValuesForPaypalCredit($options): array
{
return array_filter($options, function ($opt) {
return ($opt['value'] !== 'CREDIT');
});
}

/**
* Checks for chosen Merchant country from the config/url
*
* @param string $country
* @return bool
*/
private function isSelectedMerchantCountry(string $country): bool
{
$merchantCountry = $this->getRequest()->getParam(StructurePlugin::REQUEST_PARAM_COUNTRY)
?: $this->config->getMerchantCountry();
return $merchantCountry === $country;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,25 @@ public function testIsPaypalCreditAvailable(
) {
$this->request->expects($this->any())
->method('getParam')
->will($this->returnCallback(function ($param) use ($requestCountry) {
if ($param == StructurePlugin::REQUEST_PARAM_COUNTRY) {
return $requestCountry;
}
return $param;
}));
->will(
$this->returnCallback(
function ($param) use ($requestCountry) {
if ($param == StructurePlugin::REQUEST_PARAM_COUNTRY) {
return $requestCountry;
}
return $param;
}
)
);
$this->config->expects($this->any())
->method('getMerchantCountry')
->will($this->returnCallback(function () use ($merchantCountry) {
return $merchantCountry;
}));
->will(
$this->returnCallback(
function () use ($merchantCountry) {
return $merchantCountry;
}
)
);
$this->model->render($this->element);
$payPalCreditOption = [
'value' => 'CREDIT',
Expand All @@ -113,9 +121,9 @@ public function isPaypalCreditAvailableDataProvider(): array
[null, 'US', true],
['US', 'US', true],
['US', 'GB', true],
['GB', 'GB', false],
['GB', 'US', false],
['GB', null, false],
['GB', 'GB', true],
['GB', 'US', true],
['GB', null, true],
];
}

Expand Down

0 comments on commit e6132df

Please sign in to comment.