You are here

public function MessageThemeTest::testMessageTextWrapper in Message 8

Test that message render returns message text wrapped in a div.

File

tests/src/Kernel/MessageThemeTest.php, line 48

Class

MessageThemeTest
Test theming of messages.

Namespace

Drupal\Tests\message\Kernel

Code

public function testMessageTextWrapper() {
  $template = 'dummy_message';

  // Create message to be rendered.
  $message_template = $this
    ->createMessageTemplate($template, 'Dummy message', '', [
    'Text to be wrapped by div.',
  ]);
  $message = Message::create([
    'template' => $message_template
      ->id(),
  ])
    ->setOwner($this->account);
  $message
    ->save();

  // Simulate theming of the message.
  $build = $this->container
    ->get('entity_type.manager')
    ->getViewBuilder('message')
    ->view($message);
  $output = $this->container
    ->get('renderer')
    ->renderRoot($build);
  $this
    ->setRawContent($output);
  $xpath = $this
    ->xpath('//div');

  // @todo Something is off here, as *only* the div is there, no content.
  // @see https://github.com/Gizra/message/issues/128
  $this
    ->assertNotEmpty($xpath, 'A div has been found wrapping the message text.');
}