public function PromotionMultilingualTest::testPromotionStores in Commerce Core 8.2
Tests that a promotion returns stores in current language.
File
- modules/
promotion/ tests/ src/ Kernel/ PromotionMultilingualTest.php, line 41
Class
- PromotionMultilingualTest
- Tests promotions in a multilingual context.
Namespace
Drupal\Tests\commerce_promotion\KernelCode
public function testPromotionStores() {
$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();
// Starts now, enabled. No end time.
$promotion = Promotion::create([
'name' => 'Promotion 1',
'order_types' => 'default',
'stores' => [
$this->store
->id(),
],
'status' => TRUE,
]);
$stores = $promotion
->getStores();
$this
->assertEquals('Default store', reset($stores)
->label());
$this
->config('system.site')
->set('default_langcode', 'fr')
->save();
$stores = $promotion
->getStores();
$this
->assertEquals('Magasin par défaut', reset($stores)
->label());
// Change the default site language and ensure the store is returned
// even if it has not been translated to that language.
$this
->config('system.site')
->set('default_langcode', 'sr')
->save();
$stores = $promotion
->getStores();
$this
->assertEquals('Default store', reset($stores)
->label());
}