You are here

abstract class ContentEntityAutosaveFormTestBase in Autosave Form 8

Base test class for testing autosave support for entity forms.

Hierarchy

Expanded class hierarchy of ContentEntityAutosaveFormTestBase

File

tests/src/FunctionalJavascript/ContentEntity/ContentEntityAutosaveFormTestBase.php, line 16

Namespace

Drupal\Tests\autosave_form\FunctionalJavascript\ContentEntity
View source
abstract class ContentEntityAutosaveFormTestBase extends AutosaveFormTestBase {

  /**
   * The entity type to be tested.
   *
   * @var string
   */
  protected $entityType;

  /**
   * The bundle of the entity type to be tested.
   *
   * @var string
   */
  protected $bundle;

  /**
   * The original entity title.
   *
   * @var string
   */
  protected $originalEntityTitle;

  /**
   * The changed entity title.
   *
   * @var string
   */
  protected $changedEntityTitle;

  /**
   * The name of the field with unlimited cardinality to test ajax requests.
   *
   * @var string
   */
  protected $unlimitedCardinalityField = 'autosave_unlimited_field';

  /**
   * The name of the required test field.
   *
   * @var string
   */
  protected $requiredField = 'autosave_required_field';

  /**
   * Count of the changes to make.
   *
   * @var int
   */
  protected $testAutosaveFormExistingEntityChangesCount = 5;

  /**
   * {@inheritdoc}
   */
  protected function prepareSetUp() {
    $this
      ->createMultipleTestField();
    $this
      ->createRequiredTestField();
    parent::prepareSetUp();
    $this->originalEntityTitle = NULL;
    $this->changedEntityTitle = NULL;
  }

  /**
   * Tests autosave.
   */
  public function testAutosaveForms() {

    // It looks like phantomjs is crashing if an ajax autosave form request is
    // still running when we go the next test and visit the entity form of
    // different entity in which case the currently running ajax autosave form
    // request will be aborted. In order to prevent this crash we re-log the
    // user prior to each test.
    $this
      ->doTestAutosaveFormNewEntity();
    $this
      ->relogUser();
    $this
      ->doTestAutosaveFormExistingEntity();
    $this
      ->relogUser();
    $this
      ->doTestSavingRestoredEntityForm();
    $this
      ->relogUser();
    $this
      ->doTestConcurrentEditing();
    $this
      ->relogUser();
    $this
      ->doTestAutosaveAfterFormValidationFail();
    $this
      ->relogUser();
    $this
      ->doTestAutosaveStatesPurgingOnConfigEvent();
  }

  /**
   * Tests that the autosave form library is not loaded on new entity forms.
   */
  protected function doTestAutosaveFormNewEntity() {
    $this
      ->drupalGet($this
      ->getCreateNewEntityURL());
    $this
      ->assertAutosaveFormLibraryLoaded(FALSE);
  }

  /**
   * Tests the autosave support on entity forms.
   */
  protected function doTestAutosaveFormExistingEntity() {
    $entity = $this
      ->createTestEntity();
    $entity_id = $entity
      ->id();
    $entity_form_edit_url = $entity
      ->toUrl('edit-form');
    $this
      ->drupalGet($entity_form_edit_url);
    $this
      ->assertAutosaveFormLibraryLoaded(TRUE);
    $this
      ->assertOriginalEntityTitleAsPageTitle();

    // Wait for at least having two autosave submits being executed and assert
    // that with no changes there will be no autosave states created.
    $this
      ->assertTrue($this
      ->waitForAutosaveSubmits(2));
    $this
      ->assertEquals(0, $this
      ->getCountAutosaveEntries($entity_id));
    $latest_autosave_timestamp_per_change = $this
      ->makeAllEntityFormChanges($entity_id);

    // Test the autosave restore of each change.
    for ($change_id = $this->testAutosaveFormExistingEntityChangesCount; $change_id > 0; $change_id--) {

      // Reload page otherwise new auto saves will be done and time checks get incorrect
      $this
        ->drupalGet($entity_form_edit_url);
      if (($last_autosave_timestamp = $this
        ->getLastAutosaveTimestamp($entity_id)) && $last_autosave_timestamp > $latest_autosave_timestamp_per_change[$change_id]) {
        $delete_timestamps = range($latest_autosave_timestamp_per_change[$change_id] + 1, $last_autosave_timestamp);
        $this
          ->deleteAutosavedStates($delete_timestamps);
      }
      $this
        ->reloadPageAndRestore($entity_form_edit_url, $this
        ->getLastAutosaveTimestamp($entity_id));
      $this
        ->assertCorrectlyRestoredEntityFormState($change_id);
    }
  }

  /**
   * Tests saving an entity form restored from an autosaved state.
   */
  protected function doTestSavingRestoredEntityForm() {
    $entity = $this
      ->createTestEntity();
    $entity_form_edit_url = $entity
      ->toUrl('edit-form');
    $this
      ->drupalGet($entity_form_edit_url);
    $this
      ->makeAllEntityFormChanges($entity
      ->id());

    // Assure that an autosave submission has run.
    $this
      ->assertTrue($this
      ->waitForAutosaveSubmits(1));
    $this
      ->reloadPageAndRestore($entity_form_edit_url, $this
      ->getLastAutosaveTimestamp($entity
      ->id()));
    $this
      ->saveForm();
    $this
      ->finalizeTestSavingRestoredEntityForm($entity
      ->id());
  }

  /**
   * Submits the current form.
   */
  protected function saveForm() {
    $this
      ->drupalPostForm(NULL, [], t('Save'));
  }

  /**
   * Tests concurrent editing.
   */
  protected function doTestConcurrentEditing() {
    $entity = $this
      ->createTestEntity();

    // This test supports only entities implementing the entity changed
    // interface.
    if (!$entity instanceof EntityChangedInterface) {
      return;
    }

    // Make one change and assert that an autosave entry has been created for
    // it.
    $entity_form_edit_url = $entity
      ->toUrl('edit-form');
    $this
      ->drupalGet($entity_form_edit_url);
    $this
      ->assertTrue($this
      ->waitForAutosaveSubmits(1));
    $this
      ->makeEntityFormChange(1);
    $this
      ->assertTrue($this
      ->waitForAutosaveSubmits(2));
    $this
      ->assertTrue($this
      ->getCountAutosaveEntries($entity
      ->id()) > 0);
    $this
      ->assertAutosaveIsRunning(TRUE);

    // Meanwhile simulate saving by another user in the background.
    $entity
      ->setChangedTime($entity
      ->getChangedTime() + 1)
      ->save();

    // Ensure that after the entity is being saved in the background the
    // autosave submission is disabled by expecting maximum of one autosave
    // submission which will show the alert message on the page. If when the
    // following code is executed the autosave submission has not yet run then
    // there will be one autosave submission and afterwards autosave submission
    // should be disabled. If however when the following code is executed the
    // autosave submission has already run then autosave submission should have
    // been disabled already. In both cases we assert that we expect zero or
    // one autosave submission, but not more than one.
    $this
      ->assertFalse($this
      ->waitForAutosaveSubmits(2));
    $this
      ->assertAutosaveIsRunning(FALSE);
    $this
      ->assertEquals(0, $this
      ->getCountAutosaveEntries($entity
      ->id()));
    $message = $this
      ->config('autosave_form.messages')
      ->get('entity_saved_in_background_alert_message');
    $this
      ->assertSession()
      ->responseContains($message);
  }

