Skip to content

Commit

Permalink
MAGETWO-60246: [Backport] - [Github]Magento 2.1.1 Problem with change…
Browse files Browse the repository at this point in the history
… currency #6746 - for 2.1.x
  • Loading branch information
dhorytskyi committed Dec 6, 2017
1 parent 36fc9a7 commit e8161ad
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 27 deletions.
3 changes: 1 addition & 2 deletions app/code/Magento/CatalogSearch/Model/Layer/Filter/Price.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,7 @@ public function getCurrencyRate()
{
$rate = $this->_getData('currency_rate');
if ($rate === null) {
$rate = $this->_storeManager->getStore($this->getStoreId())
->getCurrentCurrencyRate();
$rate = $this->_storeManager->getStore()->getCurrentCurrencyRate();
}
if (!$rate) {
$rate = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,13 @@

/**
* Test for \Magento\CatalogSearch\Model\Layer\Filter\Price
* @SuppressWarnings(PHPMD.UnusedPrivateField)
*/
class PriceTest extends \PHPUnit_Framework_TestCase
{
private $itemDataBuilder;

/**
* @var \Magento\Catalog\Model\Price|MockObject
* @var \Magento\Catalog\Model\Layer\Filter\Item\DataBuilder|MockObject
*/
private $price;
private $itemDataBuilder;

/**
* @var \Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection|MockObject
Expand Down Expand Up @@ -48,69 +45,60 @@ class PriceTest extends \PHPUnit_Framework_TestCase
/** @var \Magento\Catalog\Model\Layer\Filter\ItemFactory|MockObject */
private $filterItemFactory;

/**
* @var \Magento\Store\Api\Data\StoreInterface|MockObject
*/
private $storeMock;

/** @var \Magento\Catalog\Model\Layer\State|MockObject */
private $state;

protected function setUp()
{
$this->request = $this->getMockBuilder('\Magento\Framework\App\RequestInterface')
->disableOriginalConstructor()
->setMethods(['getParam'])
->getMockForAbstractClass();

$dataProviderFactory = $this->getMockBuilder('\Magento\Catalog\Model\Layer\Filter\DataProvider\PriceFactory')
->disableOriginalConstructor()
->setMethods(['create'])
->getMock();

$this->dataProvider = $this->getMockBuilder('\Magento\Catalog\Model\Layer\Filter\DataProvider\Price')
->disableOriginalConstructor()
->setMethods(['setPriceId', 'getPrice'])
->getMock();

$dataProviderFactory->expects($this->once())
->method('create')
->will($this->returnValue($this->dataProvider));

$this->layer = $this->getMockBuilder('\Magento\Catalog\Model\Layer')
->disableOriginalConstructor()
->setMethods(['getState', 'getProductCollection'])
->getMock();

$this->state = $this->getMockBuilder('\Magento\Catalog\Model\Layer\State')
->disableOriginalConstructor()
->setMethods(['addFilter'])
->getMock();
$this->layer->expects($this->any())
->method('getState')
->will($this->returnValue($this->state));

$this->fulltextCollection = $this->fulltextCollection = $this->getMockBuilder(
$this->fulltextCollection = $this->getMockBuilder(
'\Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection'
)
->disableOriginalConstructor()
->setMethods(['addFieldToFilter', 'getFacetedData'])
)->disableOriginalConstructor()
->getMock();

$this->layer->expects($this->any())
->method('getProductCollection')
->will($this->returnValue($this->fulltextCollection));

$this->itemDataBuilder = $this->getMockBuilder('\Magento\Catalog\Model\Layer\Filter\Item\DataBuilder')
->disableOriginalConstructor()
->setMethods(['addItemData', 'build'])
->getMock();

$this->filterItemFactory = $this->getMockBuilder(
'\Magento\Catalog\Model\Layer\Filter\ItemFactory'
)
$this->filterItemFactory = $this->getMockBuilder('\Magento\Catalog\Model\Layer\Filter\ItemFactory')
->disableOriginalConstructor()
->setMethods(['create'])
->getMock();

$filterItem = $this->getMockBuilder(
'\Magento\Catalog\Model\Layer\Filter\Item'
)
$filterItem = $this->getMockBuilder('\Magento\Catalog\Model\Layer\Filter\Item')
->disableOriginalConstructor()
->setMethods(['setFilter', 'setLabel', 'setValue', 'setCount'])
->getMock();
Expand All @@ -123,12 +111,20 @@ protected function setUp()

$escaper = $this->getMockBuilder('\Magento\Framework\Escaper')
->disableOriginalConstructor()
->setMethods(['escapeHtml'])
->getMock();
$escaper->expects($this->any())
->method('escapeHtml')
->will($this->returnArgument(0));

$this->storeMock = $this->getMockBuilder(\Magento\Store\Api\Data\StoreInterface::class)
->setMethods(['getCurrentCurrencyRate'])
->getMockForAbstractClass();
$storeManagerMock = $this->getMockBuilder(\Magento\Store\Model\StoreManagerInterface::class)
->getMockForAbstractClass();
$storeManagerMock->expects($this->any())
->method('getStore')
->willReturn($this->storeMock);

$this->attribute = $this->getMockBuilder('\Magento\Eav\Model\Entity\Attribute')
->disableOriginalConstructor()
->setMethods(['getAttributeCode', 'getFrontend', 'getIsFilterable'])
Expand All @@ -142,14 +138,14 @@ protected function setUp()
'itemDataBuilder' => $this->itemDataBuilder,
'filterItemFactory' => $this->filterItemFactory,
'escaper' => $escaper,
'storeManager' => $storeManagerMock,
]
);
}

/**
* @param $requestValue
* @param $idValue
* @param $isIdUsed
* @dataProvider applyWithEmptyRequestDataProvider
*/
public function testApplyWithEmptyRequest($requestValue, $idValue)
Expand Down Expand Up @@ -224,6 +220,10 @@ function ($field) use ($requestVar, $priceId) {
->with('price')
->will($this->returnSelf());

$this->storeMock->expects($this->atLeastOnce())
->method('getCurrentCurrencyRate')
->willReturn(1);

$this->target->apply($this->request);
}

Expand Down

0 comments on commit e8161ad

Please sign in to comment.