function BasicTest::testFormatAmount in Currency 8.3
@covers ::formatAmount
File
- tests/
src/ Unit/ Plugin/ Currency/ AmountFormatter/ BasicTest.php, line 81
Class
- BasicTest
- @coversDefaultClass \Drupal\currency\Plugin\Currency\AmountFormatter\Basic
Namespace
Drupal\Tests\currency\Unit\Plugin\Currency\AmountFormatterCode
function testFormatAmount() {
$decimal_separator = '@';
$grouping_separator = '%';
$currency_locale = $this
->createMock(CurrencyLocaleInterface::class);
$currency_locale
->expects($this
->any())
->method('getDecimalSeparator')
->willReturn($decimal_separator);
$currency_locale
->expects($this
->any())
->method('getGroupingSeparator')
->willReturn($grouping_separator);
$this->localeResolver
->expects($this
->any())
->method('resolveCurrencyLocale')
->willReturn($currency_locale);
// The formatter must not alter the decimals.
$amount = '987654.321';
$currency_sign = '₴';
$currency_code = 'UAH';
$currency_decimals = 2;
$currency = $this
->createMock(CurrencyInterface::class);
$currency
->expects($this
->any())
->method('getCurrencyCode')
->willReturn($currency_code);
$currency
->expects($this
->any())
->method('getDecimals')
->willReturn($currency_decimals);
$currency
->expects($this
->any())
->method('getSign')
->willReturn($currency_sign);
$translation = 'UAH 987%654@321';
$arguments = array(
'@currency_code' => 'UAH',
'@currency_sign' => '₴',
'@amount' => '987%654@321',
);
$formatted_amount = $this->sut
->formatAmount($currency, $amount);
$this
->assertInstanceOf(TranslatableMarkup::class, $formatted_amount);
$this
->assertSame('@currency_code @amount', $formatted_amount
->getUntranslatedString());
$this
->assertSame($arguments, $formatted_amount
->getArguments());
}