Skip to content

Commit 0d15f3d

Browse files
committed
ACP2E-3276: Order reports showing the wrong currency symbol
1 parent 9ada3f6 commit 0d15f3d

File tree

1 file changed

+9
-123
lines changed
  • app/code/Magento/Reports/Test/Unit/Block/Adminhtml/Grid/Column/Renderer

1 file changed

+9
-123
lines changed

app/code/Magento/Reports/Test/Unit/Block/Adminhtml/Grid/Column/Renderer/CurrencyTest.php

Lines changed: 9 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,20 @@
1616
use Magento\Framework\Currency\Exception\CurrencyException;
1717
use Magento\Framework\DataObject;
1818
use Magento\Framework\Exception\LocalizedException;
19-
use Magento\Framework\Exception\NoSuchEntityException;
2019
use Magento\Framework\Locale\CurrencyInterface;
21-
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
2220
use Magento\Reports\Block\Adminhtml\Grid\Column\Renderer\Currency;
2321
use Magento\Store\Api\Data\StoreInterface;
24-
use Magento\Store\Api\Data\WebsiteInterface;
2522
use Magento\Store\Model\StoreManagerInterface;
23+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
24+
use PHPUnit\Framework\MockObject\Exception;
2625
use PHPUnit\Framework\MockObject\MockObject;
2726
use PHPUnit\Framework\TestCase;
2827

2928
/**
3029
* Test for class Currency.
3130
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
3231
*/
32+
#[\AllowDynamicProperties] //@phpstan-ignore-line
3333
class CurrencyTest extends TestCase
3434
{
3535
/**
@@ -57,21 +57,11 @@ class CurrencyTest extends TestCase
5757
*/
5858
private $gridColumnMock;
5959

60-
/**
61-
* @var ScopeConfigInterface|MockObject
62-
*/
63-
private $scopeConfigMock;
64-
6560
/**
6661
* @var StoreInterface|MockObject
6762
*/
6863
private $storeMock;
6964

70-
/**
71-
* @var WebsiteInterface|MockObject
72-
*/
73-
private $websiteMock;
74-
7565
/**
7666
* @var DataObject
7767
*/
@@ -110,26 +100,6 @@ protected function setUp(): void
110100
['getStore', 'getWebsite']
111101
);
112102

