Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

11793: Magento2.1.5 admin shipping report shows wrong currency code #11962

Merged
merged 3 commits into from
Nov 9, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,92 @@
<?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]
);

Copy link
Member

@osrecio osrecio Nov 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete blank line before closing brace: Line 44.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@osrecio, done.

}

/**
* @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]],
];
}
}