Same filename and directory in other branches
- 8.9.x core/modules/user/tests/src/Kernel/UserFieldsTest.php
- 9 core/modules/user/tests/src/Kernel/UserFieldsTest.php
Namespace
Drupal\Tests\user\Kernel
File
core/modules/user/tests/src/Kernel/UserFieldsTest.php
View source
<?php
declare (strict_types=1);
namespace Drupal\Tests\user\Kernel;
use Drupal\user\Entity\User;
use Drupal\KernelTests\KernelTestBase;
class UserFieldsTest extends KernelTestBase {
protected static $modules = [
'user',
'system',
];
protected function setUp() : void {
parent::setUp();
$this
->installEntitySchema('user');
\Drupal::service('theme_installer')
->install([
'user_test_theme',
]);
\Drupal::theme()
->setActiveTheme(\Drupal::service('theme.initialization')
->initTheme('user_test_theme'));
$this->container
->set('theme.registry', NULL);
}
public function testUserFields() {
$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");
}
}
Classes