You are here

public function HandlerFieldUserNameTest::testNoAdditionalFields in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/user/tests/src/Functional/Views/HandlerFieldUserNameTest.php \Drupal\Tests\user\Functional\Views\HandlerFieldUserNameTest::testNoAdditionalFields()

Tests that the field handler works when no additional fields are added.

File

core/modules/user/tests/src/Functional/Views/HandlerFieldUserNameTest.php, line 70

Class

HandlerFieldUserNameTest
Tests the handler of the user: name field.

Namespace

Drupal\Tests\user\Functional\Views

Code

public function testNoAdditionalFields() {

  /** @var \Drupal\Core\Render\RendererInterface $renderer */
  $renderer = \Drupal::service('renderer');
  $view = Views::getView('test_views_handler_field_user_name');
  $this
    ->executeView($view);
  $username = $this
    ->randomMachineName();
  $view->result[0]->_entity
    ->setUsername($username);
  $view->result[0]->_entity->uid->value = 1;
  $render = $renderer
    ->executeInRenderContext(new RenderContext(), function () use ($view) {
    return $view->field['name']
      ->advancedRender($view->result[0]);
  });
  $this
    ->assertStringContainsString($username, $render, 'If link to user is checked the username should be part of the output.');
}