You are here

public function LicenseAdminTest::testCreateLicense in Commerce License 8.2

Tests creating a license.

File

tests/src/FunctionalJavascript/LicenseAdminTest.php, line 79

Class

LicenseAdminTest
Tests the admin UI for licenses.

Namespace

Drupal\Tests\commerce_license\FunctionalJavascript

Code

public function testCreateLicense() {
  $this
    ->drupalGet('admin/commerce/licenses');
  $this
    ->getSession()
    ->getPage()
    ->clickLink('Add license');

  // Check the integrity of the form.
  $this
    ->assertSession()
    ->fieldExists('product_variation[0][target_id]');
  $this
    ->assertSession()
    ->fieldExists('uid[0][target_id]');
  $this
    ->assertSession()
    ->fieldExists('expiration_type[0][target_plugin_id]');
  $this
    ->assertSession()
    ->fieldExists('license_role');
  $this
    ->getSession()
    ->getPage()
    ->selectFieldOption('expiration_type[0][target_plugin_id]', 'rolling_interval');
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $this
    ->getSession()
    ->getPage()
    ->fillField('expiration_type[0][target_plugin_configuration][rolling_interval][interval][interval]', 30);
  $this
    ->getSession()
    ->getPage()
    ->selectFieldOption('expiration_type[0][target_plugin_configuration][rolling_interval][interval][period]', 'day');
  $this
    ->assertSession()
    ->optionNotExists('license_role', RoleInterface::AUTHENTICATED_ID);
  $this
    ->assertSession()
    ->optionNotExists('license_role', RoleInterface::ANONYMOUS_ID);
  $this
    ->getSession()
    ->getPage()
    ->fillField('product_variation[0][target_id]', $this->variation
    ->getSku() . ' (' . $this->variation
    ->id() . ')');
  $roles = $this->adminUser
    ->getRoles(TRUE);
  $this
    ->getSession()
    ->getPage()
    ->selectFieldOption('license_role', reset($roles));
  $this
    ->submitForm([], t('Save'));

  /** @var \Drupal\commerce_license\Entity\LicenseInterface $license */
  $license = $this->container
    ->get('entity_type.manager')
    ->getStorage('commerce_license')
    ->load(1);
  $this
    ->assertEquals('role', $license
    ->bundle());
  $this
    ->assertEquals($this->variation
    ->id(), $license
    ->getPurchasedEntity()
    ->id());
  $this
    ->assertEquals('new', $license
    ->getState()
    ->getId());
  $this
    ->assertEquals('rolling_interval', $license
    ->getExpirationPluginType());
  $this
    ->assertEquals([
    'interval' => [
      'interval' => '30',
      'period' => 'day',
    ],
  ], $license
    ->get('expiration_type')->target_plugin_configuration);
}