public function MessageTemplateTest::testGetTextDefaultLanguage in Message 8
Tests the getText method with default language only.
@covers ::getText
File
- tests/
src/ Unit/ Entity/ MessageTemplateTest.php, line 130
Class
- MessageTemplateTest
- Unit tests for the message template entity.
Namespace
Drupal\Tests\message\Unit\EntityCode
public function testGetTextDefaultLanguage() {
// Mock a language manager.
$container = new ContainerBuilder();
$language_manager = $this
->prophesize(LanguageManagerInterface::class)
->reveal();
$container
->set('language_manager', $language_manager);
\Drupal::setContainer($container);
// Should be empty by default.
$this
->assertEmpty($this->messageTemplate
->getText());
// Setup a renderer.
$renderer = $this
->prophesize(RendererInterface::class);
// Set some text.
$text = [
[
'value' => 'foo text',
'format' => 'foo_format',
],
[
'value' => 'bar text',
'format' => 'bar_format',
],
];
$expected_build = [
'#type' => 'processed_text',
'#text' => $text[0]['value'],
'#format' => $text[0]['format'],
'#langcode' => Language::LANGCODE_NOT_SPECIFIED,
];
$renderer
->renderPlain($expected_build)
->willReturn('<div>foo text</div>');
$expected_build = [
'#type' => 'processed_text',
'#text' => $text[1]['value'],
'#format' => $text[1]['format'],
'#langcode' => Language::LANGCODE_NOT_SPECIFIED,
];
$renderer
->renderPlain($expected_build)
->willReturn('bar text');
\Drupal::getContainer()
->set('renderer', $renderer
->reveal());
$this->messageTemplate
->set('text', $text);
$expected = [
'<div>foo text</div>',
'bar text',
];
$this
->assertEquals($expected, $this->messageTemplate
->getText());
// Test specific delta.
$this
->assertEquals([
$expected[1],
], $this->messageTemplate
->getText(Language::LANGCODE_NOT_SPECIFIED, 1));
// Non-existent delta.
$this
->assertEmpty($this->messageTemplate
->getText(Language::LANGCODE_NOT_SPECIFIED, 42));
}