You are here

public function FormHelperTest::testCurrencyLocaleOptionsWithLimitation in Currency 8.3

@covers ::getCurrencyLocaleOptions

File

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

Class

FormHelperTest
@coversDefaultClass \Drupal\currency\FormHelper

Namespace

Drupal\Tests\currency\Unit

Code

public function testCurrencyLocaleOptionsWithLimitation() {
  $this->currencyStorage
    ->expects($this
    ->never())
    ->method('loadMultiple');
  $currency_locale_id_a = $this
    ->randomMachineName();
  $currency_locale_label_a = $this
    ->randomMachineName();
  $currency_locale_a = $this
    ->createMock(CurrencyLocaleInterface::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(CurrencyLocaleInterface::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(CurrencyLocaleInterface::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_c => $currency_locale_label_c,
  ];
  natcasesort($expected_options);
  $this
    ->assertSame($expected_options, $this->sut
    ->getCurrencyLocaleOptions([
    $currency_locale_a,
    $currency_locale_b,
    $currency_locale_c,
  ]));
}