function HandlerFieldUserNameTest::testNoAdditionalFields

Same name in other branches
  1. 9 core/modules/user/tests/src/Functional/Views/HandlerFieldUserNameTest.php \Drupal\Tests\user\Functional\Views\HandlerFieldUserNameTest::testNoAdditionalFields()
  2. 8.9.x core/modules/user/tests/src/Functional/Views/HandlerFieldUserNameTest.php \Drupal\Tests\user\Functional\Views\HandlerFieldUserNameTest::testNoAdditionalFields()
  3. 11.x 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 72

Class

HandlerFieldUserNameTest
Tests the handler of the user: name field.

Namespace

Drupal\Tests\user\Functional\Views

Code

public function testNoAdditionalFields() : void {
    
    /** @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 = (string) $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.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.