You are here

public function CouponTest::testEditCoupon in Commerce Core 8.2

Tests editing a coupon.

File

modules/promotion/tests/src/Functional/CouponTest.php, line 94

Class

CouponTest
Tests the admin UI for coupons.

Namespace

Drupal\Tests\commerce_promotion\Functional

Code

public function testEditCoupon() {
  $coupon = $this
    ->createEntity('commerce_promotion_coupon', [
    'promotion_id' => $this->promotion
      ->id(),
    'code' => $this
      ->randomMachineName(8),
    'status' => TRUE,
  ]);
  $this
    ->drupalGet($coupon
    ->toUrl('edit-form'));
  $new_code = $this
    ->randomMachineName(8);
  $edit = [
    'code[0][value]' => $new_code,
  ];
  $this
    ->submitForm($edit, 'Save');
  $this->container
    ->get('entity_type.manager')
    ->getStorage('commerce_promotion_coupon')
    ->resetCache([
    $coupon
      ->id(),
  ]);
  $coupon = Coupon::load($coupon
    ->id());
  $this
    ->assertEquals($new_code, $coupon
    ->getCode());
}