You are here

public function FixedRatesOverviewTest::testOverview in Currency 8.3

@covers ::overview

File

tests/src/Unit/Controller/FixedRatesOverviewTest.php, line 113

Class

FixedRatesOverviewTest
@coversDefaultClass \Drupal\currency\Controller\FixedRatesOverview

Namespace

Drupal\Tests\currency\Unit\Controller

Code

public function testOverview() {
  $currency_code_from = 'EUR';
  $currency_code_to = 'NLG';
  $rate = '2.20371';
  $currency_from = $this
    ->createMock(CurrencyInterface::class);
  $currency_from
    ->expects($this
    ->once())
    ->method('label');
  $currency_to = $this
    ->createMock(CurrencyInterface::class);
  $currency_to
    ->expects($this
    ->once())
    ->method('label');
  $map = array(
    array(
      $currency_code_from,
      $currency_from,
    ),
    array(
      $currency_code_to,
      $currency_to,
    ),
  );
  $this->currencyStorage
    ->expects($this
    ->any())
    ->method('load')
    ->willReturnMap($map);
  $rates_configuration = array(
    $currency_code_from => array(
      $currency_code_to => $rate,
    ),
  );
  $fixed_rates = $this
    ->getMockBuilder(FixedRates::class)
    ->disableOriginalConstructor()
    ->getMock();
  $fixed_rates
    ->expects($this
    ->once())
    ->method('loadAll')
    ->willReturn($rates_configuration);
  $this->currencyExchangeRateProviderManager
    ->expects($this
    ->once())
    ->method('createInstance')
    ->with('currency_fixed_rates')
    ->willReturn($fixed_rates);
  $this->urlGenerator
    ->expects($this
    ->once())
    ->method('generateFromRoute')
    ->with('currency.exchange_rate_provider.fixed_rates.add');
  $amount_formatter = $this
    ->createMock(AmountFormatterInterface::class);
  $amount_formatter
    ->expects($this
    ->once())
    ->method('formatAmount')
    ->with($currency_to, $rate);
  $this->currencyAmountFormatterManager
    ->expects($this
    ->once())
    ->method('getDefaultPlugin')
    ->willReturn($amount_formatter);
  $build = $this->sut
    ->overview();
  $this
    ->assertIsArray($build);
}