You are here

public function ElementTest::testFormAutocomplete in Zircon Profile 8

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

Tests a form with a autocomplete setting..

File

core/modules/system/src/Tests/Form/ElementTest.php, line 148
Contains \Drupal\system\Tests\Form\ElementTest.

Class

ElementTest
Tests building and processing of core form elements.

Namespace

Drupal\system\Tests\Form

Code

public function testFormAutocomplete() {
  $this
    ->drupalGet('form-test/autocomplete');
  $result = $this
    ->xpath('//input[@id="edit-autocomplete-1" and contains(@data-autocomplete-path, "form-test/autocomplete-1")]');
  $this
    ->assertEqual(count($result), 0, 'Ensure that the user does not have access to the autocompletion');
  $result = $this
    ->xpath('//input[@id="edit-autocomplete-2" and contains(@data-autocomplete-path, "form-test/autocomplete-2/value")]');
  $this
    ->assertEqual(count($result), 0, 'Ensure that the user does not have access to the autocompletion');
  $user = $this
    ->drupalCreateUser(array(
    'access autocomplete test',
  ));
  $this
    ->drupalLogin($user);
  $this
    ->drupalGet('form-test/autocomplete');

  // Make sure that the autocomplete library is added.
  $this
    ->assertRaw('core/misc/autocomplete.js');
  $result = $this
    ->xpath('//input[@id="edit-autocomplete-1" and contains(@data-autocomplete-path, "form-test/autocomplete-1")]');
  $this
    ->assertEqual(count($result), 1, 'Ensure that the user does have access to the autocompletion');
  $result = $this
    ->xpath('//input[@id="edit-autocomplete-2" and contains(@data-autocomplete-path, "form-test/autocomplete-2/value")]');
  $this
    ->assertEqual(count($result), 1, 'Ensure that the user does have access to the autocompletion');
}