function YamlDiscoveryTest::testGetDefinitionsWithTranslatableDefinitions
Same name in other branches
- 9 core/tests/Drupal/Tests/Core/Plugin/Discovery/YamlDiscoveryTest.php \Drupal\Tests\Core\Plugin\Discovery\YamlDiscoveryTest::testGetDefinitionsWithTranslatableDefinitions()
- 8.9.x core/tests/Drupal/Tests/Core/Plugin/Discovery/YamlDiscoveryTest.php \Drupal\Tests\Core\Plugin\Discovery\YamlDiscoveryTest::testGetDefinitionsWithTranslatableDefinitions()
- 11.x core/tests/Drupal/Tests/Core/Plugin/Discovery/YamlDiscoveryTest.php \Drupal\Tests\Core\Plugin\Discovery\YamlDiscoveryTest::testGetDefinitionsWithTranslatableDefinitions()
@covers ::getDefinitions
File
-
core/
tests/ Drupal/ Tests/ Core/ Plugin/ Discovery/ YamlDiscoveryTest.php, line 78
Class
- YamlDiscoveryTest
- @coversDefaultClass \Drupal\Core\Plugin\Discovery\YamlDiscovery @group Plugin
Namespace
Drupal\Tests\Core\Plugin\DiscoveryCode
public function testGetDefinitionsWithTranslatableDefinitions() : void {
vfsStream::setup('root');
$file_1 = <<<'EOS'
test_plugin:
title: test title
EOS;
$file_2 = <<<'EOS'
test_plugin2:
title: test title2
title_context: 'test-context'
EOS;
vfsStream::create([
'test_1' => [
'test_1.test.yml' => $file_1,
],
'test_2' => [
'test_2.test.yml' => $file_2,
],
]);
$discovery = new YamlDiscovery('test', [
'test_1' => vfsStream::url('root/test_1'),
'test_2' => vfsStream::url('root/test_2'),
]);
$discovery->addTranslatableProperty('title', 'title_context');
$definitions = $discovery->getDefinitions();
$this->assertCount(2, $definitions);
$plugin_1 = $definitions['test_plugin'];
$plugin_2 = $definitions['test_plugin2'];
$this->assertInstanceOf(TranslatableMarkup::class, $plugin_1['title']);
$this->assertEquals([], $plugin_1['title']->getOptions());
$this->assertInstanceOf(TranslatableMarkup::class, $plugin_2['title']);
$this->assertEquals([
'context' => 'test-context',
], $plugin_2['title']->getOptions());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.