|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * Copyright © Magento, Inc. All rights reserved. |
| 5 | + * See COPYING.txt for license details. |
| 6 | + */ |
| 7 | +declare(strict_types=1); |
| 8 | + |
| 9 | +namespace Magento\Framework\Test\Unit\Currency\Data; |
| 10 | + |
| 11 | +use Magento\Framework\Currency\Data\Currency; |
| 12 | +use PHPUnit\Framework\TestCase; |
| 13 | + |
| 14 | +/** |
| 15 | + * Test for Magento\Framework\Currency\Data\Currency |
| 16 | + */ |
| 17 | +class CurrencyTest extends TestCase |
| 18 | +{ |
| 19 | + /** |
| 20 | + * @param float|int|null $value |
| 21 | + * @param array $options |
| 22 | + * @param string $expectedResult |
| 23 | + * @return void |
| 24 | + * @throws \Magento\Framework\Currency\Exception\CurrencyException |
| 25 | + * |
| 26 | + * @dataProvider toCurrencyPositionsDataProvider |
| 27 | + */ |
| 28 | + public function testToCurrencyPositions(float|int|null $value, array $options, string $expectedResult): void |
| 29 | + { |
| 30 | + $currency = new Currency(); |
| 31 | + $result = $currency->toCurrency($value, $options); |
| 32 | + |
| 33 | + $this->assertEquals($expectedResult, $result); |
| 34 | + } |
| 35 | + |
| 36 | + /** |
| 37 | + * @return array[] |
| 38 | + */ |
| 39 | + public function toCurrencyPositionsDataProvider(): array |
| 40 | + { |
| 41 | + return [ |
| 42 | + 'rightPosition_en_AU' => [ |
| 43 | + 'value' => 3, |
| 44 | + 'options' => [ |
| 45 | + 'position' => Currency::RIGHT, |
| 46 | + 'locale' => 'en_AU', |
| 47 | + 'currency' => 'AUD', |
| 48 | + ], |
| 49 | + 'expectedResult' => '3.00$', |
| 50 | + ], |
| 51 | + 'leftPosition_en_AU' => [ |
| 52 | + 'value' => 3, |
| 53 | + 'options' => [ |
| 54 | + 'position' => Currency::LEFT, |
| 55 | + 'locale' => 'en_AU', |
| 56 | + 'currency' => 'AUD', |
| 57 | + ], |
| 58 | + 'expectedResult' => '$3.00', |
| 59 | + ], |
| 60 | + 'defaultPosition_en_AU' => [ |
| 61 | + 'value' => 22, |
| 62 | + 'options' => [ |
| 63 | + 'locale' => 'en_AU', |
| 64 | + 'currency' => 'AUD', |
| 65 | + ], |
| 66 | + 'expectedResult' => '$22.00', |
| 67 | + ], |
| 68 | + |
| 69 | + 'rightPosition_CUST_en_US' => [ |
| 70 | + 'value' => 12, |
| 71 | + 'options' => [ |
| 72 | + 'position' => Currency::RIGHT, |
| 73 | + 'locale' => 'en_US', |
| 74 | + 'symbol' => 'CUST', |
| 75 | + ], |
| 76 | + 'expectedResult' => '12.00CUST', |
| 77 | + ], |
| 78 | + 'leftPosition_CUST_en_US' => [ |
| 79 | + 'value' => 12, |
| 80 | + 'options' => [ |
| 81 | + 'position' => Currency::LEFT, |
| 82 | + 'locale' => 'en_US', |
| 83 | + 'symbol' => 'CUST', |
| 84 | + ], |
| 85 | + 'expectedResult' => 'CUST12.00', |
| 86 | + ], |
| 87 | + 'rightPosition_CUST_with_space_zu_ZA' => [ |
| 88 | + 'value' => 12, |
| 89 | + 'options' => [ |
| 90 | + 'position' => Currency::RIGHT, |
| 91 | + 'locale' => 'zu_ZA', |
| 92 | + 'symbol' => 'CUST', |
| 93 | + ], |
| 94 | + 'expectedResult' => '12.00 CUST', |
| 95 | + ], |
| 96 | + 'leftPosition_CUST_with_space_zu_ZA' => [ |
| 97 | + 'value' => 12, |
| 98 | + 'options' => [ |
| 99 | + 'position' => Currency::LEFT, |
| 100 | + 'locale' => 'zu_ZA', |
| 101 | + 'symbol' => 'CUST', |
| 102 | + ], |
| 103 | + 'expectedResult' => 'CUST 12.00', |
| 104 | + ], |
| 105 | + ]; |
| 106 | + } |
| 107 | +} |
0 commit comments