You are here

protected function HelpTopicsSyntaxTest::verifyBadTopic in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/help_topics/tests/src/Functional/HelpTopicsSyntaxTest.php \Drupal\Tests\help_topics\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_topics/tests/src/Functional/HelpTopicsSyntaxTest.php
Tests that all Core help topics can be rendered and have good syntax.

File

core/modules/help_topics/tests/src/Functional/HelpTopicsSyntaxTest.php, line 215

Class

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

Namespace

Drupal\Tests\help_topics\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 'h1':
        $this
          ->assertStringContainsString('has no H1 tag', $message);
        break;
      case 'hierarchy':
        $this
          ->assertStringContainsString('has the correct H2-H6 heading hierarchy', $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');
  }
}