You are here

public function LicenseAdminTest::testVariationTypeEdit in Commerce License 8.2

Tests editing a variation type.

File

tests/src/Functional/LicenseAdminTest.php, line 37

Class

LicenseAdminTest
Tests our traits validation logic, submission.

Namespace

Drupal\Tests\commerce_license\Functional

Code

public function testVariationTypeEdit() {

  /** @var \Drupal\commerce_product\Entity\ProductVariationTypeInterface $product_variation_type */
  $product_variation_type = ProductVariationType::load('default');
  $this
    ->drupalGet($product_variation_type
    ->toUrl('edit-form'));
  $this
    ->getSession()
    ->getPage()
    ->checkField('traits[commerce_license]');
  $this
    ->submitForm([], 'Save');

  /** @var \Drupal\commerce_order\Entity\OrderItemTypeInterface $order_item_type */
  $order_item_type = OrderItemType::load('default');
  $this
    ->assertTrue($order_item_type
    ->hasTrait('commerce_license_order_item_type'));
  $this
    ->assertSession()
    ->pageTextContains('The License trait requires an order item type with the order item license trait, it was automatically installed for your convenience.');
  $product_variation_type = $this
    ->reloadEntity($product_variation_type);
  $third_party_settings = $product_variation_type
    ->getThirdPartySettings('commerce_license');
  $this
    ->assertNotEmpty($third_party_settings);
  $this
    ->assertArrayHasKey('license_types', $third_party_settings);
  $this
    ->assertArrayHasKey('activate_on_place', $third_party_settings);

  // Ensure the license third party settings are correctly cleaned up.
  $this
    ->drupalGet($product_variation_type
    ->toUrl('edit-form'));
  $this
    ->getSession()
    ->getPage()
    ->uncheckField('traits[commerce_license]');
  $this
    ->submitForm([], 'Save');
  $product_variation_type = $this
    ->reloadEntity($product_variation_type);
  $this
    ->assertEmpty($product_variation_type
    ->getThirdPartySettings('commerce_license'));
}