public function CompactUserRenderTest::test in Lightning Core 8.5
Same name and namespace in other branches
- 8.3 tests/src/Kernel/CompactUserRenderTest.php \Drupal\Tests\lightning_core\Kernel\CompactUserRenderTest::test()
- 8.4 tests/src/Kernel/CompactUserRenderTest.php \Drupal\Tests\lightning_core\Kernel\CompactUserRenderTest::test()
File
- tests/
src/ Kernel/ CompactUserRenderTest.php, line 43
Class
- CompactUserRenderTest
- @group lightning_core
Namespace
Drupal\Tests\lightning_core\KernelCode
public function test() {
$picture = File::create([
'uri' => $this
->getRandomGenerator()
->image('public://martok.png', '320x240', '320x240'),
]);
$this
->assertFileExists($picture
->getFileUri());
$this
->assertSame(SAVED_NEW, $picture
->save());
$user = User::create([
'name' => 'General Martok',
'user_picture' => $picture
->id(),
]);
$this
->assertSame(SAVED_NEW, $user
->save());
$build = $this->container
->get('entity_type.manager')
->getViewBuilder('user')
->view($user, 'compact');
// hook_ENTITY_TYPE_view() is normally invoked during rendering, which means
// we need to assert things in the final rendered output.
$output = (string) $this->container
->get('renderer')
->renderRoot($build);
$this
->assertStringContainsString($user
->getDisplayName(), $output);
$this
->assertStringContainsString($picture
->getFilename(), $output);
$this
->assertStringContainsString($user
->toUrl()
->toString(), $output);
}