function TranslatableStringTest::testCreateTranslatableString
Tests various ways of creating a translatable string.
File
-
core/
modules/ package_manager/ tests/ src/ Kernel/ TranslatableStringTest.php, line 22
Class
- TranslatableStringTest
- @covers \Drupal\package_manager\TranslatableStringFactory @covers \Drupal\package_manager\TranslatableStringAdapter
Namespace
Drupal\Tests\package_manager\KernelCode
public function testCreateTranslatableString() : void {
// Ensure that we have properly overridden Composer Stager's factory.
$factory = $this->container
->get(TranslatableFactoryInterface::class);
$this->assertInstanceOf(TranslatableStringFactory::class, $factory);
/** @var \Drupal\package_manager\TranslatableStringAdapter $string */
$string = $factory->createTranslatableMessage('This string has no parameters.');
$this->assertInstanceOf(TranslatableStringAdapter::class, $string);
$this->assertEmpty($string->getArguments());
$this->assertEmpty($string->getOption('context'));
$this->assertSame('This string has no parameters.', (string) $string);
$parameters = $factory->createTranslationParameters([
'%name' => 'Slim Shady',
]);
$string = $factory->createTranslatableMessage('My name is %name.', $parameters, 'outer space');
$this->assertSame($parameters->getAll(), $string->getArguments());
$this->assertSame('outer space', $string->getOption('context'));
$this->assertSame('My name is <em class="placeholder">Slim Shady</em>.', (string) $string);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.