You are here

public function PromotionTest::testCreatePromotionWithSaveAndAddCoupons in Commerce Core 8.2

Tests creating a promotion using the "Save and add coupons" button.

File

modules/promotion/tests/src/FunctionalJavascript/PromotionTest.php, line 219

Class

PromotionTest
Tests the admin UI for promotions.

Namespace

Drupal\Tests\commerce_promotion\FunctionalJavascript

Code

public function testCreatePromotionWithSaveAndAddCoupons() {
  $this
    ->drupalGet('admin/commerce/promotions');
  $this
    ->getSession()
    ->getPage()
    ->clickLink('Add promotion');
  $name = $this
    ->randomString();
  $this
    ->getSession()
    ->getPage()
    ->fillField('name[0][value]', $name);
  $this
    ->getSession()
    ->getPage()
    ->selectFieldOption('offer[0][target_plugin_id]', 'order_item_fixed_amount_off');
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $this
    ->getSession()
    ->getPage()
    ->fillField('offer[0][target_plugin_configuration][order_item_fixed_amount_off][amount][number]', '10.00');
  $this
    ->submitForm([], t('Save and add coupons'));
  $this
    ->assertSession()
    ->pageTextContains("Saved the {$name} promotion.");

  /** @var \Drupal\commerce_promotion\Entity\PromotionInterface $promotion */
  $promotion = Promotion::load(1);
  $offer = $promotion
    ->getOffer();
  $this
    ->assertEquals('order_item_fixed_amount_off', $offer
    ->getPluginId());
  $this
    ->assertEquals('10.00', $offer
    ->getConfiguration()['amount']['number']);
}