You are here

public function ElementTest::testFormAutocomplete in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/system/tests/src/Functional/Form/ElementTest.php \Drupal\Tests\system\Functional\Form\ElementTest::testFormAutocomplete()
  2. 10 core/modules/system/tests/src/Functional/Form/ElementTest.php \Drupal\Tests\system\Functional\Form\ElementTest::testFormAutocomplete()

Tests a form with an autocomplete setting..

File

core/modules/system/tests/src/Functional/Form/ElementTest.php, line 169

Class

ElementTest
Tests building and processing of core form elements.

Namespace

Drupal\Tests\system\Functional\Form

Code

public function testFormAutocomplete() {
  $this
    ->drupalGet('form-test/autocomplete');

  // Ensure that the user does not have access to the autocompletion.
  $this
    ->assertSession()
    ->elementNotExists('xpath', '//input[@id="edit-autocomplete-1" and contains(@data-autocomplete-path, "form-test/autocomplete-1")]');
  $this
    ->assertSession()
    ->elementNotExists('xpath', '//input[@id="edit-autocomplete-2" and contains(@data-autocomplete-path, "form-test/autocomplete-2/value")]');
  $user = $this
    ->drupalCreateUser([
    'access autocomplete test',
  ]);
  $this
    ->drupalLogin($user);
  $this
    ->drupalGet('form-test/autocomplete');

  // Make sure that the autocomplete library is added.
  $this
    ->assertSession()
    ->responseContains('core/misc/autocomplete.js');

  // Ensure that the user does have access to the autocompletion.
  $this
    ->assertSession()
    ->elementExists('xpath', '//input[@id="edit-autocomplete-1" and contains(@data-autocomplete-path, "form-test/autocomplete-1")]');
  $this
    ->assertSession()
    ->elementExists('xpath', '//input[@id="edit-autocomplete-2" and contains(@data-autocomplete-path, "form-test/autocomplete-2/value")]');
}