You are here

public function PromotionStorageTest::testValidWithCoupons in Commerce Core 8.2

Tests that promotions with coupons do not get loaded.

File

modules/promotion/tests/src/Kernel/PromotionStorageTest.php, line 217

Class

PromotionStorageTest
Tests promotion storage.

Namespace

Drupal\Tests\commerce_promotion\Kernel

Code

public function testValidWithCoupons() {
  $promotion1 = Promotion::create([
    'name' => 'Promotion 1',
    'order_types' => [
      $this->orderType,
    ],
    'stores' => [
      $this->store
        ->id(),
    ],
    'start_date' => '2019-01-01T00:00:00',
    'status' => TRUE,
  ]);
  $promotion1
    ->save();

  /** @var \Drupal\commerce_promotion\Entity\Promotion $promotion2 */
  $promotion2 = Promotion::create([
    'name' => 'Promotion 2',
    'order_types' => [
      $this->orderType,
    ],
    'stores' => [
      $this->store
        ->id(),
    ],
    'start_date' => '2019-01-01T00:00:00',
    'status' => TRUE,
  ]);
  $promotion2
    ->save();

  // Add a coupon to promotion2 and validate it does not load.
  $coupon = Coupon::create([
    'code' => $this
      ->randomString(),
    'status' => TRUE,
  ]);
  $coupon
    ->save();
  $promotion2
    ->get('coupons')
    ->appendItem($coupon);
  $promotion2
    ->save();
  $promotion2 = $this
    ->reloadEntity($promotion2);
  $promotion3 = Promotion::create([
    'name' => 'Promotion 3',
    'order_types' => [
      $this->orderType,
    ],
    'stores' => [
      $this->store
        ->id(),
    ],
    'start_date' => '2019-01-01T00:00:00',
    'status' => TRUE,
  ]);
  $promotion3
    ->save();
  $promotions = $this->promotionStorage
    ->loadAvailable($this->order);
  $this
    ->assertEquals(2, count($promotions));
}