You are here

public function HandlerFieldUserNameTest::testNoAdditionalFields in Zircon Profile 8

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

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

File

core/modules/user/src/Tests/Views/HandlerFieldUserNameTest.php, line 70
Contains \Drupal\user\Tests\Views\HandlerFieldUserNameTest.

Class

HandlerFieldUserNameTest
Tests the handler of the user: name field.

Namespace

Drupal\user\Tests\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
    ->assertTrue(strpos($render, $username) !== FALSE, 'If link to user is checked the username should be part of the output.');
}