You are here

function AmountTest::testGetCurrencyWithCurrencyCodeField in Currency 8.3

@covers ::getCurrency

File

tests/src/Unit/Plugin/views/field/AmountTest.php, line 318

Class

AmountTest
@coversDefaultClass \Drupal\currency\Plugin\views\field\Amount

Namespace

Drupal\Tests\currency\Unit\Plugin\views\field

Code

function testGetCurrencyWithCurrencyCodeField() {
  $currency_code = $this
    ->randomMachineName();
  $currency_code_field = $this
    ->randomMachineName();
  $currency = $this
    ->createMock(CurrencyInterface::class);
  $map = [
    [
      $currency_code,
      $currency,
    ],
  ];
  $this->currencyStorage
    ->expects($this
    ->atLeastOnce())
    ->method('load')
    ->willReturnMap($map);
  $field_alias = $this
    ->randomMachineName();
  $result_row = new ResultRow([
    $field_alias => $currency_code,
  ]);
  $configuration = [];
  $plugin_id = $this
    ->randomMachineName();
  $this->pluginDefinition['currency_code_field'] = $currency_code_field;
  $this->sut = new Amount($configuration, $plugin_id, $this->pluginDefinition, $this->stringTranslation, $this->moduleHandler, $this->renderer, $this->currencyStorage);
  $this->sut
    ->init($this->viewsViewExecutable, $this->viewsDisplayHandler);
  $this->sut->aliases['currency_code_field'] = $field_alias;
  $method = new \ReflectionMethod($this->sut, 'getCurrency');
  $method
    ->setAccessible(TRUE);
  $this
    ->assertSame($currency, $method
    ->invoke($this->sut, $result_row));
}