113-
$this->storeMock = $this->getMockForAbstractClass(
114-
StoreInterface::class,
115-
[],
116-
'',
117-
true,
118-
true,
119-
true,
120-
['getWebsiteId', 'getCurrentCurrencyCode']
121-
);
122-
123-
$this->websiteMock = $this->getMockForAbstractClass(
124-
WebsiteInterface::class,
125-
[],
126-
'',
127-
true,
128-
true,
129-
true,
130-
['getBaseCurrencyCode']
131-
);
132-
133103
$this->currencyLocatorMock = $this->getMockBuilder(DefaultLocator::class)
134104
->disableOriginalConstructor()
135105
->getMock();
@@ -175,32 +145,19 @@ protected function setUp(): void
175145
*
176146
* @param float $rate
177147
* @param string $columnIndex
178-
* @param int $catalogPriceScope
179-
* @param int $adminWebsiteId
180-
* @param string $adminCurrencyCode
181148
* @param string $storeCurrencyCode
182-
* @param string $displayCurrencyCode
183149
* @param string $adminOrderAmount
184150
* @param string $convertedAmount
185-
* @param bool $needToGetRateFromModel
186151
* @throws LocalizedException
187-
* @throws NoSuchEntityException
188-
* @throws CurrencyException
152+
* @throws CurrencyException|Exception
189153
* @dataProvider getCurrencyDataProvider
190-
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
191-
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
192154
*/
193155
public function testRender(
194156
float $rate,
195157
string $columnIndex,
196-
int $catalogPriceScope,
197-
int $adminWebsiteId,
198-
string $adminCurrencyCode,
199158
string $storeCurrencyCode,
200-
string $displayCurrencyCode,
201159
string $adminOrderAmount,
202160
string $convertedAmount,
203-
bool $needToGetRateFromModel
204161
): void {
205162
$this->row = new DataObject(
206163
[
@@ -220,35 +177,14 @@ public function testRender(
220177
->expects($this->any())
221178
->method('getRate')
222179
->willReturn($rate);
223-
$this->scopeConfigMock
224-
->expects($this->any())
225-
->method('getValue')
226-
->willReturn($catalogPriceScope);
227180
$this->storeManagerMock
228181
->expects($this->any())
229182
->method('getStore')
230183
->willReturn($this->storeMock);
231-
$this->storeMock
232-
->expects($this->any())
233-
->method('getWebsiteId')
234-
->willReturn($adminWebsiteId);
235-
$this->storeManagerMock
236-
->expects($this->any())
237-
->method('getWebsite')
238-
->with($adminWebsiteId)
239-
->willReturn($this->websiteMock);
240-
$this->websiteMock
241-
->expects($this->any())
242-
->method('getBaseCurrencyCode')
243-
->willReturn($adminCurrencyCode);
244184
$this->currencyLocatorMock
245185
->expects($this->any())
246186
->method('getDefaultCurrency')
247187
->willReturn($storeCurrencyCode);
248-
$this->currencyLocatorMock
249-
->expects($this->any())
250-
->method('getDisplayCurrency')
251-
->willReturn($displayCurrencyCode);
252188
$currLocaleMock = $this->createMock(CurrencyData::class);
253189
$currLocaleMock
254190
->expects($this->any())
@@ -257,18 +193,11 @@ public function testRender(
257193
$this->localeCurrencyMock
258194
->expects($this->any())
259195
->method('getCurrency')
260-
->with($displayCurrencyCode)
196+
->with($storeCurrencyCode)
261197
->willReturn($currLocaleMock);
262-
$this->gridColumnMock->method('getCurrency')->willReturn($displayCurrencyCode);
198+
$this->gridColumnMock->method('getCurrency')->willReturn($storeCurrencyCode);
263199
$this->gridColumnMock->method('getRateField')->willReturn('test_rate_field');
264200

265-
if ($needToGetRateFromModel) {
266-
$this->currencyMock->expects($this->once())
267-
->method('getAnyRate')
268-
->with($storeCurrencyCode)
269-
->willReturn($rate);
270-
}
271-
272201
$actualAmount = $this->model->render($this->row);
273202
$this->assertEquals($convertedAmount, $actualAmount);
274203
}
@@ -281,64 +210,21 @@ public function testRender(
281210
public static function getCurrencyDataProvider(): array
282211
{
283212
return [
284-
'rate conversion with same admin and storefront rate' => [
285-
'rate' => 1.00,
286-
'columnIndex' => 'total_income_amount',
287-
'catalogPriceScope' => 1,
288-
'adminWebsiteId' => 1,
289-
'adminCurrencyCode' => 'EUR',
290-
'storeCurrencyCode' => 'EUR',
291-
'displayCurrencyCode' => 'EUR',
292-
'adminOrderAmount' => '105.00',
293-
'convertedAmount' => '€105.00',
294-
'needToGetRateFromModel' => false
295-
],
296-
'rate conversion with different admin and storefront rate' => [
297-
'rate' => 1.4150,
213+
'rate conversion with storefront' => [
214+
'rate' => 1.367,
298215
'columnIndex' => 'total_income_amount',
299-
'catalogPriceScope' => 1,
300-
'adminWebsiteId' => 1,
301-
'adminCurrencyCode' => 'USD',
302216
'storeCurrencyCode' => 'EUR',
303-
'displayCurrencyCode' => 'EUR',
304-
'adminOrderAmount' => '105.00',
305-
'convertedAmount' => '148.575',
306-
'needToGetRateFromModel' => true
307-
],
308-
'rate conversation with same rate for different currencies' => [
309-
'rate' => 1.00,
310-
'columnIndex' => 'total_income_amount',
311-
'catalogPriceScope' => 1,
312-
'adminWebsiteId' => 1,
313-
'adminCurrencyCode' => 'USD',
314-
'storeCurrencyCode' => 'THB',
315-
'displayCurrencyCode' => 'THB',
316217
'adminOrderAmount' => '100.00',
317-
'convertedAmount' => '100.00',
318-
'needToGetRateFromModel' => true
319-
],
320-
'rate conversation with different rate for different display currencies' => [
321-
'rate' => 1.6150,
322-
'columnIndex' => 'total_income_amount',
323-
'catalogPriceScope' => 1,
324-
'adminWebsiteId' => 1,
325-
'adminCurrencyCode' => 'USD',
326-
'storeCurrencyCode' => 'USD',
327-
'displayCurrencyCode' => 'EUR',
328-
'adminOrderAmount' => '$100.00',
329-
'convertedAmount' => '€161.50',
330-
'needToGetRateFromModel' => false
218+
'convertedAmount' => '€136.70',
331219
],
332220
];
333221
}
334222

335223
protected function tearDown(): void
336224
{
337-
unset($this->scopeConfigMock);
338225
unset($this->storeManagerMock);
339226
unset($this->currencyLocatorMock);
340227
unset($this->localeCurrencyMock);
341-
unset($this->websiteMock);
342228
unset($this->storeMock);
343229
unset($this->currencyMock);
344230
unset($this->backendCurrencyMock);

0 commit comments

Comments
 (0)