You are here

public function AppSettingsFormTest::testAppSettingsForm in Apigee Edge 8

Tests the app settings AJAX form.

File

tests/src/FunctionalJavascript/AppSettingsFormTest.php, line 64

Class

AppSettingsFormTest
App settings form Javascript tests.

Namespace

Drupal\Tests\apigee_edge\FunctionalJavascript

Code

public function testAppSettingsForm() {
  $web_assert = $this
    ->assertSession();
  $this
    ->drupalLogin($this->rootUser);

  // Visit the app settings form using invalid API credentials.
  $this
    ->invalidateKey();
  $this
    ->drupalGet(Url::fromRoute('apigee_edge.settings.general_app'));
  $this
    ->assertSession()
    ->pageTextContains('Unable to retrieve API product list from Apigee Edge. Please ensure that Apigee Edge connection settings are correct.');

  // Visit the app settings form using valid API credentials.
  $this
    ->restoreKey();
  $this
    ->drupalGet(Url::fromRoute('apigee_edge.settings.general_app'));
  $this
    ->assertSession()
    ->pageTextNotContains('Unable to retrieve API product list from Apigee Edge. Please ensure that Apigee Edge connection settings are correct.');

  // Selecting default API product is not required by default.
  $product_list = $this
    ->getSession()
    ->getPage()
    ->find('css', '#default-api-product-multiple fieldset');
  $this
    ->assertFalse($product_list
    ->hasAttribute('required'));
  $this
    ->getSession()
    ->getPage()
    ->pressButton('edit-submit');
  $this
    ->assertSession()
    ->pageTextContains('The configuration options have been saved.');

  // Selecting default API product is required.
  $this
    ->getSession()
    ->getPage()
    ->uncheckField('edit-user-select');
  $web_assert
    ->assertWaitOnAjaxRequest();
  $this
    ->createScreenshot("AppSettingsFormTest-" . __FUNCTION__);
  $product_list = $this
    ->getSession()
    ->getPage()
    ->find('css', '#default-api-product-multiple fieldset');
  $this
    ->assertTrue($product_list
    ->hasClass('required'));
  $this
    ->getSession()
    ->getPage()
    ->pressButton('edit-submit');
  $this
    ->assertSession()
    ->pageTextContains('Default API Products field is required.');
  $this
    ->getSession()
    ->getPage()
    ->checkField("default_api_product_multiple[{$this->defaultApiProduct->getName()}]");
  $this
    ->getSession()
    ->getPage()
    ->pressButton('edit-submit');
  $this
    ->assertSession()
    ->pageTextContains('The configuration options have been saved.');

  // Selecting default API product is not required.
  $this
    ->getSession()
    ->getPage()
    ->checkField('edit-user-select');
  $web_assert
    ->assertWaitOnAjaxRequest();
  $this
    ->createScreenshot("AppSettingsFormTest-" . __FUNCTION__);
  $product_list = $this
    ->getSession()
    ->getPage()
    ->find('css', '#default-api-product-multiple fieldset');
  $this
    ->assertFalse($product_list
    ->hasAttribute('required'));
  $this
    ->getSession()
    ->getPage()
    ->uncheckField("default_api_product_multiple[{$this->defaultApiProduct->getName()}]");
  $this
    ->getSession()
    ->getPage()
    ->pressButton('edit-submit');
  $this
    ->assertSession()
    ->pageTextContains('The configuration options have been saved.');
}