You are here

public function OrderMultilingualTest::testOrderStoreTranslated in Commerce Core 8.2

Tests that the order's store is translated to current language.

File

modules/order/tests/src/Kernel/OrderMultilingualTest.php, line 41

Class

OrderMultilingualTest
Tests orders and order items in a multilingual context.

Namespace

Drupal\Tests\commerce_order\Kernel

Code

public function testOrderStoreTranslated() {
  $this->container
    ->get('content_translation.manager')
    ->setEnabled('commerce_store', 'online', TRUE);
  $this->store = $this
    ->reloadEntity($this->store);
  $this->store
    ->addTranslation('fr', [
    'name' => 'Magasin par défaut',
  ])
    ->save();
  $user = $this
    ->createUser([
    'mail' => $this
      ->randomString() . '@example.com',
  ]);
  $order = Order::create([
    'type' => 'default',
    'store_id' => $this->store
      ->id(),
    'state' => 'draft',
    'mail' => 'text@example.com',
    'uid' => $user
      ->id(),
    'ip_address' => '127.0.0.1',
    'order_items' => [],
  ]);
  $this
    ->assertEquals('Default store', $order
    ->getStore()
    ->label());
  $this
    ->config('system.site')
    ->set('default_langcode', 'fr')
    ->save();
  $this
    ->assertEquals('Magasin par défaut', $order
    ->getStore()
    ->label());

  // Change the default site language and ensure the store is returned
  // even if it has not been translated to that language.
  $this
    ->config('system.site')
    ->set('default_langcode', 'sr')
    ->save();
  $this
    ->assertEquals('Default store', $order
    ->getStore()
    ->label());
}