You are here

public function AmpViewModeTest::testAmpViewMode in Accelerated Mobile Pages (AMP) 8.3

Same name and namespace in other branches
  1. 8.2 tests/src/Functional/AmpViewModeTest.php \Drupal\Tests\amp\Functional\AmpViewModeTest::testAmpViewMode()

Test the AMP view mode is viewable and contains basic metadata.

File

tests/src/Functional/AmpViewModeTest.php, line 17

Class

AmpViewModeTest
Tests AMP view mode.

Namespace

Drupal\Tests\amp\Functional

Code

public function testAmpViewMode() {

  // Create a node to test AMP field formatters.
  $this
    ->createAmpNode();
  $text = $this->node
    ->get('body')->value;
  $title = $this->node
    ->get('title')->value;

  // Check that the AMP view mode is available.
  $view_modes_url = Url::fromRoute('entity.entity_view_mode.collection')
    ->toString();
  $this
    ->drupalGet($view_modes_url);
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->pageTextContains('AMP');

  // Check the metadata of the full display mode.
  $this
    ->drupalGet($this
    ->nodeUrl());
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->responseContains($text);
  $this
    ->assertSession()
    ->responseContains($title);
  $this
    ->assertSession()
    ->responseContains('link rel="amphtml" href="' . $this
    ->nodeAmpUrl() . '"');
  $this
    ->assertSession()
    ->responseHeaderEquals('Link', '<' . $this
    ->nodeAmpUrl() . '> rel="amphtml"');

  // Check the metadata of the AMP display mode.
  $this
    ->drupalGet($this
    ->nodeAmpUrl());
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->responseContains($text);
  $this
    ->assertSession()
    ->responseContains($title);
  $this
    ->assertSession()
    ->responseContains('link rel="canonical" href="' . $this
    ->nodeUrl() . '"');
}