Version 1
[yaffs-website] / web / core / modules / user / tests / src / Kernel / UserFieldsTest.php
1 <?php
2
3 namespace Drupal\Tests\user\Kernel;
4
5 use Drupal\user\Entity\User;
6 use Drupal\KernelTests\KernelTestBase;
7
8 /**
9  * Tests available user fields in twig.
10  *
11  * @group user
12  */
13 class UserFieldsTest extends KernelTestBase {
14
15   /**
16    * Modules to enable.
17    *
18    * @var array
19    */
20   public static $modules = ['user', 'system'];
21
22   /**
23    * {@inheritdoc}
24    */
25   protected function setUp() {
26     parent::setUp();
27     $this->installEntitySchema('user');
28
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);
34   }
35
36   /**
37    * Tests account's available fields.
38    */
39   public function testUserFields() {
40     // Create the user to test the user fields.
41     $user = User::create([
42       'name' => 'foobar',
43       'mail' => 'foobar@example.com',
44     ]);
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");
50   }
51
52 }