IntlTest.php in Currency 8.3
File
modules/currency_intl/tests/src/Unit/Plugin/Currency/AmountFormatter/IntlTest.php
View source
<?php
namespace Drupal\Tests\currency_intl\Unit\Plugin\Currency\AmountFormatter;
use Commercie\Currency\CurrencyInterface;
use Drupal\currency\Entity\CurrencyLocaleInterface;
use Drupal\currency\LocaleResolverInterface;
use Drupal\currency_intl\Plugin\Currency\AmountFormatter\Intl;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\DependencyInjection\ContainerInterface;
class IntlTest extends UnitTestCase {
protected $formatter;
protected $localeResolver;
public function setUp() {
$configuration = array();
$plugin_id = $this
->randomMachineName();
$plugin_definition = array();
$this->localeResolver = $this
->createMock(LocaleResolverInterface::class);
$this->formatter = new Intl($configuration, $plugin_id, $plugin_definition, $this->localeResolver);
}
function testCreate() {
$container = $this
->createMock(ContainerInterface::class);
$container
->expects($this
->once())
->method('get')
->with('currency.locale_resolver')
->willReturn($this->localeResolver);
$configuration = array();
$plugin_id = $this
->randomMachineName();
$plugin_definition = array();
$formatter = Intl::create($container, $configuration, $plugin_id, $plugin_definition);
$this
->assertInstanceOf(Intl::class, $formatter);
}
function testFormatAmount() {
$locale = 'nl_NL';
$pattern = '¤-#,##0.00¤¤';
$decimal_separator = '@';
$grouping_separator = '%';
$currency_locale = $this
->createMock(CurrencyLocaleInterface::class);
$currency_locale
->expects($this
->any())
->method('getLocale')
->willReturn($locale);
$currency_locale
->expects($this
->any())
->method('getPattern')
->willReturn($pattern);
$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);
$currency_sign = '₴';
$currency_code = 'UAH';
$currency = $this
->createMock(CurrencyInterface::class);
$currency
->expects($this
->any())
->method('getCurrencyCode')
->willReturn($currency_code);
$currency
->expects($this
->any())
->method('getSign')
->willReturn($currency_sign);
$results = array(
'123' => '₴-123UAH',
'1234567.890' => '₴-1%234%567@890UAH',
'.3' => '₴-0@3UAH',
);
foreach ($results as $amount => $expected) {
$formatted = $this->formatter
->formatAmount($currency, $amount);
$this
->assertSame($expected, $formatted);
}
}
}