You are here

public function HelpTopicDiscoveryTest::testHelpTopicsDefinition in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/help_topics/tests/src/Unit/HelpTopicDiscoveryTest.php \Drupal\Tests\help_topics\Unit\HelpTopicDiscoveryTest::testHelpTopicsDefinition()
  2. 9 core/modules/help_topics/tests/src/Unit/HelpTopicDiscoveryTest.php \Drupal\Tests\help_topics\Unit\HelpTopicDiscoveryTest::testHelpTopicsDefinition()

@covers ::findAll

File

core/modules/help_topics/tests/src/Unit/HelpTopicDiscoveryTest.php, line 226

Class

HelpTopicDiscoveryTest
@coversDefaultClass \Drupal\help_topics\HelpTopicDiscovery @group help_topics

Namespace

Drupal\Tests\help_topics\Unit

Code

public function testHelpTopicsDefinition() {
  $container = new ContainerBuilder();
  $container
    ->set('string_translation', $this
    ->getStringTranslationStub());
  \Drupal::setContainer($container);
  vfsStream::setup('root');
  $topic_content = <<<EOF
---
label: 'Test'
top_level: true
related:
  - one
  - two
  - three
---
<h2>Test</h2>
EOF;
  vfsStream::create([
    'modules' => [
      'foo' => [
        'help_topics' => [
          'foo.topic.html.twig' => $topic_content,
        ],
      ],
    ],
  ]);
  $discovery = new HelpTopicDiscovery([
    'foo' => vfsStream::url('root/modules/foo/help_topics'),
  ]);
  $definition = $discovery
    ->getDefinitions()['foo.topic'];
  $this
    ->assertEquals('Test', $definition['label']);
  $this
    ->assertInstanceOf(TranslatableMarkup::class, $definition['label']);
  $this
    ->assertTrue($definition['top_level']);

  // Each related plugin ID should be trimmed.
  $this
    ->assertSame([
    'one',
    'two',
    'three',
  ], $definition['related']);
  $this
    ->assertSame('foo', $definition['provider']);
  $this
    ->assertSame(HelpTopicTwig::class, $definition['class']);
  $this
    ->assertSame(vfsStream::url('root/modules/foo/help_topics/foo.topic.html.twig'), $definition['_discovered_file_path']);
  $this
    ->assertSame('foo.topic', $definition['id']);
}