You are here

public function ConfigImporterTest::testGetImportableCurrencies in Currency 8.3

@covers ::getImportableCurrencies @covers ::createCurrencyFromRepository

File

tests/src/Unit/ConfigImporterTest.php, line 134

Class

ConfigImporterTest
@coversDefaultClass \Drupal\currency\ConfigImporter

Namespace

Drupal\Tests\currency\Unit

Code

public function testGetImportableCurrencies() {
  $resource_repository = new ResourceRepository();
  $resource_repository_currency_codes = $resource_repository
    ->listCurrencies();

  // Fake the importable and existing currencies, by taking two mutually
  // exclusive, randomized samples of the currencies available in the
  // repository.
  shuffle($resource_repository_currency_codes);
  list($expected_importable_currency_codes, $stored_currency_codes) = array_chunk($resource_repository_currency_codes, ceil(count($resource_repository_currency_codes) / 2));
  $currency = $this
    ->createMock(CurrencyInterface::class);
  $stored_currencies = [];
  foreach ($stored_currency_codes as $stored_currency_code) {
    $stored_currencies[$stored_currency_code] = $this
      ->createMock(CurrencyInterface::class);
  }
  $this->currencyStorage
    ->expects($this
    ->atLeastOnce())
    ->method('create')
    ->willReturn($currency);
  $this->currencyStorage
    ->expects($this
    ->atLeastOnce())
    ->method('loadMultiple')
    ->with(NULL)
    ->willReturn($stored_currencies);
  $importable_currencies = $this->sut
    ->getImportableCurrencies();
  sort($expected_importable_currency_codes);
  $importable_currency_codes = array_keys($importable_currencies);
  sort($importable_currency_codes);
  $this
    ->assertSame($expected_importable_currency_codes, $importable_currency_codes);
}