You are here

public function UserFieldsTest::testUserFields in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/user/tests/src/Kernel/UserFieldsTest.php \Drupal\Tests\user\Kernel\UserFieldsTest::testUserFields()
  2. 10 core/modules/user/tests/src/Kernel/UserFieldsTest.php \Drupal\Tests\user\Kernel\UserFieldsTest::testUserFields()

Tests account's available fields.

File

core/modules/user/tests/src/Kernel/UserFieldsTest.php, line 39

Class

UserFieldsTest
Tests available user fields in twig.

Namespace

Drupal\Tests\user\Kernel

Code

public function testUserFields() {

  // Create the user to test the user fields.
  $user = User::create([
    'name' => 'foobar',
    'mail' => 'foobar@example.com',
  ]);
  $build = \Drupal::entityTypeManager()
    ->getViewBuilder('user')
    ->view($user);
  $output = \Drupal::service('renderer')
    ->renderRoot($build);
  $this
    ->setRawContent($output);
  $userEmail = $user
    ->getEmail();
  $this
    ->assertText($userEmail, "User's mail field is found in the twig template");
}