Mercurial > hg > isophonics-drupal-site
annotate core/modules/user/tests/src/Kernel/UserFieldsTest.php @ 19:fa3358dc1485 tip
Add ndrum files
author | Chris Cannam |
---|---|
date | Wed, 28 Aug 2019 13:14:47 +0100 |
parents | 4c8ae668cc8c |
children |
rev | line source |
---|---|
Chris@0 | 1 <?php |
Chris@0 | 2 |
Chris@0 | 3 namespace Drupal\Tests\user\Kernel; |
Chris@0 | 4 |
Chris@0 | 5 use Drupal\user\Entity\User; |
Chris@0 | 6 use Drupal\KernelTests\KernelTestBase; |
Chris@0 | 7 |
Chris@0 | 8 /** |
Chris@0 | 9 * Tests available user fields in twig. |
Chris@0 | 10 * |
Chris@0 | 11 * @group user |
Chris@0 | 12 */ |
Chris@0 | 13 class UserFieldsTest extends KernelTestBase { |
Chris@0 | 14 |
Chris@0 | 15 /** |
Chris@0 | 16 * Modules to enable. |
Chris@0 | 17 * |
Chris@0 | 18 * @var array |
Chris@0 | 19 */ |
Chris@0 | 20 public static $modules = ['user', 'system']; |
Chris@0 | 21 |
Chris@0 | 22 /** |
Chris@0 | 23 * {@inheritdoc} |
Chris@0 | 24 */ |
Chris@0 | 25 protected function setUp() { |
Chris@0 | 26 parent::setUp(); |
Chris@0 | 27 $this->installEntitySchema('user'); |
Chris@0 | 28 |
Chris@0 | 29 // Set up a test theme that prints the user's mail field. |
Chris@0 | 30 \Drupal::service('theme_handler')->install(['user_test_theme']); |
Chris@0 | 31 \Drupal::theme()->setActiveTheme(\Drupal::service('theme.initialization')->initTheme('user_test_theme')); |
Chris@0 | 32 // Clear the theme registry. |
Chris@0 | 33 $this->container->set('theme.registry', NULL); |
Chris@0 | 34 } |
Chris@0 | 35 |
Chris@0 | 36 /** |
Chris@0 | 37 * Tests account's available fields. |
Chris@0 | 38 */ |
Chris@0 | 39 public function testUserFields() { |
Chris@0 | 40 // Create the user to test the user fields. |
Chris@0 | 41 $user = User::create([ |
Chris@0 | 42 'name' => 'foobar', |
Chris@0 | 43 'mail' => 'foobar@example.com', |
Chris@0 | 44 ]); |
Chris@0 | 45 $build = user_view($user); |
Chris@0 | 46 $output = \Drupal::service('renderer')->renderRoot($build); |
Chris@0 | 47 $this->setRawContent($output); |
Chris@0 | 48 $userEmail = $user->getEmail(); |
Chris@0 | 49 $this->assertText($userEmail, "User's mail field is found in the twig template"); |
Chris@0 | 50 } |
Chris@0 | 51 |
Chris@0 | 52 } |