You are here

public function PromotionOrderProcessorTest::testOrderTotal in Commerce Core 8.2

Tests the order amount condition.

File

modules/promotion/tests/src/Kernel/PromotionOrderProcessorTest.php, line 67

Class

PromotionOrderProcessorTest
Tests the promotion order processor.

Namespace

Drupal\Tests\commerce_promotion\Kernel

Code

public function testOrderTotal() {

  // 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
    ->addItem($order_item);
  $this->order
    ->save();

  // Starts now, enabled. No end time.
  $promotion = Promotion::create([
    'name' => 'Promotion 1',
    'order_types' => [
      $this->order
        ->bundle(),
    ],
    'stores' => [
      $this->store
        ->id(),
    ],
    'status' => TRUE,
    'offer' => [
      'target_plugin_id' => 'order_percentage_off',
      'target_plugin_configuration' => [
        'percentage' => '0.10',
      ],
    ],
    'conditions' => [
      [
        'target_plugin_id' => 'order_total_price',
        'target_plugin_configuration' => [
          'amount' => [
            'number' => '20.00',
            'currency_code' => 'USD',
          ],
        ],
      ],
    ],
  ]);
  $promotion
    ->save();
  $this
    ->assertTrue($promotion
    ->applies($this->order));
  $this->container
    ->get('commerce_order.order_refresh')
    ->refresh($this->order);
  $this->order
    ->recalculateTotalPrice();
  $this
    ->assertEquals(1, count($this->order
    ->collectAdjustments()));
  $this
    ->assertEquals(new Price('36.00', 'USD'), $this->order
    ->getTotalPrice());
}