public function ProductMultilingualTest::testProductStoresTranslated in Commerce Core 8.2
Tests that the products's stores are translated to specified language.
File
- modules/
product/ tests/ src/ Kernel/ ProductMultilingualTest.php, line 51
Class
- ProductMultilingualTest
- Tests the product and variation entity in a multilingual context.
Namespace
Drupal\Tests\commerce_product\KernelCode
public function testProductStoresTranslated() {
$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();
$this->container
->get('content_translation.manager')
->setEnabled('commerce_product', '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' => 'Мој супер производ',
]);
$stores = $product
->getStores();
$this
->assertEquals('Default store', reset($stores)
->label());
$stores = $product
->getTranslation('fr')
->getStores();
$this
->assertEquals('Magasin par défaut', reset($stores)
->label());
$stores = $product
->getTranslation('en')
->getStores();
$this
->assertEquals('Default store', reset($stores)
->label());
$stores = $product
->getTranslation('sr')
->getStores();
$this
->assertEquals('Default store', reset($stores)
->label());
}