PromotionMultilingualTest.php in Commerce Core 8.2
File
modules/promotion/tests/src/Kernel/PromotionMultilingualTest.php
View source
<?php
namespace Drupal\Tests\commerce_promotion\Kernel;
use Drupal\commerce_promotion\Entity\Promotion;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\Tests\commerce_order\Kernel\OrderKernelTestBase;
class PromotionMultilingualTest extends OrderKernelTestBase {
public static $modules = [
'commerce_promotion',
'language',
'content_translation',
];
protected function setUp() : void {
parent::setUp();
$this
->installEntitySchema('commerce_promotion');
ConfigurableLanguage::createFromLangcode('fr')
->save();
ConfigurableLanguage::createFromLangcode('sr')
->save();
}
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();
$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());
$this
->config('system.site')
->set('default_langcode', 'sr')
->save();
$stores = $promotion
->getStores();
$this
->assertEquals('Default store', reset($stores)
->label());
}
}