public function TranslationCartAddResourceTest::setUp in Commerce Cart API 8
Overrides CartResourceTestBase::setUp
File
- tests/
src/ Functional/ TranslationCartAddResourceTest.php, line 34
Class
- TranslationCartAddResourceTest
- Tests the cart add resource.
Namespace
Drupal\Tests\commerce_cart_api\FunctionalCode
public function setUp() {
parent::setUp();
$this
->setUpAuthorization('POST');
// Add a new language.
ConfigurableLanguage::createFromLangcode('fr')
->save();
// Enable translation for the product and ensure the change is picked up.
$this->container
->get('content_translation.manager')
->setEnabled('commerce_product', $this->variation
->bundle(), TRUE);
$this->container
->get('content_translation.manager')
->setEnabled('commerce_product_variation', $this->variation
->bundle(), TRUE);
$this->container
->get('entity_type.manager')
->clearCachedDefinitions();
$this->container
->get('router.builder')
->rebuild();
// Rebuild the container so that the new languages are picked up by services
// that hold a list of languages.
$this
->rebuildContainer();
// Reload the variation since we have new fields.
$this->variation = ProductVariation::load($this->variation
->id());
$this->variation_2 = ProductVariation::load($this->variation_2
->id());
// Translate the product's title.
$product = $this->variation
->getProduct();
$product
->setTitle('My Super Product');
$product
->addTranslation('fr', [
'title' => 'Mon super produit',
]);
$product
->save();
// Create a translation for each variation on the product.
$this->variation
->addTranslation('fr')
->save();
$this->variation
->save();
$this->variation_2
->addTranslation('fr')
->save();
$this->variation_2
->save();
}