function HelpTopicsSyntaxTest::verifyBadTopic

Same name in other branches
  1. 9 core/modules/help_topics/tests/src/Functional/HelpTopicsSyntaxTest.php \Drupal\Tests\help_topics\Functional\HelpTopicsSyntaxTest::verifyBadTopic()
  2. 8.9.x core/modules/help_topics/tests/src/Functional/HelpTopicsSyntaxTest.php \Drupal\Tests\help_topics\Functional\HelpTopicsSyntaxTest::verifyBadTopic()
  3. 11.x core/modules/help/tests/src/Functional/HelpTopicsSyntaxTest.php \Drupal\Tests\help\Functional\HelpTopicsSyntaxTest::verifyBadTopic()

Verifies that a bad topic fails in the expected way.

Parameters

string $id: ID of the topic to verify. It should start with "bad_help_topics.".

array $definitions: Array of all topic definitions, keyed by ID.

1 call to HelpTopicsSyntaxTest::verifyBadTopic()
HelpTopicsSyntaxTest::testHelpTopics in core/modules/help/tests/src/Functional/HelpTopicsSyntaxTest.php
Tests that all Core help topics can be rendered and have good syntax.

File

core/modules/help/tests/src/Functional/HelpTopicsSyntaxTest.php, line 235

Class

HelpTopicsSyntaxTest
Verifies that all core Help topics can be rendered and comply with standards.

Namespace

Drupal\Tests\help\Functional

Code

protected function verifyBadTopic($id, $definitions) {
    $bad_topic_type = substr($id, 16);
    // Topics should fail verifyTopic() in specific ways.
    $found_error = FALSE;
    try {
        $this->verifyTopic($id, $definitions, 404);
    } catch (ExpectationFailedException|AssertionFailedError $e) {
        $found_error = TRUE;
        $message = $e->getMessage();
        switch ($bad_topic_type) {
            case 'related':
                $this->assertStringContainsString('only related to topics that exist', $message);
                break;
            case 'bad_html':
            case 'bad_html2':
            case 'bad_html3':
                $this->assertStringContainsString('Opening and ending tag mismatch', $message);
                break;
            case 'top_level':
                $this->assertStringContainsString('is either top-level or related to at least one other top-level topic', $message);
                break;
            case 'empty':
                $this->assertStringContainsString('contains some text outside of front matter', $message);
                break;
            case 'translated':
                $this->assertStringContainsString('Twig file has all of its text translated', $message);
                break;
            case 'locale':
                $this->assertStringContainsString('translatable string is locale-safe', $message);
                break;
            case 'h1':
                $this->assertStringContainsString('has no H1 tag', $message);
                break;
            case 'hierarchy':
                $this->assertStringContainsString('has the correct H2-H6 heading hierarchy', $message);
                break;
            case 'url_func_used':
                $this->assertStringContainsString('appears to use the url() function', $message);
                break;
            default:
                // This was an unexpected error.
                throw $e;
        }
    }
    if (!$found_error) {
        $this->fail('Bad help topic ' . $bad_topic_type . ' did not fail as expected');
    }
}

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