You are here

public function IntegrationTest::checkCdfMarkup in Acquia Content Hub 8

Ensures the rendered view mode have no extra markup.

Parameters

\Drupal\node\NodeInterface $entity: The entity to be used.

1 call to IntegrationTest::checkCdfMarkup()
IntegrationTest::testFramework in tests/src/Functional/IntegrationTest.php
Tests various operations via the Acquia Content Hub admin UI.

File

tests/src/Functional/IntegrationTest.php, line 274

Class

IntegrationTest
Tests the overall functionality of the Acquia Content Hub module.

Namespace

Drupal\Tests\acquia_contenthub\Functional

Code

public function checkCdfMarkup(NodeInterface $entity) {
  $this
    ->enableViewModeFor('node', 'article', [
    'default',
    'full',
    'teaser',
  ]);
  $output = $this
    ->drupalGetCdf('acquia-contenthub-cdf/' . $entity
    ->getEntityTypeId() . '/' . $entity
    ->id());

  // Drupal 8.5 has added off-canvas links to the main template.
  // https://www.drupal.org/project/drupal/issues/2784443
  $dialog_off_canvas_openning = floatval(\Drupal::VERSION) <= 8.4 ? '' : '<div class="dialog-off-canvas-main-canvas" data-off-canvas-main-canvas>';
  $dialog_off_canvas_closing = floatval(\Drupal::VERSION) <= 8.4 ? '' : '</div>';
  $this
    ->setRawContent($output['entities'][0]['metadata']['view_modes']['default']['html']);
  $this
    ->removeWhiteSpace();
  $expected = '</head><body>' . $dialog_off_canvas_openning . '<article role="article" class="node node--type-article node--promoted node--view-mode-default"><h2><a href="/node/1" rel="bookmark"><span class="field field--name-title field--type-string field--label-hidden">';
  $this
    ->assertRaw($expected, 'Default view mode have no extra markup.');
  $expected = '</article>' . $dialog_off_canvas_closing . '<div data-content-barrier-exclude="true"></div></body></html>';
  $this
    ->assertRaw($expected, 'Default view mode footer JS is wrapped into div with data-content-barrier-exclude attribute.');
  $this
    ->setRawContent($output['entities'][0]['metadata']['view_modes']['full']['html']);
  $this
    ->removeWhiteSpace();
  $expected = '</head><body>' . $dialog_off_canvas_openning . '<article role="article" class="node node--type-article node--promoted node--view-mode-full"><h2><a href="/node/1" rel="bookmark"><span class="field field--name-title field--type-string field--label-hidden">';
  $this
    ->assertRaw($expected, 'Full view mode have no extra markup.');
  $expected = '</article>' . $dialog_off_canvas_closing . '<div data-content-barrier-exclude="true"></div></body></html>';
  $this
    ->assertRaw($expected, 'Full view mode footer JS is wrapped into div with data-content-barrier-exclude attribute.');
  $this
    ->setRawContent($output['entities'][0]['metadata']['view_modes']['teaser']['html']);
  $this
    ->removeWhiteSpace();
  $expected = '</head><body>' . $dialog_off_canvas_openning . '<article role="article" class="node node--type-article node--promoted node--view-mode-teaser"><h2><a href="/node/1" rel="bookmark"><span class="field field--name-title field--type-string field--label-hidden">';
  $this
    ->assertRaw($expected, 'Teaser view mode have no extra markup.');
  $expected = '</article>' . $dialog_off_canvas_closing . '<div data-content-barrier-exclude="true"></div></body></html>';
  $this
    ->assertRaw($expected, 'Teaser view mode footer JS is wrapped into div with data-content-barrier-exclude attribute.');
  $this
    ->enableViewModeFor('node', 'article', 'teaser');
}