function HelpTopicDiscoveryTest::testHelpTopicsDefinition

Same name and namespace in other branches
  1. 8.9.x core/modules/help_topics/tests/src/Unit/HelpTopicDiscoveryTest.php \Drupal\Tests\help_topics\Unit\HelpTopicDiscoveryTest::testHelpTopicsDefinition()
  2. 10 core/modules/help/tests/src/Unit/HelpTopicDiscoveryTest.php \Drupal\Tests\help\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_topics/tests/src/Unit/HelpTopicDiscoveryTest.php, line 226

Class

HelpTopicDiscoveryTest
@coversDefaultClass <a href="/api/drupal/core%21modules%21help_topics%21src%21HelpTopicDiscovery.php/class/HelpTopicDiscovery/9" title="Discovers help topic plugins from Twig files in help_topics directories." class="local">\Drupal\help_topics\HelpTopicDiscovery</a> @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']);
}

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