  /**
   * Tests the autosave message not being shown on reload after validation fail.
   */
  protected function doTestAutosaveAfterFormValidationFail() {

    // Create a test entity and ensure that the required field is not filled in
    // order to trigger a validation error on entity form submission.
    $entity = $this
      ->createTestEntity();

    // Disable the HTML5 validation as it prevents the form submission when a
    // required field is empty, which however we want to do on purpose to test
    // how autosave_form behaves when a form is returned with validation errors,
    // but for that it has to be submitted first.
    \Drupal::state()
      ->set('disable_html5_validation', TRUE);
    $entity_form_edit_url = $entity
      ->toUrl('edit-form');
    $this
      ->drupalGet($entity_form_edit_url);

    // Assure that the initial autosave submission for gathering initial input
    // has run.
    $this
      ->assertTrue($this
      ->waitForAutosaveSubmits(1));

    // Make the first change to trigger an autosave state creation, but do not
    // fill the required field.
    $this
      ->alterTitleField();

    // Ensure a validation fail will occur.
    $this
      ->emptyRequiredFieldTestAutosaveAfterFormValidationFail();

    // Ensure an autosave state is saved.
    $this
      ->assertTrue($this
      ->waitForAutosaveSubmits(2));
    $before_submission_autosave_entries = $this
      ->getCountAutosaveEntries($entity
      ->id());
    $this
      ->assertTrue($before_submission_autosave_entries > 0);

    // Submit the form.
    $this
      ->saveForm();

    // Do not prevent the HTML5 validation anymore.
    \Drupal::state()
      ->delete('disable_html5_validation');
    $this
      ->logHtmlOutput(__FUNCTION__ . ' after validation fail.');

    // Ensure the validation fail message is shown.
    $error_messages = $this
      ->getSession()
      ->getPage()
      ->find('css', '.messages--error');
    $this
      ->assertNotNull($error_messages);

    // Ensure that the autosave resume/discard message is not shown.
    $this
      ->assertAutosaveResumeDiscardMessageIsShown(FALSE, $this
      ->getLastAutosaveTimestamp($entity
      ->id()));

    // Ensure that autosave submissions are running.
    $this
      ->assertTrue($this
      ->waitForAutosaveSubmits(2));

    // Ensure no further autosave states are being created without changes.
    $this
      ->assertEquals($before_submission_autosave_entries, $this
      ->getCountAutosaveEntries($entity
      ->id()));
  }

  /**
   * Tests that autosave states are purged on modifying a form related config.
   */
  protected function doTestAutosaveStatesPurgingOnConfigEvent() {
    $entity = $this
      ->createTestEntity();
    $entity_id = $entity
      ->id();
    $entity_form_edit_url = $entity
      ->toUrl('edit-form');
    $create_autosave_state = function () use ($entity_form_edit_url, $entity_id) {
      $this
        ->drupalGet($entity_form_edit_url);

      // Wait for at least having two autosave submits being executed, make a
      // change wait for two more autosave submits and ensure an autosave state
      // has been created.
      $this
        ->assertTrue($this
        ->waitForAutosaveSubmits(2));
      $this
        ->makeEntityFormChange(1);
      $this
        ->assertTrue($this
        ->waitForAutosaveSubmits(2));
      $this
        ->assertEquals(1, $this
        ->getCountAutosaveEntries($entity_id));
    };

    // Make a non-significant modification on a form related config and ensure
    // that the autosave state hasn't been purged.
    $create_autosave_state();
    $field_config = FieldConfig::loadByName($this->entityType, $this->bundle, $this->unlimitedCardinalityField);
    $field_config
      ->setLabel('New Label Test AutosaveState Purge')
      ->save();
    $this
      ->assertEquals(1, $this
      ->getCountAutosaveEntries($entity_id));

    // Modify a form related config and ensure that the autosave state has been
    // purged.
    $field_storage = FieldStorageConfig::loadByName($this->entityType, $this->unlimitedCardinalityField);
    $field_storage
      ->setCardinality(10)
      ->save();
    $this
      ->assertEquals(0, $this
      ->getCountAutosaveEntries($entity_id));

    // Delete a form related config and ensure that the autosave state has been
    // purged.
    $create_autosave_state();
    $field_storage = FieldStorageConfig::loadByName($this->entityType, $this->unlimitedCardinalityField);
    $field_storage
      ->delete();
    $this
      ->assertEquals(0, $this
      ->getCountAutosaveEntries($entity_id));

    // Create a form related config and ensure that the autosave state has been
    // purged.
    $create_autosave_state();
    $this
      ->createMultipleTestField();
    $this
      ->assertEquals(0, $this
      ->getCountAutosaveEntries($entity_id));
  }

  /**
   * Empties a required field.
   *
   * Helper method for ::doTestAutosaveAfterFormValidationFail() to empty a
   * required field on the entity form in order to trigger a form validation
   * fail on form submission.
   */
  protected function emptyRequiredFieldTestAutosaveAfterFormValidationFail() {
    $this
      ->fillTestField($this->requiredField, 0, '');
  }

  /**
   * Tests correctly saved entity after autosave restore.
   *
   * Helper method for ::doTestSavingRestoredEntityForm() to test the saved
   * entity.
   *
   * @param mixed $entity_id
   *   The ID of the entity.
   */
  protected function finalizeTestSavingRestoredEntityForm($entity_id) {
    $entity = $this
      ->reloadEntity($entity_id);

    // Change 1.
    $this
      ->assertEquals($entity
      ->label(), $this->changedEntityTitle);

    // Changes 2, 3 and 4.
    $this
      ->assertEquals(2, $entity
      ->get($this->unlimitedCardinalityField)
      ->count());
    $this
      ->assertEquals('delta 0', $entity
      ->get($this->unlimitedCardinalityField)
      ->get(0)->value);
    $this
      ->assertEquals('delta 1', $entity
      ->get($this->unlimitedCardinalityField)
      ->get(1)->value);

    // Change 5.
    $this
      ->assertEquals('required test field', $entity
      ->get($this->requiredField)
      ->get(0)->value);
  }

