public function PromotionOrderProcessorTest::testAdjustmentsTranslation in Commerce Core 8.2
Tests that promotion adjustments are correctly translated.
File
- modules/
promotion/ tests/ src/ Kernel/ PromotionOrderProcessorTest.php, line 263
Class
- PromotionOrderProcessorTest
- Tests the promotion order processor.
Namespace
Drupal\Tests\commerce_promotion\KernelCode
public function testAdjustmentsTranslation() {
// Use addOrderItem so the total is calculated.
$order_item = OrderItem::create([
'type' => 'test',
'quantity' => 2,
'unit_price' => [
'number' => '20.00',
'currency_code' => 'USD',
],
]);
$order_item
->save();
$this->order
->setRefreshState(Order::REFRESH_SKIP);
$this->order
->addItem($order_item);
$this->order
->save();
// Starts now, enabled. No end time.
$promotion = Promotion::create([
'name' => 'Promotion 1',
'display_name' => 'Promotion EN',
'order_types' => [
$this->order
->bundle(),
],
'stores' => [
$this->store
->id(),
],
'status' => TRUE,
'offer' => [
'target_plugin_id' => 'order_percentage_off',
'target_plugin_configuration' => [
'percentage' => '0.10',
],
],
]);
$promotion
->save();
$this
->assertTrue($promotion
->applies($this->order));
$this->container
->get('commerce_order.order_refresh')
->refresh($this->order);
$adjustments = $this->order
->collectAdjustments();
$this
->assertEquals(1, count($adjustments));
$this
->assertEquals('Promotion EN', $adjustments[0]
->getLabel());
$this->container
->get('content_translation.manager')
->setEnabled('commerce_promotion', 'default', TRUE);
$this
->changeActiveLanguage('fr');
$promotion
->addTranslation('fr', [
'display_name' => 'Promotion FR',
]);
$promotion
->save();
$this->container
->get('commerce_order.order_refresh')
->refresh($this->order);
$adjustments = $this->order
->collectAdjustments();
$this
->assertEquals(1, count($adjustments));
$this
->assertEquals('Promotion FR', $adjustments[0]
->getLabel());
// Test that a promotion with coupons is correctly translated as well.
$coupon = Coupon::create([
'code' => $this
->randomString(),
'promotion_id' => $promotion
->id(),
'status' => TRUE,
]);
$coupon
->save();
$this->container
->get('commerce_order.order_refresh')
->refresh($this->order);
$this
->assertEquals(0, count($this->order
->collectAdjustments()));
$this->order
->get('coupons')
->appendItem($coupon);
$this->order
->save();
$this->container
->get('commerce_order.order_refresh')
->refresh($this->order);
$adjustments = $this->order
->collectAdjustments();
$this
->assertEquals(1, count($adjustments));
$this
->assertEquals('Promotion FR', $adjustments[0]
->getLabel());
$this
->changeActiveLanguage('en');
$this->container
->get('commerce_order.order_refresh')
->refresh($this->order);
$adjustments = $this->order
->collectAdjustments();
$this
->assertEquals(1, count($adjustments));
$this
->assertEquals('Promotion EN', $adjustments[0]
->getLabel());
}