CompactUserRenderTest.php in Lightning Core 8.4
File
tests/src/Kernel/CompactUserRenderTest.php
View source
<?php
namespace Drupal\Tests\lightning_core\Kernel;
use Drupal\file\Entity\File;
use Drupal\KernelTests\KernelTestBase;
use Drupal\user\Entity\User;
class CompactUserRenderTest extends KernelTestBase {
protected static $modules = [
'field',
'file',
'image',
'lightning_core',
'system',
'user',
];
protected function setUp() {
parent::setUp();
$this
->installSchema('system', 'sequences');
$this
->installSchema('file', 'file_usage');
$this
->installEntitySchema('file');
$this
->installEntitySchema('user');
$this
->installConfig('image');
$this
->installConfig('user');
$this
->installConfig('lightning_core');
}
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');
$output = (string) $this->container
->get('renderer')
->renderRoot($build);
$this
->assertContains($user
->getDisplayName(), $output);
$this
->assertContains($picture
->getFilename(), $output);
$this
->assertContains($user
->toUrl()
->toString(), $output);
}
}