3 namespace Drupal\Tests\user\Kernel;
5 use Drupal\user\Entity\User;
6 use Drupal\KernelTests\KernelTestBase;
9 * Tests available user fields in twig.
13 class UserFieldsTest extends KernelTestBase {
20 public static $modules = ['user', 'system'];
25 protected function setUp() {
27 $this->installEntitySchema('user');
29 // Set up a test theme that prints the user's mail field.
30 \Drupal::service('theme_handler')->install(['user_test_theme']);
31 \Drupal::theme()->setActiveTheme(\Drupal::service('theme.initialization')->initTheme('user_test_theme'));
32 // Clear the theme registry.
33 $this->container->set('theme.registry', NULL);
37 * Tests account's available fields.
39 public function testUserFields() {
40 // Create the user to test the user fields.
41 $user = User::create([
43 'mail' => 'foobar@example.com',
45 $build = user_view($user);
46 $output = \Drupal::service('renderer')->renderRoot($build);
47 $this->setRawContent($output);
48 $userEmail = $user->getEmail();
49 $this->assertText($userEmail, "User's mail field is found in the twig template");