You are here

protected function CurrentCurrencyTest::setUp in Commerce Currency Resolver 8

Overrides OrderKernelTestBase::setUp

File

tests/src/Kernel/CurrentCurrencyTest.php, line 58

Class

CurrentCurrencyTest
Tests current currency class.

Namespace

Drupal\Tests\commerce_currency_resolver\Kernel

Code

protected function setUp() {
  parent::setUp();
  $this
    ->installConfig('system');
  $this
    ->installConfig('language');

  // Add additional language.
  ConfigurableLanguage::create([
    'id' => 'hr',
  ])
    ->save();

  // Ensure we are building a new Language object for each test.
  $this->languageManager = $this->container
    ->get('language_manager');
  $this->languageDefault = $this->container
    ->get('language.default');
  $language = ConfigurableLanguage::load('hr');
  $this->languageDefault
    ->set($language);
  $this
    ->config('system.site')
    ->set('default_langcode', $language
    ->getId())
    ->save();
  $this->languageManager
    ->reset();

  // Add additional currency.
  // The parent has already imported USD.
  $currency_importer = $this->container
    ->get('commerce_price.currency_importer');
  $currency_importer
    ->import('HRK');

  // Resolver configuration specifics.
  $this
    ->installConfig([
    'commerce_currency_resolver',
  ]);
  $this
    ->config('commerce_currency_resolver.settings')
    ->set('currency_default', 'HRK')
    ->save();
  $this->currentCurrency = $this->container
    ->get('commerce_currency_resolver.current_currency');

  // Prepare mapping for language test.
  $this
    ->config('commerce_currency_resolver.currency_mapping')
    ->setData([
    'domicile_currency' => NULL,
    'logic' => NULL,
    'matrix' => [
      'en' => 'USD',
      'hr' => 'HRK',
    ],
  ])
    ->save();
}