  /**
   * Executes all change steps.
   *
   * @param mixed $entity_id
   *   The ID of the entity.
   *
   * @return array
   *   An array keyed by the change ID and having as value the latest autosave
   *   timestamp.
   */
  protected function makeAllEntityFormChanges($entity_id) {
    $this
      ->logHtmlOutput(__FUNCTION__ . ' before changes are made');

    // Assure the first autosave submission for gathering the initial input has
    // been executed before making any changes, otherwise it might happen that
    // a change is made too fast and makes its way into the initial user input
    // used for comparison in order to determine if a new autosave state has
    // to be created or not.
    $this
      ->assertTrue($this
      ->waitForAutosaveSubmits(1));
    $latest_autosave_timestamp_per_change = [];
    for ($change_id = 1; $change_id <= $this->testAutosaveFormExistingEntityChangesCount; $change_id++) {
      $before_change_autosave_entries = $this
        ->getCountAutosaveEntries($entity_id);
      $this
        ->makeEntityFormChange($change_id);

      // Assert that a new autosave has been created, but wait for at least two
      // autosave submits to exclude any race conditions.
      $this
        ->assertTrue($this
        ->waitForAutosaveSubmits(2));
      $after_change_autosave_entries = $this
        ->getCountAutosaveEntries($entity_id);
      $this
        ->assertTrue($after_change_autosave_entries > $before_change_autosave_entries);

      // Wait for at least two more autosave submits to ensure no additional
      // autosave states are being created.
      $this
        ->assertTrue($this
        ->waitForAutosaveSubmits(2));
      $this
        ->assertEquals($after_change_autosave_entries, $this
        ->getCountAutosaveEntries($entity_id));
      $latest_autosave_timestamp_per_change[$change_id] = $this
        ->getLastAutosaveTimestamp($entity_id);
    }
    $this
      ->logHtmlOutput(__FUNCTION__ . ' after changes are made');
    return $latest_autosave_timestamp_per_change;
  }

  /**
   * Makes a change by the given change/step ID.
   *
   * @param $change_id
   *   The change id of the change to make.
   */
  protected function makeEntityFormChange($change_id) {
    $this
      ->logHtmlOutput(__FUNCTION__ . ' before change ' . $change_id);
    switch ($change_id) {
      case 1:

        // Alter the title field.
        $this
          ->alterTitleField();
        break;
      case 2:

        // Fill the first item of the test field and assert that a new autosave
        // entry has been created.
        $this
          ->fillTestField($this->unlimitedCardinalityField, 0, 'delta 0');
        break;
      case 3:

        // Add new item to the test field and assert that a new autosave entry has
        // been created.
        $new_delta_expected = 1;
        $this
          ->addItemToUnlimitedTestField($new_delta_expected);
        break;
      case 4:

        // Fill the new item of the test field and assert that a new autosave
        // entry has been created.
        $field_delta = 1;
        $this
          ->fillTestField($this->unlimitedCardinalityField, $field_delta, 'delta 1');
        break;
      case 5:

        // Fill the required test field.
        $this
          ->fillTestField($this->requiredField, 0, 'required test field');
        break;
    }
    $this
      ->logHtmlOutput(__FUNCTION__ . ' after change ' . $change_id);
  }

  /**
   * Tests the restored autosave state by the change ID.
   *
   * @param $change_id
   *  The change ID for which to test the restored autosaved state.
   *
   * @see ::makeEntityFormChange().
   */
  protected function assertCorrectlyRestoredEntityFormState($change_id) {
    $page = $this
      ->getSession()
      ->getPage();
    $this
      ->logHtmlOutput(__FUNCTION__ . ' before restore of change ' . $change_id);
    switch ($change_id) {
      case 5:
        $test_field_delta_0 = $page
          ->findField($this->requiredField . '[0][value]');
        $this
          ->assertNotEmpty($test_field_delta_0);
        $this
          ->assertEquals('required test field', $test_field_delta_0
          ->getValue());
      case 4:
        $test_field_delta_1 = $page
          ->findField($this->unlimitedCardinalityField . '[1][value]');
        $this
          ->assertNotEmpty($test_field_delta_1);
        $this
          ->assertEquals('delta 1', $test_field_delta_1
          ->getValue());
      case 3:

        // Not applying because of case 4.
        if ($change_id == 3) {
          $test_field_delta_1 = $page
            ->findField($this->unlimitedCardinalityField . '[1][value]');
          $this
            ->assertNotEmpty($test_field_delta_1);
          $this
            ->assertEquals('', $test_field_delta_1
            ->getValue());
        }
      case 2:
        $test_field_delta_0 = $page
          ->findField($this->unlimitedCardinalityField . '[0][value]');
        $this
          ->assertNotEmpty($test_field_delta_0);
        $this
          ->assertEquals('delta 0', $test_field_delta_0
          ->getValue());
      case 1:
        $this
          ->assertOriginalEntityTitleAsPageTitle();
        $entity_type = \Drupal::entityTypeManager()
          ->getDefinition($this->entityType);
        $this
          ->assertEquals($this->changedEntityTitle, $page
          ->findField($entity_type
          ->getKey('label') . '[0][value]')
          ->getValue());
        break;
    }
    $this
      ->logHtmlOutput(__FUNCTION__ . ' after restore of change ' . $change_id);
  }

  /**
   * Alters the title field of the entity.
   *
   * @param string $changed_title
   *   The title to use to set on the title form field.
   */
  protected function alterTitleField($changed_title = 'changed title') {
    if ($label_field_name = \Drupal::entityTypeManager()
      ->getDefinition($this->entityType)
      ->getKey('label')) {
      $this->changedEntityTitle = $changed_title;
      $this
        ->getSession()
        ->getPage()
        ->fillField($label_field_name . '[0][value]', $this->changedEntityTitle);
    }
  }

  /**
   * Fields a field item by its name and delta.
   *
   * @param $field_name
   *   The name of the field.
   * @param $delta
   *   The delta item of the field.
   * @param $value
   *   The value.
   */
  protected function fillTestField($field_name, $delta, $value) {
    $this
      ->getSession()
      ->getPage()
      ->fillField("{$field_name}[{$delta}][value]", $value);
  }

