public function ProductMultilingualTest::testVariationGetProductTranslated in Commerce Core 8.2
Tests that a variation's product is returned in specified language.
File
- modules/
product/ tests/ src/ Kernel/ ProductMultilingualTest.php, line 199
Class
- ProductMultilingualTest
- Tests the product and variation entity in a multilingual context.
Namespace
Drupal\Tests\commerce_product\KernelCode
public function testVariationGetProductTranslated() {
$default_variation_type = ProductVariationType::load('default');
$default_variation_type
->setGenerateTitle(FALSE);
$default_variation_type
->save();
$this->container
->get('content_translation.manager')
->setEnabled('commerce_product', 'default', TRUE);
$this->container
->get('content_translation.manager')
->setEnabled('commerce_product_variation', 'default', TRUE);
$product = Product::create([
'type' => 'default',
'title' => 'My Super Product',
'stores' => [
$this->store,
],
]);
$product
->addTranslation('fr', [
'title' => 'Mon super produit',
]);
$variation1 = ProductVariation::create([
'type' => 'default',
'title' => 'Version one',
'product_id' => $product,
]);
$variation1
->addTranslation('fr', [
'title' => 'Version une',
]);
$variation1
->addTranslation('sr', [
'title' => 'Верзија два',
]);
$product
->addVariation($variation1);
$this
->assertEquals('My Super Product', $variation1
->getProduct()
->label());
$this
->assertEquals('Mon super produit', $variation1
->getTranslation('fr')
->getProduct()
->label());
$this
->assertEquals('My Super Product', $variation1
->getTranslation('en')
->getProduct()
->label());
$this
->assertEquals('My Super Product', $variation1
->getTranslation('sr')
->getProduct()
->label());
}