Skip to content

Commit 4b54591

Browse files
authored
ENGCOM-7962: Fix Issues 29213 #29214
2 parents f894aaf + e7c4de7 commit 4b54591

File tree

2 files changed

+105
-3
lines changed
  • app/code/Magento/Backend

2 files changed

+105
-3
lines changed

app/code/Magento/Backend/Block/Widget/Grid/Column/Filter/Price.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ protected function _getCurrencyList()
162162
/**
163163
* Retrieve filter value
164164
*
165-
* @param null $index
165+
* @param string|null $index
166166
* @return array|null
167167
*/
168168
public function getValue($index = null)
@@ -194,11 +194,11 @@ public function getCondition()
194194
$rate = $this->_getRate($displayCurrency, $this->_getColumnCurrencyCode());
195195

196196
if (isset($value['from'])) {
197-
$value['from'] *= $rate;
197+
$value['from'] = (float) $value['from'] * $rate;
198198
}
199199

200200
if (isset($value['to'])) {
201-
$value['to'] *= $rate;
201+
$value['to'] = (float) $value['to'] * $rate;
202202
}
203203

204204
$this->prepareRates($displayCurrency);
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Backend\Test\Unit\Block\Widget\Grid\Column\Filter;
9+
10+
use Magento\Backend\Block\Context;
11+
use Magento\Backend\Block\Widget\Grid\Column;
12+
use Magento\Backend\Block\Widget\Grid\Column\Filter\Price;
13+
use Magento\Framework\App\RequestInterface;
14+
use Magento\Framework\DB\Helper;
15+
use Magento\Directory\Model\Currency;
16+
use Magento\Directory\Model\Currency\DefaultLocator;
17+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
18+
use PHPUnit\Framework\MockObject\MockObject;
19+
use PHPUnit\Framework\TestCase;
20+
21+
class PriceTest extends TestCase
22+
{
23+
/** @var RequestInterface|MockObject */
24+
private $requestMock;
25+
26+
/** @var Context|MockObject */
27+
private $context;
28+
29+
/** @var Helper|MockObject */
30+
private $helper;
31+
32+
/** @var Currency|MockObject */
33+
private $currency;
34+
35+
/** @var DefaultLocator|MockObject */
36+
private $currencyLocator;
37+
38+
/** @var Column|MockObject */
39+
private $columnMock;
40+
41+
/** @var Price */
42+
private $blockPrice;
43+
44+
protected function setUp(): void
45+
{
46+
$this->requestMock = $this->getMockForAbstractClass(RequestInterface::class);
47+
48+
$this->context = $this->createMock(Context::class);
49+
$this->context->expects($this->any())->method('getRequest')->willReturn($this->requestMock);
50+
51+
$this->helper = $this->createMock(Helper::class);
52+
53+
$this->currency = $this->getMockBuilder(Currency::class)
54+
->disableOriginalConstructor()
55+
->setMethods(['getAnyRate'])
56+
->getMock();
57+
58+
$this->currencyLocator = $this->createMock(DefaultLocator::class);
59+
60+
$this->columnMock = $this->getMockBuilder(Column::class)
61+
->disableOriginalConstructor()
62+
->setMethods(['getCurrencyCode'])
63+
->getMock();
64+
65+
$helper = new ObjectManager($this);
66+
67+
$this->blockPrice = $helper->getObject(Price::class, [
68+
'context' => $this->context,
69+
'resourceHelper' => $this->helper,
70+
'currencyModel' => $this->currency,
71+
'currencyLocator' => $this->currencyLocator
72+
]);
73+
$this->blockPrice->setColumn($this->columnMock);
74+
}
75+
76+
public function testGetCondition()
77+
{
78+
$this->currencyLocator->expects(
79+
$this->any()
80+
)->method(
81+
'getDefaultCurrency'
82+
)->with(
83+
$this->requestMock
84+
)->willReturn(
85+
'defaultCurrency'
86+
);
87+
88+
$this->currency->expects($this->at(0))
89+
->method('getAnyRate')
90+
->with('defaultCurrency')
91+
->willReturn(1.0);
92+
93+
$testValue = [
94+
'value' => [
95+
'from' => '1234a',
96+
]
97+
];
98+
99+
$this->blockPrice->addData($testValue);
100+
$this->assertEquals(['from' => 1234], $this->blockPrice->getCondition());
101+
}
102+
}

0 commit comments

Comments
 (0)