You are here

public function PromotionAvailabilityTest::testUsageCount in Commerce Core 8.2

Tests the usage count logic.

File

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

Class

PromotionAvailabilityTest
Tests the promotion availability logic.

Namespace

Drupal\Tests\commerce_promotion\Kernel

Code

public function testUsageCount() {
  $promotion = Promotion::create([
    'order_types' => [
      'default',
    ],
    'stores' => [
      $this->store
        ->id(),
    ],
    'usage_limit' => 2,
    'usage_limit_customer' => 0,
    'start_date' => '2019-01-01T00:00:00',
    'status' => TRUE,
  ]);
  $promotion
    ->save();
  $this
    ->assertTrue($promotion
    ->available($this->order));
  $this->container
    ->get('commerce_promotion.usage')
    ->register($this->order, $promotion);
  $this
    ->assertTrue($promotion
    ->available($this->order));
  $this->container
    ->get('commerce_promotion.usage')
    ->register($this->order, $promotion);
  $this
    ->assertFalse($promotion
    ->available($this->order));
}