You are here

protected function AutofillJavascriptTest::configureAutofillFields in Autofill 8

Configures the autofill fields.

1 call to AutofillJavascriptTest::configureAutofillFields()
AutofillJavascriptTest::testAutofillFromAnotherField in tests/src/FunctionalJavascript/AutofillJavascriptTest.php
Tests the autofill of a new field based on the node title.

File

tests/src/FunctionalJavascript/AutofillJavascriptTest.php, line 124

Class

AutofillJavascriptTest
Tests the Autofill module.

Namespace

Drupal\Tests\autofill\FunctionalJavascript

Code

protected function configureAutofillFields() {

  // Setup the source and target field names as a key/value pair.
  $fields = [
    'field_source_1' => 'field_target_1',
    'field_source_2' => 'field_target_2',
  ];

  // Open the "Manage form display" page.
  $this
    ->drupalGet('admin/structure/types/manage/' . $this->contentType
    ->id() . '/form-display');
  foreach ($fields as $source => $target) {

    // Configure the target fields.
    $this
      ->click('[name="' . $target . '_settings_edit"]');
    $this
      ->assertSession()
      ->assertWaitOnAjaxRequest();
    $autofill_enable_checkbox = $this
      ->assertSession()
      ->elementExists('css', 'input[name="fields[' . $target . '][settings_edit_form][third_party_settings][autofill][enabled]"]');
    $autofill_enable_checkbox
      ->check();
    $this
      ->assertSession()
      ->assertWaitOnAjaxRequest();
    $source_field_select = $this
      ->assertSession()
      ->elementExists('css', 'select[name="fields[' . $target . '][settings_edit_form][third_party_settings][autofill][source_field]"]');

    // Set the source autofill field.
    $source_field_select
      ->selectOption($source);
    $this
      ->getSession()
      ->getPage()
      ->findButton('Update')
      ->click();
    $this
      ->assertSession()
      ->assertWaitOnAjaxRequest();

    // The target field summary should state the source field.
    $target_drupal_selector = 'edit-fields-' . str_replace('_', '-', $target);
    $this
      ->assertSession()
      ->elementTextContains('css', 'tr[data-drupal-selector="' . $target_drupal_selector . '"]', 'Autofill from: ' . $source);
  }

  // Save the configuration.
  $this
    ->getSession()
    ->getPage()
    ->findButton('Save')
    ->click();
}