function UserFieldsTest::testUserFields

Same name and namespace in other branches
  1. 9 core/modules/user/tests/src/Kernel/UserFieldsTest.php \Drupal\Tests\user\Kernel\UserFieldsTest::testUserFields()
  2. 8.9.x core/modules/user/tests/src/Kernel/UserFieldsTest.php \Drupal\Tests\user\Kernel\UserFieldsTest::testUserFields()
  3. 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() : void {
  // 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");
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.