Skip to content

Commit

Permalink
⏫ Forwardport of #11962 to 2.3-develop branch
Browse files Browse the repository at this point in the history
Applied pull request patch https://github.com/magento/magento2/pull/11962.patch (created by @RomaKis) based on commit(s):
  1. 1717df4
  2. c438c17
  3. 42d9b52

Fixed GitHub Issues in 2.3-develop branch:
  - #11793: Magento2.1.5 admin shipping report shows wrong currency code (reported by @pushparaj100)
  • Loading branch information
magento-engcom-team committed Jan 23, 2018
1 parent 8e77e2f commit d96327d
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -363,12 +363,11 @@ public function setStoreIds($storeIds)
public function getCurrentCurrencyCode()
{
if ($this->_currentCurrencyCode === null) {
$this->_currentCurrencyCode = count(
$this->_storeIds
) > 0 ? $this->_storeManager->getStore(
array_shift($this->_storeIds)
)->getBaseCurrencyCode() : $this->_storeManager->getStore()->getBaseCurrencyCode();
$this->_currentCurrencyCode = count($this->_storeIds) > 0
? $this->_storeManager->getStore(array_shift($this->_storeIds))->getCurrentCurrencyCode()
: $this->_storeManager->getStore()->getBaseCurrencyCode();
}

return $this->_currentCurrencyCode;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Reports\Test\Unit\Block\Adminhtml\Grid;

use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;

/**
* Test for class \Magento\Reports\Block\Adminhtml\Grid\AbstractGrid.
*/
class AbstractGridTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \Magento\Reports\Block\Adminhtml\Grid\AbstractGrid|\PHPUnit_Framework_MockObject_MockObject
*/
private $model;

/**
* @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $storeManagerMock;

protected function setUp()
{
$objectManager = new ObjectManager($this);

$this->storeManagerMock = $this->getMockForAbstractClass(
\Magento\Store\Model\StoreManagerInterface::class,
[],
'',
true,
true,
true,
['getStore']
);

$this->model = $objectManager->getObject(
\Magento\Reports\Block\Adminhtml\Grid\AbstractGrid::class,
['_storeManager' => $this->storeManagerMock]
);
}

/**
* @param $storeIds
*
* @dataProvider getCurrentCurrencyCodeDataProvider
*/
public function testGetCurrentCurrencyCode($storeIds)
{
$storeMock = $this->getMockForAbstractClass(
\Magento\Store\Api\Data\StoreInterface::class,
[],
'',
true,
true,
true,
['getBaseCurrencyCode', 'getCurrentCurrencyCode']
);

$this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($storeMock);

$this->model->setStoreIds($storeIds);

if ($storeIds) {
$storeMock->expects($this->once())->method('getCurrentCurrencyCode')->willReturn('EUR');
$expectedCurrencyCode = 'EUR';
} else {
$storeMock->expects($this->once())->method('getBaseCurrencyCode')->willReturn('USD');
$expectedCurrencyCode = 'USD';
}

$currencyCode = $this->model->getCurrentCurrencyCode();
$this->assertEquals($expectedCurrencyCode, $currencyCode);
}

/**
* DataProvider for testGetCurrentCurrencyCode.
*
* @return array
*/
public function getCurrentCurrencyCodeDataProvider()
{
return [
[[]],
[[2]],
];
}
}

0 comments on commit d96327d

Please sign in to comment.