You are here

protected function CurrentCurrencyCartTest::setUp in Commerce Currency Resolver 8

Overrides CartBrowserTestBase::setUp

File

tests/src/Functional/CurrentCurrencyCartTest.php, line 43

Class

CurrentCurrencyCartTest
Tests the add to cart form with mixed currencies.

Namespace

Drupal\Tests\commerce_currency_resolver\Functional

Code

protected function setUp() {
  parent::setUp();

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

  // Create new exchange rates.
  $exchange_rates = ExchangeRates::create([
    'id' => 'testing',
    'label' => 'Manual',
    'plugin' => 'manual',
    'status' => TRUE,
    'configuration' => [
      'cron' => FALSE,
      'use_cross_sync' => FALSE,
      'demo_amount' => 100,
      'base_currency' => 'USD',
      'mode' => 'live',
    ],
  ]);
  $exchange_rates
    ->save();
  $this
    ->config($exchange_rates
    ->getExchangerConfigName())
    ->setData([
    'rates' => [
      'HRK' => [
        'USD' => [
          'value' => 0.15,
          'sync' => 0,
        ],
      ],
      'USD' => [
        'HRK' => [
          'value' => 6.85,
          'sync' => 0,
        ],
      ],
    ],
  ])
    ->save();
  $this
    ->config('commerce_currency_resolver.settings')
    ->set('currency_exchange_rates', 'testing')
    ->save();
  $this->store
    ->setDefaultCurrencyCode('HRK');
  $this->store
    ->save();
  $this
    ->reloadEntity($this->store);
  $this->currentCurrency = $this->container
    ->get('commerce_currency_resolver.current_currency');
  $variation_display = commerce_get_entity_display('commerce_product_variation', 'default', 'view');
  $variation_display
    ->setComponent('price', [
    'label' => 'above',
    'type' => 'commerce_price_calculated',
    'settings' => [],
  ]);
  $variation_display
    ->save();
}