You are here

protected function CouponCodeGeneratorTest::setUp in Commerce Core 8.2

Overrides OrderKernelTestBase::setUp

File

modules/promotion/tests/src/Kernel/CouponCodeGeneratorTest.php, line 45

Class

CouponCodeGeneratorTest
Tests the coupon code generator.

Namespace

Drupal\Tests\commerce_promotion\Kernel

Code

protected function setUp() : void {
  parent::setUp();
  $this
    ->installEntitySchema('commerce_promotion');
  $this
    ->installEntitySchema('commerce_promotion_coupon');
  $this
    ->installSchema('commerce_promotion', [
    'commerce_promotion_usage',
  ]);
  $this
    ->installConfig([
    'commerce_order',
  ]);
  $promotion = Promotion::create([
    'name' => 'Promotion 1',
    'order_types' => [
      'default',
    ],
    'stores' => [
      $this->store
        ->id(),
    ],
    'status' => TRUE,
    'offer' => [
      'target_plugin_id' => 'order_item_percentage_off',
      'target_plugin_configuration' => [
        'percentage' => '0.5',
      ],
    ],
  ]);
  $promotion
    ->save();
  $this->numericCoupons = [];
  for ($i = 0; $i < 10; $i++) {
    $coupon = Coupon::create([
      'promotion_id' => $promotion
        ->id(),
      'code' => 'COUPON' . $i,
      'usage_limit' => 1,
      'usage_limit_customer' => 1,
      'status' => 1,
    ]);
    $coupon
      ->save();
    $this->numericCoupons[] = $coupon;
  }
  $this->couponCodeGenerator = $this->container
    ->get('commerce_promotion.coupon_code_generator');
}