function HelpTopicDiscoveryTest::testHelpTopicsDefinition

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

@covers ::findAll

File

core/modules/help/tests/src/Unit/HelpTopicDiscoveryTest.php, line 206

Class

HelpTopicDiscoveryTest
@coversDefaultClass \Drupal\help\HelpTopicDiscovery[[api-linebreak]] @group help

Namespace

Drupal\Tests\help\Unit

Code

public function testHelpTopicsDefinition() : void {
  $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']);
}

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