You are here

protected function OrderIntegrationTest::setUp in Commerce Currency Resolver 8

Overrides OrderKernelTestBase::setUp

File

tests/src/Kernel/OrderIntegrationTest.php, line 47

Class

OrderIntegrationTest
Tests integration with orders.

Namespace

Drupal\Tests\commerce_currency_resolver\Kernel

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');
  $this
    ->installConfig([
    'commerce_currency_resolver',
  ]);
  $user = $this
    ->createUser([
    'mail' => $this
      ->randomString() . '@example.com',
  ]);

  // 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();
  $order = Order::create([
    'type' => 'default',
    'store_id' => $this->store
      ->id(),
    'state' => 'draft',
    'mail' => $user
      ->getEmail(),
    'uid' => $user
      ->id(),
    'ip_address' => '127.0.0.1',
    'order_number' => '6',
  ]);
  $order
    ->save();
  $this->order = $this
    ->reloadEntity($order);
  $this->currentCurrency = $this->container
    ->get('commerce_currency_resolver.current_currency');
}