You are here

protected function CouponRedemptionElementTest::setUp in Commerce Core 8.2

Overrides CommerceWebDriverTestBase::setUp

File

modules/promotion/tests/src/FunctionalJavascript/CouponRedemptionElementTest.php, line 54

Class

CouponRedemptionElementTest
Tests the coupon redemption form element.

Namespace

Drupal\Tests\commerce_promotion\FunctionalJavascript

Code

protected function setUp() : void {
  parent::setUp();
  $this->cart = $this->container
    ->get('commerce_cart.cart_provider')
    ->createCart('default', $this->store, $this->adminUser);
  $this->cartManager = $this->container
    ->get('commerce_cart.cart_manager');
  OrderItemType::create([
    'id' => 'test',
    'label' => 'Test',
    'orderType' => 'default',
  ])
    ->save();
  $order_item = OrderItem::create([
    'type' => 'test',
    'quantity' => 1,
    'unit_price' => new Price('12.00', 'USD'),
  ]);
  $order_item
    ->save();
  $this->cartManager
    ->addOrderItem($this->cart, $order_item);

  // Starts now, enabled. No end time.
  $this->promotion = $this
    ->createEntity('commerce_promotion', [
    'name' => 'Promotion (with coupon)',
    'order_types' => [
      'default',
    ],
    'stores' => [
      $this->store
        ->id(),
    ],
    'status' => TRUE,
    'offer' => [
      'target_plugin_id' => 'order_percentage_off',
      'target_plugin_configuration' => [
        'percentage' => '0.10',
      ],
    ],
    'start_date' => '2017-01-01',
    'conditions' => [],
  ]);
  $first_coupon = $this
    ->createEntity('commerce_promotion_coupon', [
    'code' => $this
      ->getRandomGenerator()
      ->word(8),
    'status' => TRUE,
  ]);
  $first_coupon
    ->save();
  $second_coupon = $this
    ->createEntity('commerce_promotion_coupon', [
    'code' => $this
      ->getRandomGenerator()
      ->word(8),
    'status' => TRUE,
  ]);
  $second_coupon
    ->save();
  $this->promotion
    ->setCoupons([
    $first_coupon,
    $second_coupon,
  ]);
  $this->promotion
    ->save();
}