You are here

public function NodeCreationTest::testAuthorAutocomplete in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/node/tests/src/Functional/NodeCreationTest.php \Drupal\Tests\node\Functional\NodeCreationTest::testAuthorAutocomplete()

Tests the author autocompletion textfield.

File

core/modules/node/tests/src/Functional/NodeCreationTest.php, line 235

Class

NodeCreationTest
Create a node and test saving it.

Namespace

Drupal\Tests\node\Functional

Code

public function testAuthorAutocomplete() {
  $admin_user = $this
    ->drupalCreateUser([
    'administer nodes',
    'create page content',
  ]);
  $this
    ->drupalLogin($admin_user);
  $this
    ->drupalGet('node/add/page');
  $result = $this
    ->xpath('//input[@id="edit-uid-0-value" and contains(@data-autocomplete-path, "user/autocomplete")]');
  $this
    ->assertCount(0, $result, 'No autocompletion without access user profiles.');
  $admin_user = $this
    ->drupalCreateUser([
    'administer nodes',
    'create page content',
    'access user profiles',
  ]);
  $this
    ->drupalLogin($admin_user);
  $this
    ->drupalGet('node/add/page');
  $result = $this
    ->xpath('//input[@id="edit-uid-0-target-id" and contains(@data-autocomplete-path, "/entity_reference_autocomplete/user/default")]');
  $this
    ->assertCount(1, $result, 'Ensure that the user does have access to the autocompletion');
}