You are here

public function PromotionAvailabilityTest::testCustomerUsageCount in Commerce Core 8.2

Tests the customer usage count logic.

File

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

Class

PromotionAvailabilityTest
Tests the promotion availability logic.

Namespace

Drupal\Tests\commerce_promotion\Kernel

Code

public function testCustomerUsageCount() {
  $promotion = Promotion::create([
    'order_types' => [
      'default',
    ],
    'stores' => [
      $this->store
        ->id(),
    ],
    'usage_limit' => 0,
    'usage_limit_customer' => 2,
    '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));
}