function YamlDirectoryDiscoveryTest::testGetDefinitionsWithTranslatableDefinitions

Same name in other branches
  1. 8.9.x core/tests/Drupal/Tests/Core/Plugin/Discovery/YamlDirectoryDiscoveryTest.php \Drupal\Tests\Core\Plugin\Discovery\YamlDirectoryDiscoveryTest::testGetDefinitionsWithTranslatableDefinitions()
  2. 10 core/tests/Drupal/Tests/Core/Plugin/Discovery/YamlDirectoryDiscoveryTest.php \Drupal\Tests\Core\Plugin\Discovery\YamlDirectoryDiscoveryTest::testGetDefinitionsWithTranslatableDefinitions()
  3. 11.x 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\Discovery

Code

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());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.