You are here

public function Select2BoxesTests::testWidgetsAdminExistence in Select2 Boxes 8

Check whether all widgets exist in the field widgets settings.

File

tests/src/FunctionalJavascript/Select2BoxesTests.php, line 44

Class

Select2BoxesTests
Class for testing Select2Boxes.

Namespace

Drupal\Tests\select2boxes\FunctionalJavascript

Code

public function testWidgetsAdminExistence() {
  $page = $this
    ->getSession()
    ->getPage();
  $assert_session = $this
    ->assertSession();

  // Go the the "Manage Form Display" form.
  $this
    ->drupalGet('admin/structure/types/manage/select2boxes_test_content_type/form-display');

  // Check for entity reference field widgets.
  $page
    ->hasSelect('edit-fields-field-tags-type');
  $assert_session
    ->optionExists('edit-fields-field-tags-type', static::$pluginIds[1]);
  $assert_session
    ->optionExists('edit-fields-field-tags-type', static::$pluginIds[2]);

  // Check if the newly created field exists in the list.
  $page
    ->hasSelect('edit-fields-field-test-list-type');

  // Check for list field widgets.
  $assert_session
    ->optionExists('edit-fields-field-test-list-type', static::$pluginIds[0]);

  // Set the Select2Boxes widgets for both fields and submit the form.
  $assert_session
    ->elementExists('xpath', '//select[@name="fields[field_test_list][type]"]')
    ->setValue(static::$pluginIds[0]);
  $assert_session
    ->assertWaitOnAjaxRequest();
  $assert_session
    ->elementExists('xpath', '//select[@name="fields[field_tags][type]"]')
    ->setValue(static::$pluginIds[1]);
  $assert_session
    ->assertWaitOnAjaxRequest();
  $page
    ->pressButton('Save');

  // Check if the submission has been successful.
  $this
    ->assertSession()
    ->pageTextContains('Your settings have been saved.');
}