Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 1717df4

Browse files
committed
11793: Magento2.1.5 admin shipping report shows wrong currency code
1 parent 148da00 commit 1717df4

File tree

2 files changed

+96
-5
lines changed

2 files changed

+96
-5
lines changed

app/code/Magento/Reports/Block/Adminhtml/Grid/AbstractGrid.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -363,12 +363,11 @@ public function setStoreIds($storeIds)
363363
public function getCurrentCurrencyCode()
364364
{
365365
if ($this->_currentCurrencyCode === null) {
366-
$this->_currentCurrencyCode = count(
367-
$this->_storeIds
368-
) > 0 ? $this->_storeManager->getStore(
369-
array_shift($this->_storeIds)
370-
)->getBaseCurrencyCode() : $this->_storeManager->getStore()->getBaseCurrencyCode();
366+
$this->_currentCurrencyCode = count($this->_storeIds) > 0
367+
? $this->_storeManager->getStore(array_shift($this->_storeIds))->getCurrentCurrencyCode()
368+
: $this->_storeManager->getStore()->getBaseCurrencyCode();
371369
}
370+
372371
return $this->_currentCurrencyCode;
373372
}
374373

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Reports\Test\Unit\Block\Adminhtml\Grid;
8+
9+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
10+
11+
/**
12+
* Test for class \Magento\Reports\Block\Adminhtml\Grid\AbstractGrid.
13+
*/
14+
class AbstractGridTest extends \PHPUnit\Framework\TestCase
15+
{
16+
/**
17+
* @var \Magento\Reports\Block\Adminhtml\Grid\AbstractGrid|\PHPUnit_Framework_MockObject_MockObject
18+
*/
19+
private $model;
20+
21+
/**
22+
* @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
23+
*/
24+
private $storeManagerMock;
25+
26+
protected function setUp()
27+
{
28+
$objectManager = new ObjectManager($this);
29+
30+
$this->storeManagerMock = $this->getMockForAbstractClass(
31+
\Magento\Store\Model\StoreManagerInterface::class,
32+
[],
33+
'',
34+
true,
35+
true,
36+
true,
37+
['getStore']
38+
);
39+
40+
$this->model = $objectManager->getObject(
41+
\Magento\Reports\Block\Adminhtml\Grid\AbstractGrid::class,
42+
['_storeManager' => $this->storeManagerMock]
43+
);
44+
45+
}
46+
47+
/**
48+
* @param $storeIds
49+
*
50+
* @dataProvider getCurrentCurrencyCodeDataProvider
51+
*/
52+
public function testGetCurrentCurrencyCode($storeIds)
53+
{
54+
$storeMock = $this->getMockForAbstractClass(
55+
\Magento\Store\Api\Data\StoreInterface::class,
56+
[],
57+
'',
58+
true,
59+
true,
60+
true,
61+
['getBaseCurrencyCode', 'getCurrentCurrencyCode']
62+
);
63+
64+
$this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($storeMock);
65+
66+
$this->model->setStoreIds($storeIds);
67+
68+
if ($storeIds) {
69+
$storeMock->expects($this->once())->method('getCurrentCurrencyCode')->willReturn('EUR');
70+
$expectedCurrencyCode = 'EUR';
71+
} else {
72+
$storeMock->expects($this->once())->method('getBaseCurrencyCode')->willReturn('USD');
73+
$expectedCurrencyCode = 'USD';
74+
}
75+
76+
$currencyCode = $this->model->getCurrentCurrencyCode();
77+
$this->assertEquals($expectedCurrencyCode, $currencyCode);
78+
}
79+
80+
/**
81+
* DataProvider for testGetCurrentCurrencyCode.
82+
*
83+
* @return array
84+
*/
85+
public function getCurrentCurrencyCodeDataProvider()
86+
{
87+
return [
88+
[[]],
89+
[[2]],
90+
];
91+
}
92+
}

0 commit comments

Comments
 (0)