  /**
   * Adds a new item to the unlimited test field.
   *
   * @param $delta
   *   The new excepted delta.
   */
  protected function addItemToUnlimitedTestField($delta) {
    $this
      ->logHtmlOutput(__FUNCTION__ . ' before adding a new item to unlimited field');
    $page = $this
      ->getSession()
      ->getPage();
    $add_button = $page
      ->find('css', '[data-drupal-selector="edit-' . Html::cleanCssIdentifier($this->unlimitedCardinalityField) . '-add-more"]');
    $this
      ->assertTrue(!empty($add_button));
    $add_button
      ->press();
    $result = $this
      ->assertSession()
      ->waitForElement('css', "[name=\"{$this->unlimitedCardinalityField}[{$delta}][value]\"]");
    $this
      ->assertNotEmpty($result);
    $this
      ->logHtmlOutput(__FUNCTION__ . ' after adding a new item to unlimited field');
  }

  /**
   * Returns the currently rendered page title.
   *
   * @return string|NULL
   *   The page title.
   */
  protected function getCurrentPageTitle() {
    $element = $this
      ->getSession()
      ->getPage()
      ->find('css', '.page-title');
    $title = !empty($element) ? $element
      ->getText() : NULL;
    return $title;
  }

  /**
   * Asserts that page title matches the original entity title.
   */
  protected function assertOriginalEntityTitleAsPageTitle() {
    $current_title = $this
      ->getCurrentPageTitle();
    $this
      ->assertTrue(strpos($current_title, $this->originalEntityTitle) !== FALSE);
  }

  /**
   * Gets the count of autosave states.
   *
   * @param mixed $entity_id
   *   The ID of the entity.
   *
   * @return int
   *   The count of autosave entries.
   */
  protected function getCountAutosaveEntries($entity_id) {
    $count = \Drupal::database()
      ->select(AutosaveEntityFormStorageInterface::AUTOSAVE_ENTITY_FORM_TABLE)
      ->condition('entity_id', $entity_id)
      ->countQuery()
      ->execute()
      ->fetchField();
    return $count !== FALSE ? $count : 0;
  }

  /**
   * Gets the count of autosave unique session entries.
   *
   * @return int
   *   The count of autosave unique session entries.
   */
  protected function getCountAutosaveSessionEntries() {
    $count = \Drupal::database()
      ->select(AutosaveEntityFormStorageInterface::AUTOSAVE_ENTITY_FORM_TABLE)
      ->groupBy('form_session_id')
      ->countQuery()
      ->execute()
      ->fetchField();
    return $count !== FALSE ? $count : 0;
  }

  /**
   * Returns the timestamp of the last autosave entry for the given entity ID.
   *
   * @param mixed $entity_id
   *   The ID of the entity.
   *
   * @return int|null
   *   The timestamp of the last autosave entry.
   */
  protected function getLastAutosaveTimestamp($entity_id) {
    $timestamp = \Drupal::database()
      ->select(AutosaveEntityFormStorageInterface::AUTOSAVE_ENTITY_FORM_TABLE, 't')
      ->fields('t', [
      'timestamp',
    ])
      ->condition('entity_id', $entity_id)
      ->orderBy('timestamp', 'DESC')
      ->execute()
      ->fetchField();
    return $timestamp !== FALSE ? $timestamp : NULL;
  }

  /**
   * Deletes the autosaved states.
   *
   * @param $timestamps
   *   (optional) If specified, only the autosaved states with the given
   *   timestamps will be deleted.
   */
  protected function deleteAutosavedStates(array $timestamps = NULL) {
    $query = \Drupal::database()
      ->delete(AutosaveEntityFormStorageInterface::AUTOSAVE_ENTITY_FORM_TABLE);
    if (isset($timestamps)) {
      $query
        ->condition('timestamp', $timestamps, 'IN');
    }
    $query
      ->execute();
  }

  /**
   * Creates a new test entity.
   *
   * @return \Drupal\Core\Entity\ContentEntityInterface
   *   The newly created entity.
   */
  protected function createTestEntity() {
    $entity_type_manager = \Drupal::entityTypeManager();
    $entity_type = $entity_type_manager
      ->getDefinition($this->entityType);
    $storage = $entity_type_manager
      ->getStorage($this->entityType);
    $values = [
      'type' => $this->bundle,
    ];
    if ($label_field_name = $entity_type
      ->getKey('label')) {
      $values[$label_field_name] = 'original title';
    }
    $entity = $storage
      ->create($values);
    if ($entity instanceof EntityOwnerInterface) {
      $entity
        ->setOwner($this->webUser);
    }
    elseif ($entity_type
      ->hasKey('uid')) {
      $entity
        ->set('uid', $this->webUser
        ->id());
    }
    $entity
      ->save();
    $this->originalEntityTitle = $entity
      ->label();
    return $entity;
  }

  /**
   * Returns the test entity
   *
   * @param mixed $id
   *   The ID of the entity to load.
   *
   * @return \Drupal\Core\Entity\EntityInterface|null
   *   An entity object. NULL if no matching entity is found.
   */
  protected function reloadEntity($id) {
    $storage = \Drupal::entityTypeManager()
      ->getStorage($this->entityType);
    $storage
      ->resetCache([
      $id,
    ]);
    return $storage
      ->load($id);
  }

  /**
   * Creates a multiple field to test ajax submits with.
   */
  protected function createMultipleTestField() {
    if (!FieldStorageConfig::loadByName($this->entityType, $this->unlimitedCardinalityField)) {

      // Create an unlimited cardinality field.
      FieldStorageConfig::create([
        'field_name' => $this->unlimitedCardinalityField,
        'entity_type' => $this->entityType,
        'type' => 'text',
        'cardinality' => -1,
      ])
        ->save();
    }
    if (!FieldConfig::loadByName($this->entityType, $this->bundle, $this->unlimitedCardinalityField)) {

      // Attach an instance of the field to the content type.
      FieldConfig::create([
        'field_name' => $this->unlimitedCardinalityField,
        'entity_type' => $this->entityType,
        'bundle' => $this->bundle,
        'label' => $this
          ->randomMachineName() . '_label',
      ])
        ->save();
      $this
        ->getEntityFormDisplay($this->entityType, $this->bundle, 'default')
        ->setComponent($this->unlimitedCardinalityField, [
        'type' => 'text_textfield',
      ])
        ->save();
    }
  }

  /**
   * Creates a required test field to test ajax submits with.
   */
  protected function createRequiredTestField() {
    if (!FieldStorageConfig::loadByName($this->entityType, $this->requiredField)) {

      // Create a required test field.
      FieldStorageConfig::create([
        'field_name' => $this->requiredField,
        'entity_type' => $this->entityType,
        'type' => 'text',
        'cardinality' => 1,
      ])
        ->save();
    }
    if (!FieldConfig::loadByName($this->entityType, $this->bundle, $this->requiredField)) {

      // Attach an instance of the field to the content type.
      FieldConfig::create([
        'field_name' => $this->requiredField,
        'entity_type' => $this->entityType,
        'bundle' => $this->bundle,
        'label' => $this->requiredField,
        'required' => TRUE,
      ])
        ->save();
      $this
        ->getEntityFormDisplay($this->entityType, $this->bundle, 'default')
        ->setComponent($this->requiredField, [
        'type' => 'text_textfield',
      ])
        ->save();
    }
  }

