You are here

public function ProductTranslationTest::testProductTranslation in Commerce Core 8.2

Test translating a product and its variations.

File

modules/product/tests/src/Functional/ProductTranslationTest.php, line 74

Class

ProductTranslationTest
Tests translating products and variations.

Namespace

Drupal\Tests\commerce_product\Functional

Code

public function testProductTranslation() {
  $product = $this
    ->createEntity('commerce_product', [
    'type' => 'default',
    'title' => 'Translation test product',
    'stores' => $this->stores,
  ]);
  $this
    ->createEntity('commerce_product_variation', [
    'type' => 'default',
    'product_id' => $product
      ->id(),
    'sku' => $this
      ->randomMachineName(),
    'price' => new Price('9.99', 'USD'),
  ]);
  $this
    ->drupalGet($product
    ->toUrl('edit-form'));
  $this
    ->getSession()
    ->getPage()
    ->clickLink('Translate');
  $this
    ->assertSession()
    ->linkByHrefExists("/product/{$product->id()}/translations/add/en/fr");
  $this
    ->getSession()
    ->getPage()
    ->clickLink('Add');
  $this
    ->getSession()
    ->getPage()
    ->fillField('Title', 'Produit de test de traduction');
  $this
    ->getSession()
    ->getPage()
    ->pressButton('Save (this translation)');
  $this
    ->assertSession()
    ->pageTextContains('The product Produit de test de traduction has been successfully saved.');
  $this
    ->drupalGet(Url::fromRoute('entity.commerce_product_variation.collection', [
    'commerce_product' => $product
      ->id(),
  ]));
  $this
    ->assertSession()
    ->linkByHrefExists('/product/1/variations/1/translations');
  $this
    ->getSession()
    ->getPage()
    ->clickLink('Translate');
  $this
    ->assertSession()
    ->linkByHrefExists('/fr/product/1/variations/1/translations/add/en/fr');
  $this
    ->getSession()
    ->getPage()
    ->clickLink('Add');
  $this
    ->getSession()
    ->getPage()
    ->pressButton('Save');
  $this
    ->assertSession()
    ->pageTextContains('Saved the Produit de test de traduction variation.');
}