You are here

public function AmpTestContext::testAmpContextCondition in Accelerated Mobile Pages (AMP) 7

Test the AMP context condition.

File

modules/amp_context/tests/amp_context.test, line 90
Tests for amp_context.module.

Class

AmpTestContext
@file Tests for amp_context.module.

Code

public function testAmpContextCondition() {

  // Login as an admin user.
  $this
    ->drupalLogin($this->adminUser);

  // Create a node to test AMP metadata.
  $node = $this
    ->drupalCreateNode(array(
    'type' => 'article',
  ));

  // Check context on non amp page.
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertResponse(200);
  $this
    ->assertNoPattern("|Active context:.*<a href.*is_amp_page<\\/a>|");

  // With ?amp.
  $this
    ->drupalGet('node/' . $node->nid, array(
    'query' => array(
      'amp' => TRUE,
    ),
  ));
  $this
    ->assertResponse(200);
  $this
    ->assertPattern("|Active context:.*<a href.*is_amp_page<\\/a>|");

  // Sitewide context should not appear on AMP page.
  $this
    ->assertNoPattern("|Active context:.*<a href.*sitewide<\\/a>|");

  // Turn off global switch to disable non AMP contexts.
  $this
    ->drupalGet('admin/config/content/amp');
  $this
    ->assertResponse(200);
  $edit = [
    'amp_context_disable_non_amp_contexts' => FALSE,
  ];
  $this
    ->drupalPost(NULL, $edit, t('Save configuration'));

  // Sitewide context will now appear on AMP pages.
  $this
    ->drupalGet('node/' . $node->nid, array(
    'query' => array(
      'amp' => TRUE,
    ),
  ));
  $this
    ->assertResponse(200);
  $this
    ->assertPattern("|Active context:.*<a href.*is_amp_page<\\/a>|");
  $this
    ->assertPattern("|Active context:.*<a href.*sitewide<\\/a>|");
}