Skip to content

Commit 6759709

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-99111' into 2.2-develop-pr32
2 parents 062ff36 + 08daad8 commit 6759709

File tree

3 files changed

+106
-61
lines changed

3 files changed

+106
-61
lines changed

app/code/Magento/Payment/Helper/Data.php

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public function getStoreMethods($store = null, $quote = null)
147147
}
148148
$res[] = $methodInstance;
149149
}
150-
150+
// phpcs:ignore Generic.PHP.NoSilencedErrors
151151
@uasort(
152152
$res,
153153
function (MethodInterface $a, MethodInterface $b) {
@@ -267,14 +267,12 @@ public function getPaymentMethodList($sorted = true, $asLabelValue = false, $wit
267267
$groupRelations = [];
268268

269269
foreach ($this->getPaymentMethods() as $code => $data) {
270-
if (!empty($data['active'])) {
271-
$storedTitle = $this->getMethodInstance($code)->getConfigData('title', $store);
272-
if (!empty($storedTitle)) {
273-
$methods[$code] = $storedTitle;
274-
} elseif (!empty($data['title'])) {
275-
$methods[$code] = $data['title'];
276-
}
270+
$storeId = $store ? (int)$store->getId() : null;
271+
$storedTitle = $this->getMethodStoreTitle($code, $storeId);
272+
if (!empty($storedTitle)) {
273+
$methods[$code] = $storedTitle;
277274
}
275+
278276
if ($asLabelValue && $withGroups && isset($data['group'])) {
279277
$groupRelations[$code] = $data['group'];
280278
}
@@ -356,4 +354,21 @@ public function getZeroSubTotalPaymentAutomaticInvoice($store = null)
356354
$store
357355
);
358356
}
357+
358+
/**
359+
* Get config title of payment method
360+
*
361+
* @param string $code
362+
* @param int|null $storeId
363+
* @return string
364+
*/
365+
private function getMethodStoreTitle(string $code, $storeId = null): string
366+
{
367+
$configPath = sprintf('%s/%s/title', self::XML_PATH_PAYMENT_METHODS, $code);
368+
return (string) $this->scopeConfig->getValue(
369+
$configPath,
370+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
371+
$storeId
372+
);
373+
}
359374
}

app/code/Magento/Payment/Test/Unit/Helper/DataTest.php

Lines changed: 38 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
namespace Magento\Payment\Test\Unit\Helper;
88

9-
use \Magento\Payment\Helper\Data;
10-
119
use Magento\Framework\TestFramework\Unit\Matcher\MethodInvokedAtIndex;
10+
use Magento\Payment\Helper\Data;
11+
use Magento\Store\Model\ScopeInterface;
1212

1313
class DataTest extends \PHPUnit\Framework\TestCase
1414
{
@@ -37,6 +37,9 @@ class DataTest extends \PHPUnit\Framework\TestCase
3737
*/
3838
private $appEmulation;
3939

40+
/**
41+
* @inheritDoc
42+
*/
4043
protected function setUp()
4144
{
4245
$objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
@@ -57,6 +60,9 @@ protected function setUp()
5760
$this->helper = $objectManagerHelper->getObject($className, $arguments);
5861
}
5962

63+
/**
64+
* @return void
65+
*/
6066
public function testGetMethodInstance()
6167
{
6268
list($code, $class, $methodInstance) = ['method_code', 'method_class', 'method_instance'];
@@ -170,6 +176,9 @@ public function testSortMethods(array $methodA, array $methodB)
170176
);
171177
}
172178

179+
/**
180+
* @return void
181+
*/
173182
public function testGetMethodFormBlock()
174183
{
175184
list($blockType, $methodCode) = ['method_block_type', 'method_code'];
@@ -195,6 +204,9 @@ public function testGetMethodFormBlock()
195204
$this->assertSame($blockMock, $this->helper->getMethodFormBlock($methodMock, $layoutMock));
196205
}
197206

207+
/**
208+
* @return void`
209+
*/
198210
public function testGetInfoBlock()
199211
{
200212
$blockType = 'method_block_type';
@@ -220,6 +232,9 @@ public function testGetInfoBlock()
220232
$this->assertSame($blockMock, $this->helper->getInfoBlock($infoMock));
221233
}
222234

235+
/**
236+
* @return void
237+
*/
223238
public function testGetInfoBlockHtml()
224239
{
225240
list($storeId, $blockHtml, $secureMode, $blockType) = [1, 'HTML MARKUP', true, 'method_block_type'];
@@ -257,6 +272,23 @@ public function testGetInfoBlockHtml()
257272
$this->assertEquals($blockHtml, $this->helper->getInfoBlockHtml($infoMock, $storeId));
258273
}
259274

275+
/**
276+
* @return array
277+
*/
278+
public function getSortMethodsDataProvider()
279+
{
280+
return [
281+
[
282+
['code' => 'methodA', 'data' => ['sort_order' => 0]],
283+
['code' => 'methodB', 'data' => ['sort_order' => 1]]
284+
],
285+
[
286+
['code' => 'methodA', 'data' => ['sort_order' => 2]],
287+
['code' => 'methodB', 'data' => ['sort_order' => 1]],
288+
]
289+
];
290+
}
291+
260292
/**
261293
* @param bool $sorted
262294
* @param bool $asLabelValue
@@ -288,17 +320,10 @@ public function testGetPaymentMethodList(
288320
]
289321
);
290322

323+
$titlePath = sprintf('%s/%s/title', Data::XML_PATH_PAYMENT_METHODS, $paymentMethod['code']);
291324
$this->scopeConfig->method('getValue')
292-
->with(sprintf('%s/%s/model', Data::XML_PATH_PAYMENT_METHODS, $paymentMethod['code']))
293-
->willReturn(\Magento\Payment\Model\Method\AbstractMethod::class);
294-
295-
$methodInstanceMock = $this->getMockBuilder(\Magento\Payment\Model\MethodInterface::class)
296-
->getMockForAbstractClass();
297-
$methodInstanceMock->method('getConfigData')
298-
->with('title', null)
325+
->with($titlePath, ScopeInterface::SCOPE_STORE, null)
299326
->willReturn($configTitle);
300-
$this->methodFactory->method('create')
301-
->willReturn($methodInstanceMock);
302327

303328
$this->paymentConfig->method('getGroups')
304329
->willReturn($groups);
@@ -307,23 +332,6 @@ public function testGetPaymentMethodList(
307332
$this->assertEquals($expectedPaymentMethodList, $paymentMethodList);
308333
}
309334

310-
/**
311-
* @return array
312-
*/
313-
public function getSortMethodsDataProvider()
314-
{
315-
return [
316-
[
317-
['code' => 'methodA', 'data' => ['sort_order' => 0]],
318-
['code' => 'methodB', 'data' => ['sort_order' => 1]]
319-
],
320-
[
321-
['code' => 'methodA', 'data' => ['sort_order' => 2]],
322-
['code' => 'methodB', 'data' => ['sort_order' => 1]],
323-
]
324-
];
325-
}
326-
327335
/**
328336
* @return array
329337
*/
@@ -345,27 +353,12 @@ public function paymentMethodListDataProvider(): array
345353
],
346354
['payment_method' => 'Config Payment Title'],
347355
],
348-
'Payment method with default title' =>
349-
[
350-
true,
351-
false,
352-
false,
353-
null,
354-
[
355-
'code' => 'payment_method',
356-
'data' => [
357-
'active' => 1,
358-
'title' => 'Payment Title',
359-
],
360-
],
361-
['payment_method' => 'Payment Title'],
362-
],
363356
'Payment method as value => label' =>
364357
[
365358
true,
366359
true,
367360
false,
368-
null,
361+
'Payment Title',
369362
[
370363
'code' => 'payment_method',
371364
'data' => [
@@ -385,7 +378,7 @@ public function paymentMethodListDataProvider(): array
385378
true,
386379
true,
387380
true,
388-
null,
381+
'Payment Title',
389382
[
390383
'code' => 'payment_method',
391384
'data' => [

dev/tests/integration/testsuite/Magento/Payment/Helper/DataTest.php

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,59 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
namespace Magento\Payment\Helper;
7+
8+
use PHPUnit\Framework\TestCase;
9+
use Magento\OfflinePayments\Block\Info\Checkmo;
10+
use Magento\Payment\Model\Info;
11+
use Magento\TestFramework\Helper\Bootstrap;
612

713
/**
814
* Test class for \Magento\Payment\Helper\Data
915
*/
10-
namespace Magento\Payment\Helper;
11-
12-
class DataTest extends \PHPUnit\Framework\TestCase
16+
class DataTest extends TestCase
1317
{
18+
/**
19+
* @var Data
20+
*/
21+
private $helper;
22+
23+
/**
24+
* @inheritdoc
25+
*/
26+
protected function setUp()
27+
{
28+
parent::setUp();
29+
30+
$this->helper = Bootstrap::getObjectManager()->get(Data::class);
31+
}
32+
33+
/**
34+
* @return void
35+
*/
1436
public function testGetInfoBlock()
1537
{
16-
$helper = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Payment\Helper\Data::class);
17-
$paymentInfo = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
18-
\Magento\Payment\Model\Info::class
38+
$paymentInfo = Bootstrap::getObjectManager()->create(
39+
Info::class
1940
);
2041
$paymentInfo->setMethod('checkmo');
21-
$result = $helper->getInfoBlock($paymentInfo);
22-
$this->assertInstanceOf(\Magento\OfflinePayments\Block\Info\Checkmo::class, $result);
42+
$result = $this->helper->getInfoBlock($paymentInfo);
43+
$this->assertInstanceOf(Checkmo::class, $result);
44+
}
45+
46+
/**
47+
* Test to load Payment method title from the store config
48+
*
49+
* @magentoConfigFixture current_store payment/cashondelivery/title Cash On Delivery Title Of The Method
50+
*/
51+
public function testPaymentMethodLabelByStore()
52+
{
53+
$result = $this->helper->getPaymentMethodList(true, true);
54+
$this->assertArrayHasKey('cashondelivery', $result, 'Payment info does not exist');
55+
$this->assertEquals(
56+
'Cash On Delivery Title Of The Method',
57+
$result['cashondelivery']['label'],
58+
'Payment method title is not loaded from the store config'
59+
);
2360
}
2461
}

0 commit comments

Comments
 (0)