public function YamlDirectoryDiscoveryTest::testGetDefinitionsWithTranslatableDefinitions in Drupal 9
Same name and namespace in other branches
- 8 core/tests/Drupal/Tests/Core/Plugin/Discovery/YamlDirectoryDiscoveryTest.php \Drupal\Tests\Core\Plugin\Discovery\YamlDirectoryDiscoveryTest::testGetDefinitionsWithTranslatableDefinitions()
@covers ::getDefinitions
File
- core/
tests/ Drupal/ Tests/ Core/ Plugin/ Discovery/ YamlDirectoryDiscoveryTest.php, line 69
Class
- YamlDirectoryDiscoveryTest
- @coversDefaultClass \Drupal\Core\Plugin\Discovery\YamlDirectoryDiscovery
Namespace
Drupal\Tests\Core\Plugin\DiscoveryCode
public function testGetDefinitionsWithTranslatableDefinitions() {
vfsStream::setup('modules', NULL, [
'module_a' => [
'subdir1' => [
'plugin1.yml' => "id: plugin1\ntest_provider: module_a\ntitle: 'test title'",
'plugin2.yml' => "id: plugin2\ntest_provider: module_a\ntitle: 'test title'\ntitle_context: test-context",
],
],
]);
$directories = [
'module_a' => vfsStream::url('modules/module_a/subdir1'),
];
$discovery = new YamlDirectoryDiscovery($directories, 'test');
$discovery
->addTranslatableProperty('title', 'title_context');
$definitions = $discovery
->getDefinitions();
$this
->assertCount(2, $definitions);
$plugin_1 = $definitions['plugin1'];
$plugin_2 = $definitions['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());
}