  /**
   * Logs out and logs in the web user.
   */
  protected function relogUser() {
    $this
      ->drupalLogout();
    $this
      ->drupalLogin($this->webUser);
  }

  /**
   * Returns the URL for creating a new entity.
   *
   * @return string
   *   The url for creating a new entity.
   */
  protected abstract function getCreateNewEntityURL();

  /**
   * Returns the entity form display associated with a bundle and form mode.
   *
   * This is just a wrapper around
   * Drupal\Core\Entity\EntityDisplayRepository::getFormDisplay() for Drupal
   * versions >= 8.8, with a fallback to entity_get_form_display() for prior
   * Drupal versions.
   *
   * @param string $entity_type
   *   The entity type.
   * @param string $bundle
   *   The bundle.
   * @param string $form_mode
   *   The form mode.
   *
   * @return \Drupal\Core\Entity\Display\EntityFormDisplayInterface
   *   The entity form display associated with the given form mode.
   *
   * @todo Remove this once Drupal 8.7 is no longer supported.
   */
  private function getEntityFormDisplay($entity_type, $bundle, $form_mode) {
    if (version_compare(\Drupal::VERSION, '8.8', '>=')) {
      return \Drupal::service('entity_display.repository')
        ->getFormDisplay($entity_type, $bundle, $form_mode);
    }
    else {

      // Because this code only runs for older Drupal versions, we do not need
      // or want IDEs or the Upgrade Status module warning people about this
      // deprecated code usage. Setting the function name dynamically
      // circumvents those warnings.
      $function = 'entity_get_form_display';
      return $function($entity_type, $bundle, $form_mode);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AssertHelperTrait::castSafeStrings protected static function Casts MarkupInterface objects into strings.
AssertLegacyTrait::assert protected function Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertTrue() instead.
AssertLegacyTrait::assertCacheTag protected function Asserts whether an expected cache tag was present in the last response.
AssertLegacyTrait::assertElementNotPresent protected function Asserts that the element with the given CSS selector is not present.
AssertLegacyTrait::assertElementPresent protected function Asserts that the element with the given CSS selector is present.
AssertLegacyTrait::assertEqual protected function Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertEquals() instead.
AssertLegacyTrait::assertEscaped protected function Passes if the raw text IS found escaped on the loaded page, fail otherwise.
AssertLegacyTrait::assertField protected function Asserts that a field exists with the given name or ID.
AssertLegacyTrait::assertFieldById protected function Asserts that a field exists with the given ID and value.
AssertLegacyTrait::assertFieldByName protected function Asserts that a field exists with the given name and value.
AssertLegacyTrait::assertFieldByXPath protected function Asserts that a field exists in the current page by the given XPath.
AssertLegacyTrait::assertFieldChecked protected function Asserts that a checkbox field in the current page is checked.
AssertLegacyTrait::assertFieldsByValue protected function Asserts that a field exists in the current page with a given Xpath result.
AssertLegacyTrait::assertHeader protected function Checks that current response header equals value.
AssertLegacyTrait::assertIdentical protected function Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertSame() instead.
AssertLegacyTrait::assertIdenticalObject protected function Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertEquals() instead.
AssertLegacyTrait::assertLink protected function Passes if a link with the specified label is found.
AssertLegacyTrait::assertLinkByHref protected function Passes if a link containing a given href (part) is found.
AssertLegacyTrait::assertNoCacheTag protected function Asserts whether an expected cache tag was absent in the last response.
AssertLegacyTrait::assertNoEscaped protected function Passes if the raw text is not found escaped on the loaded page.
AssertLegacyTrait::assertNoField protected function Asserts that a field does NOT exist with the given name or ID.
AssertLegacyTrait::assertNoFieldById protected function Asserts that a field does not exist with the given ID and value.
AssertLegacyTrait::assertNoFieldByName protected function Asserts that a field does not exist with the given name and value.
AssertLegacyTrait::assertNoFieldByXPath protected function Asserts that a field does not exist or its value does not match, by XPath.
AssertLegacyTrait::assertNoFieldChecked protected function Asserts that a checkbox field in the current page is not checked.
AssertLegacyTrait::assertNoLink protected function Passes if a link with the specified label is not found.
AssertLegacyTrait::assertNoLinkByHref protected function Passes if a link containing a given href (part) is not found.
AssertLegacyTrait::assertNoOption protected function Asserts that a select option does NOT exist in the current page.
AssertLegacyTrait::assertNoPattern protected function Triggers a pass if the Perl regex pattern is not found in the raw content.
AssertLegacyTrait::assertNoRaw protected function Passes if the raw text IS not found on the loaded page, fail otherwise. 1
AssertLegacyTrait::assertNotEqual protected function Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertNotEquals() instead.
AssertLegacyTrait::assertNoText protected function Passes if the page (with HTML stripped) does not contains the text. 1
AssertLegacyTrait::assertNotIdentical protected function Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertNotSame() instead.
AssertLegacyTrait::assertNoUniqueText protected function Passes if the text is found MORE THAN ONCE on the text version of the page.
AssertLegacyTrait::assertOption protected function Asserts that a select option in the current page exists.
AssertLegacyTrait::assertOptionByText protected function Asserts that a select option with the visible text exists.
AssertLegacyTrait::assertOptionSelected protected function Asserts that a select option in the current page is checked.
AssertLegacyTrait::assertPattern protected function Triggers a pass if the Perl regex pattern is found in the raw content.
AssertLegacyTrait::assertRaw protected function Passes if the raw text IS found on the loaded page, fail otherwise. 1
AssertLegacyTrait::assertResponse protected function Asserts the page responds with the specified response code. 1
AssertLegacyTrait::assertText protected function Passes if the page (with HTML stripped) contains the text. 1
AssertLegacyTrait::assertTextHelper protected function Helper for assertText and assertNoText.
AssertLegacyTrait::assertTitle protected function Pass if the page title is the given string.
AssertLegacyTrait::assertUniqueText protected function Passes if the text is found ONLY ONCE on the text version of the page.
AssertLegacyTrait::assertUrl protected function Passes if the internal browser's URL matches the given path.
AssertLegacyTrait::buildXPathQuery protected function Builds an XPath query.
AssertLegacyTrait::constructFieldXpath protected function Helper: Constructs an XPath for the given set of attributes and value.
AssertLegacyTrait::getAllOptions protected function Get all option elements, including nested options, in a select.
AssertLegacyTrait::getRawContent protected function Gets the current raw content.
AssertLegacyTrait::pass protected function Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertTrue() instead.
AssertLegacyTrait::verbose protected function
AutosaveFormTestBase::$defaultTheme protected property The theme to install as the default for testing. Overrides BrowserTestBase::$defaultTheme
AutosaveFormTestBase::$interval protected property The autosave submission interval in milliseconds.
AutosaveFormTestBase::$modules protected static property Modules to enable. Overrides BrowserTestBase::$modules 1
AutosaveFormTestBase::$profile protected property Profile to use. Overrides BrowserTestBase::$profile
AutosaveFormTestBase::$webUser protected property The user to test with.
AutosaveFormTestBase::assertAutosaveFormLibraryLoaded protected function Asserts that the autosave form library is loaded.
AutosaveFormTestBase::assertAutosaveIsRunning protected function Asserts whether autosave is currently running.
AutosaveFormTestBase::assertAutosaveResumeDiscardMessageIsShown protected function Asserts whether the autosave resume/discard message is shown or not.
AutosaveFormTestBase::getUserPermissions abstract protected function Returns the user permissions. 1
AutosaveFormTestBase::logHtmlOutput protected function Logs the html of the current page.
AutosaveFormTestBase::prepareUser protected function Prepares the user before login.
AutosaveFormTestBase::pressAutosaveRestoreButton protected function Presses the autosave restore button.
AutosaveFormTestBase::reloadPageAndRestore protected function Loads the page and submits the autosave restore.
AutosaveFormTestBase::setUp protected function Overrides BrowserTestBase::setUp
AutosaveFormTestBase::waitForAutosaveResumeButtonToDisappear protected function Waits for the autosave restore button to disappear.
AutosaveFormTestBase::waitForAutosaveSubmits protected function Waits until a specific count of autosave submits have been triggered.
AutosaveFormTestBase::waitForElementToDisappear protected function Waits for the specified selector and to disappear.
BlockCreationTrait::placeBlock protected function Creates a block instance based on default settings. Aliased as: drupalPlaceBlock
BrowserHtmlDebugTrait::$htmlOutputBaseUrl protected property The Base URI to use for links to the output files.
BrowserHtmlDebugTrait::$htmlOutputClassName protected property Class name for HTML output logging.
BrowserHtmlDebugTrait::$htmlOutputCounter protected property Counter for HTML output logging.
BrowserHtmlDebugTrait::$htmlOutputCounterStorage protected property Counter storage for HTML output logging.
BrowserHtmlDebugTrait::$htmlOutputDirectory protected property Directory name for HTML output logging.
BrowserHtmlDebugTrait::$htmlOutputEnabled protected property HTML output output enabled.
BrowserHtmlDebugTrait::$htmlOutputFile protected property The file name to write the list of URLs to.
BrowserHtmlDebugTrait::$htmlOutputTestId protected property HTML output test ID.
BrowserHtmlDebugTrait::formatHtmlOutputHeaders protected function Formats HTTP headers as string for HTML output logging.
BrowserHtmlDebugTrait::htmlOutput protected function Logs a HTML output message in a text file.
BrowserHtmlDebugTrait::initBrowserOutputFile protected function Creates the directory to store browser output.
BrowserTestBase::$baseUrl protected property The base URL.
BrowserTestBase::$configImporter protected property The config importer that can be used in a test.
BrowserTestBase::$customTranslations protected property An array of custom translations suitable for drupal_rewrite_settings().
BrowserTestBase::$databasePrefix protected property The database prefix of this test run.
BrowserTestBase::$mink protected property Mink session manager.
BrowserTestBase::$minkDefaultDriverArgs protected property
BrowserTestBase::$originalContainer protected property The original container.
BrowserTestBase::$originalShutdownCallbacks protected property The original array of shutdown function callbacks.
BrowserTestBase::$preserveGlobalState protected property
BrowserTestBase::$root protected property The app root.
BrowserTestBase::$runTestInSeparateProcess protected property Browser tests are run in separate processes to prevent collisions between code that may be loaded by tests.
BrowserTestBase::$timeLimit protected property Time limit in seconds for the test.
BrowserTestBase::$translationFilesDirectory protected property The translation file directory for the test environment.
BrowserTestBase::cleanupEnvironment protected function Clean up the Simpletest environment.
BrowserTestBase::config protected function Configuration accessor for tests. Returns non-overridden configuration.
BrowserTestBase::cssSelectToXpath protected function Translates a CSS expression to its XPath equivalent.
BrowserTestBase::drupalGetHeader protected function Gets the value of an HTTP response header.
BrowserTestBase::drupalGetHeaders Deprecated protected function Returns all response headers.
BrowserTestBase::filePreDeleteCallback public static function Ensures test files are deletable.
BrowserTestBase::getDefaultDriverInstance protected function Gets an instance of the default Mink driver.
BrowserTestBase::getHttpClient protected function Obtain the HTTP client for the system under test.
BrowserTestBase::getOptions protected function Helper function to get the options of select field.
BrowserTestBase::getResponseLogHandler protected function Provides a Guzzle middleware handler to log every response received. Overrides BrowserHtmlDebugTrait::getResponseLogHandler
BrowserTestBase::getSession public function Returns Mink session.
BrowserTestBase::getSessionCookies protected function Get session cookies from current session.
BrowserTestBase::getTestMethodCaller protected function Retrieves the current calling line in the class under test. Overrides BrowserHtmlDebugTrait::getTestMethodCaller
BrowserTestBase::installDrupal public function Installs Drupal into the Simpletest site. 1
BrowserTestBase::registerSessions protected function Registers additional Mink sessions.
BrowserTestBase::translatePostValues protected function Transforms a nested array into a flat array suitable for drupalPostForm().
BrowserTestBase::xpath protected function Performs an xpath search on the contents of the internal browser.
BrowserTestBase::__construct public function 1
BrowserTestBase::__sleep public function Prevents serializing any properties.
ConfigTestTrait::configImporter protected function Returns a ConfigImporter object to import test configuration.
ConfigTestTrait::copyConfig protected function Copies configuration objects from source storage to target storage.
ContentEntityAutosaveFormTestBase::$bundle protected property The bundle of the entity type to be tested. 1
ContentEntityAutosaveFormTestBase::$changedEntityTitle protected property The changed entity title.
ContentEntityAutosaveFormTestBase::$entityType protected property The entity type to be tested. 1
ContentEntityAutosaveFormTestBase::$originalEntityTitle protected property The original entity title.
ContentEntityAutosaveFormTestBase::$requiredField protected property The name of the required test field.
ContentEntityAutosaveFormTestBase::$testAutosaveFormExistingEntityChangesCount protected property Count of the changes to make.
ContentEntityAutosaveFormTestBase::$unlimitedCardinalityField protected property The name of the field with unlimited cardinality to test ajax requests.
ContentEntityAutosaveFormTestBase::addItemToUnlimitedTestField protected function Adds a new item to the unlimited test field.
ContentEntityAutosaveFormTestBase::alterTitleField protected function Alters the title field of the entity.
ContentEntityAutosaveFormTestBase::assertCorrectlyRestoredEntityFormState protected function Tests the restored autosave state by the change ID.
ContentEntityAutosaveFormTestBase::assertOriginalEntityTitleAsPageTitle protected function Asserts that page title matches the original entity title.
ContentEntityAutosaveFormTestBase::createMultipleTestField protected function Creates a multiple field to test ajax submits with.
ContentEntityAutosaveFormTestBase::createRequiredTestField protected function Creates a required test field to test ajax submits with.
ContentEntityAutosaveFormTestBase::createTestEntity protected function Creates a new test entity.
ContentEntityAutosaveFormTestBase::deleteAutosavedStates protected function Deletes the autosaved states.
ContentEntityAutosaveFormTestBase::doTestAutosaveAfterFormValidationFail protected function Tests the autosave message not being shown on reload after validation fail.
ContentEntityAutosaveFormTestBase::doTestAutosaveFormExistingEntity protected function Tests the autosave support on entity forms.
ContentEntityAutosaveFormTestBase::doTestAutosaveFormNewEntity protected function Tests that the autosave form library is not loaded on new entity forms.
ContentEntityAutosaveFormTestBase::doTestAutosaveStatesPurgingOnConfigEvent protected function Tests that autosave states are purged on modifying a form related config.
ContentEntityAutosaveFormTestBase::doTestConcurrentEditing protected function Tests concurrent editing.
ContentEntityAutosaveFormTestBase::doTestSavingRestoredEntityForm protected function Tests saving an entity form restored from an autosaved state.
ContentEntityAutosaveFormTestBase::emptyRequiredFieldTestAutosaveAfterFormValidationFail protected function Empties a required field.
ContentEntityAutosaveFormTestBase::fillTestField protected function Fields a field item by its name and delta.
ContentEntityAutosaveFormTestBase::finalizeTestSavingRestoredEntityForm protected function Tests correctly saved entity after autosave restore.
ContentEntityAutosaveFormTestBase::getCountAutosaveEntries protected function Gets the count of autosave states.
ContentEntityAutosaveFormTestBase::getCountAutosaveSessionEntries protected function Gets the count of autosave unique session entries.
ContentEntityAutosaveFormTestBase::getCreateNewEntityURL abstract protected function Returns the URL for creating a new entity. 1
ContentEntityAutosaveFormTestBase::getCurrentPageTitle protected function Returns the currently rendered page title.
ContentEntityAutosaveFormTestBase::getEntityFormDisplay private function Returns the entity form display associated with a bundle and form mode.
ContentEntityAutosaveFormTestBase::getLastAutosaveTimestamp protected function Returns the timestamp of the last autosave entry for the given entity ID.
ContentEntityAutosaveFormTestBase::makeAllEntityFormChanges protected function Executes all change steps.
ContentEntityAutosaveFormTestBase::makeEntityFormChange protected function Makes a change by the given change/step ID.
ContentEntityAutosaveFormTestBase::prepareSetUp protected function Prepares the test setup. Overrides AutosaveFormTestBase::prepareSetUp 1
ContentEntityAutosaveFormTestBase::reloadEntity protected function Returns the test entity
ContentEntityAutosaveFormTestBase::relogUser protected function Logs out and logs in the web user.
ContentEntityAutosaveFormTestBase::saveForm protected function Submits the current form.
ContentEntityAutosaveFormTestBase::testAutosaveForms public function Tests autosave.
ContentTypeCreationTrait::createContentType protected function Creates a custom content type based on default settings. Aliased as: drupalCreateContentType 1
FunctionalTestSetupTrait::$apcuEnsureUniquePrefix protected property The flag to set 'apcu_ensure_unique_prefix' setting. 1
FunctionalTestSetupTrait::$classLoader protected property The class loader to use for installation and initialization of setup.
FunctionalTestSetupTrait::$configDirectories Deprecated protected property The config directories used in this test.
FunctionalTestSetupTrait::$rootUser protected property The "#1" admin user.
FunctionalTestSetupTrait::doInstall protected function Execute the non-interactive installer. 1
FunctionalTestSetupTrait::getDatabaseTypes protected function Returns all supported database driver installer objects.
FunctionalTestSetupTrait::initConfig protected function Initialize various configurations post-installation. 2
FunctionalTestSetupTrait::initKernel protected function Initializes the kernel after installation.
FunctionalTestSetupTrait::initSettings protected function Initialize settings created during install.
FunctionalTestSetupTrait::initUserSession protected function Initializes user 1 for the site to be installed.
FunctionalTestSetupTrait::installDefaultThemeFromClassProperty protected function Installs the default theme defined by `static::$defaultTheme` when needed.
FunctionalTestSetupTrait::installParameters protected function Returns the parameters that will be used when Simpletest installs Drupal. 9
FunctionalTestSetupTrait::prepareEnvironment protected function Prepares the current environment for running the test. 23
FunctionalTestSetupTrait::prepareRequestForGenerator protected function Creates a mock request and sets it on the generator.
FunctionalTestSetupTrait::prepareSettings protected function Prepares site settings and services before installation. 2
FunctionalTestSetupTrait::rebuildAll protected function Resets and rebuilds the environment after setup.
FunctionalTestSetupTrait::rebuildContainer protected function Rebuilds \Drupal::getContainer().
FunctionalTestSetupTrait::resetAll protected function Resets all data structures after having enabled new modules.
FunctionalTestSetupTrait::setContainerParameter protected function Changes parameters in the services.yml file.
FunctionalTestSetupTrait::setupBaseUrl protected function Sets up the base URL based upon the environment variable.
FunctionalTestSetupTrait::writeSettings protected function Rewrites the settings.php file of the test site.
NodeCreationTrait::createNode protected function Creates a node based on default settings. Aliased as: drupalCreateNode
NodeCreationTrait::getNodeByTitle public function Get a node from the database based on its title. Aliased as: drupalGetNodeByTitle
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
RandomGeneratorTrait::$randomGenerator protected property The random generator.
RandomGeneratorTrait::getRandomGenerator protected function Gets the random generator for the utility methods.
RandomGeneratorTrait::randomMachineName protected function Generates a unique random string containing letters and numbers. 1
RandomGeneratorTrait::randomObject public function Generates a random PHP object.
RandomGeneratorTrait::randomString public function Generates a pseudo-random string of ASCII characters of codes 32 to 126.
RandomGeneratorTrait::randomStringValidate public function Callback for random string validation.
RefreshVariablesTrait::refreshVariables protected function Refreshes in-memory configuration and state information. 3
SessionTestTrait::$sessionName protected property The name of the session cookie.
SessionTestTrait::generateSessionName protected function Generates a session cookie name.
SessionTestTrait::getSessionName protected function Returns the session name in use on the child site.
StorageCopyTrait::replaceStorageContents protected static function Copy the configuration from one storage to another and remove stale items.
TestRequirementsTrait::checkModuleRequirements private function Checks missing module requirements.
TestRequirementsTrait::checkRequirements protected function Check module requirements for the Drupal use case. 1
TestRequirementsTrait::getDrupalRoot protected static function Returns the Drupal root directory.
TestSetupTrait::$configSchemaCheckerExclusions protected static property An array of config object names that are excluded from schema checking.
TestSetupTrait::$container protected property The dependency injection container used in the test.
TestSetupTrait::$kernel protected property The DrupalKernel instance used in the test.
TestSetupTrait::$originalSite protected property The site directory of the original parent site.
TestSetupTrait::$privateFilesDirectory protected property The private file directory for the test environment.
TestSetupTrait::$publicFilesDirectory protected property The public file directory for the test environment.
TestSetupTrait::$siteDirectory protected property The site directory of this test run.
TestSetupTrait::$strictConfigSchema protected property Set to TRUE to strict check all configuration saved. 2
TestSetupTrait::$tempFilesDirectory protected property The temporary file directory for the test environment.
TestSetupTrait::$testId protected property The test run ID.
TestSetupTrait::changeDatabasePrefix protected function Changes the database connection to the prefixed one.
TestSetupTrait::getConfigSchemaExclusions protected function Gets the config schema exclusions for this test.
TestSetupTrait::getDatabaseConnection public static function Returns the database connection to the site running Simpletest.
TestSetupTrait::prepareDatabasePrefix protected function Generates a database prefix for running tests. 2
UiHelperTrait::$loggedInUser protected property The current user logged in using the Mink controlled browser.
UiHelperTrait::$maximumMetaRefreshCount protected property The number of meta refresh redirects to follow, or NULL if unlimited.
UiHelperTrait::$metaRefreshCount protected property The number of meta refresh redirects followed during ::drupalGet().
UiHelperTrait::buildUrl protected function Builds an a absolute URL from a system path or a URL object.
UiHelperTrait::checkForMetaRefresh protected function Checks for meta refresh tag and if found call drupalGet() recursively.
UiHelperTrait::click protected function Clicks the element with the given CSS selector.
UiHelperTrait::clickLink protected function Follows a link by complete name.
UiHelperTrait::cssSelect protected function Searches elements using a CSS selector in the raw content.
UiHelperTrait::drupalGet protected function Retrieves a Drupal path or an absolute path. 3
UiHelperTrait::drupalLogin protected function Logs in a user using the Mink controlled browser.
UiHelperTrait::drupalLogout protected function Logs a user out of the Mink controlled browser and confirms.
UiHelperTrait::drupalPostForm protected function Executes a form submission.
UiHelperTrait::drupalUserIsLoggedIn protected function Returns whether a given user account is logged in.
UiHelperTrait::getAbsoluteUrl protected function Takes a path and returns an absolute path.
UiHelperTrait::getTextContent protected function Retrieves the plain-text content from the current page.
UiHelperTrait::getUrl protected function Get the current URL from the browser.
UiHelperTrait::prepareRequest protected function Prepare for a request to testing site. 1
UiHelperTrait::submitForm protected function Fills and submits a form.
UserCreationTrait::checkPermissions protected function Checks whether a given list of permission names is valid.
UserCreationTrait::createAdminRole protected function Creates an administrative role.
UserCreationTrait::createRole protected function Creates a role with specified permissions. Aliased as: drupalCreateRole
UserCreationTrait::createUser protected function Create a user with a given set of permissions. Aliased as: drupalCreateUser
UserCreationTrait::grantPermissions protected function Grant permissions to a user role.
UserCreationTrait::setCurrentUser protected function Switch the current logged in user.
UserCreationTrait::setUpCurrentUser protected function Creates a random user account and sets it as current user.
WebDriverTestBase::$disableCssAnimations protected property Disables CSS animations in tests for more reliable testing.
WebDriverTestBase::$minkDefaultDriverClass protected property To use a legacy phantomjs based approach, please use PhantomJSDriver::class. Overrides BrowserTestBase::$minkDefaultDriverClass 2
WebDriverTestBase::assertElementNotVisible Deprecated protected function Asserts that the element with the given CSS selector is not visible.
WebDriverTestBase::assertElementVisible Deprecated protected function Asserts that the element with the given CSS selector is visible.
WebDriverTestBase::assertJsCondition protected function Waits for the given time or until the given JS condition becomes TRUE.
WebDriverTestBase::assertSession public function Returns WebAssert object. Overrides UiHelperTrait::assertSession 1
WebDriverTestBase::createScreenshot protected function Creates a screenshot.
WebDriverTestBase::getDrupalSettings protected function Gets the current Drupal javascript settings and parses into an array. Overrides BrowserTestBase::getDrupalSettings
WebDriverTestBase::getHtmlOutputHeaders protected function Returns headers in HTML output format. Overrides BrowserHtmlDebugTrait::getHtmlOutputHeaders
WebDriverTestBase::getMinkDriverArgs protected function Get the Mink driver args from an environment variable, if it is set. Can be overridden in a derived class so it is possible to use a different value for a subset of tests, e.g. the JavaScript tests. Overrides BrowserTestBase::getMinkDriverArgs
WebDriverTestBase::initFrontPage protected function Visits the front page when initializing Mink. Overrides BrowserTestBase::initFrontPage
WebDriverTestBase::initMink protected function Initializes Mink sessions. Overrides BrowserTestBase::initMink 1
WebDriverTestBase::installModulesFromClassProperty protected function Install modules defined by `static::$modules`. Overrides FunctionalTestSetupTrait::installModulesFromClassProperty
WebDriverTestBase::tearDown protected function Overrides BrowserTestBase::tearDown 1
XdebugRequestTrait::extractCookiesFromRequest protected function Adds xdebug cookies, from request setup.