You are here

public function YamlDiscoveryTest::testGetDefinitionsWithTranslatableDefinitions in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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
Contains \Drupal\Tests\Core\Plugin\Discovery\YamlDiscoveryTest.

Class

YamlDiscoveryTest
@coversDefaultClass \Drupal\Core\Plugin\Discovery\YamlDiscovery @group Plugin

Namespace

Drupal\Tests\Core\Plugin\Discovery

Code

public function testGetDefinitionsWithTranslatableDefinitions() {
  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());
}