You are here

public function FormHelperTest::testCurrencyOptionsWithLimitation in Currency 8.3

@covers ::getCurrencyOptions

File

tests/src/Unit/FormHelperTest.php, line 98

Class

FormHelperTest
@coversDefaultClass \Drupal\currency\FormHelper

Namespace

Drupal\Tests\currency\Unit

Code

public function testCurrencyOptionsWithLimitation() {
  $this->currencyStorage
    ->expects($this
    ->never())
    ->method('loadMultiple');
  $currency_locale_id_a = $this
    ->randomMachineName();
  $currency_locale_label_a = $this
    ->randomMachineName();
  $currency_locale_a = $this
    ->createMock(CurrencyInterface::class);
  $currency_locale_a
    ->expects($this
    ->atLeastOnce())
    ->method('id')
    ->willReturn($currency_locale_id_a);
  $currency_locale_a
    ->expects($this
    ->atLeastOnce())
    ->method('label')
    ->willReturn($currency_locale_label_a);
  $currency_locale_a
    ->expects($this
    ->atLeastOnce())
    ->method('status')
    ->willReturn(TRUE);
  $currency_locale_b = $this
    ->createMock(CurrencyInterface::class);
  $currency_locale_b
    ->expects($this
    ->atLeastOnce())
    ->method('status')
    ->willReturn(FALSE);
  $currency_locale_id_c = $this
    ->randomMachineName();
  $currency_locale_label_c = $this
    ->randomMachineName();
  $currency_locale_c = $this
    ->createMock(CurrencyInterface::class);
  $currency_locale_c
    ->expects($this
    ->atLeastOnce())
    ->method('id')
    ->willReturn($currency_locale_id_c);
  $currency_locale_c
    ->expects($this
    ->atLeastOnce())
    ->method('label')
    ->willReturn($currency_locale_label_c);
  $currency_locale_c
    ->expects($this
    ->atLeastOnce())
    ->method('status')
    ->willReturn(TRUE);
  $expected_options = [
    $currency_locale_id_a => $currency_locale_label_a . ' (' . $currency_locale_id_a . ')',
    $currency_locale_id_c => $currency_locale_label_c . ' (' . $currency_locale_id_c . ')',
  ];
  natcasesort($expected_options);
  $options = $this->sut
    ->getCurrencyOptions([
    $currency_locale_a,
    $currency_locale_b,
    $currency_locale_c,
  ]);
  $this
    ->assertEmpty(array_diff_key($options, $expected_options));
  $this
    ->assertEmpty(array_diff_key($expected_options, $options));
  foreach ($options as $option) {
    $this
      ->assertInstanceOf(TranslatableMarkup::class, $option);
  }
}