You are here

public function PromotionAvailabilityTest::testStartDate in Commerce Core 8.2

Tests the start date logic.

File

modules/promotion/tests/src/Kernel/PromotionAvailabilityTest.php, line 100

Class

PromotionAvailabilityTest
Tests the promotion availability logic.

Namespace

Drupal\Tests\commerce_promotion\Kernel

Code

public function testStartDate() {
  $promotion = Promotion::create([
    'order_types' => [
      'default',
    ],
    'stores' => [
      $this->store
        ->id(),
    ],
    'usage_limit' => 1,
    'usage_limit_customer' => 0,
    'status' => TRUE,
  ]);
  $promotion
    ->save();

  // Start date equal to the order placed date.
  $date = new DrupalDateTime('2019-11-15 10:14:00');
  $promotion
    ->setStartDate($date);
  $this
    ->assertTrue($promotion
    ->available($this->order));

  // Past start date.
  $date = new DrupalDateTime('2019-11-10 10:14:00');
  $promotion
    ->setStartDate($date);
  $this
    ->assertTrue($promotion
    ->available($this->order));

  // Future start date.
  $date = new DrupalDateTime('2019-11-20 10:14:00');
  $promotion
    ->setStartDate($date);
  $this
    ->assertFalse($promotion
    ->available($this->order));
}