public function ProductMultilingualTest::testDefaultVariationTranslated in Commerce Core 8.2
Tests that the product's default variation returned in specified language.
File
- modules/
product/ tests/ src/ Kernel/ ProductMultilingualTest.php, line 152
Class
- ProductMultilingualTest
- Tests the product and variation entity in a multilingual context.
Namespace
Drupal\Tests\commerce_product\KernelCode
public function testDefaultVariationTranslated() {
$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',
]);
$product
->addTranslation('sr', [
'title' => 'Мој супер производ',
]);
$variation1 = ProductVariation::create([
'type' => 'default',
'title' => 'Version one',
]);
$variation1
->addTranslation('fr', [
'title' => 'Version une',
]);
$product
->addVariation($variation1);
$variation2 = ProductVariation::create([
'type' => 'default',
'title' => 'Version two',
]);
$variation2
->addTranslation('fr', [
'title' => 'Version deux',
]);
$product
->addVariation($variation2);
$this
->assertEquals('Version one', $product
->getDefaultVariation()
->label());
$this
->assertEquals('Version une', $product
->getTranslation('fr')
->getDefaultVariation()
->label());
$this
->assertEquals('Version one', $product
->getTranslation('en')
->getDefaultVariation()
->label());
$this
->assertEquals('Version one', $product
->getTranslation('sr')
->getDefaultVariation()
->label());
}