You are here

public function AmpDFPTestCase::testAmpDFP in Accelerated Mobile Pages (AMP) 7

Test AMP DFP.

File

modules/amp_dfp/tests/amp_dfp.test, line 49
Tests for amp_DFP.module.

Class

AmpDFPTestCase
@file Tests for amp_DFP.module.

Code

public function testAmpDFP() {

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

  // Enable AMP display on article content.
  $this
    ->drupalGet("admin/structure/types/manage/article/display");
  $this
    ->assertResponse(200);
  $edit = [
    "view_modes_custom[amp]" => '1',
  ];
  $this
    ->drupalPost(NULL, $edit, t('Save'));

  // Create DFP tag.
  $this
    ->drupalGet('admin/structure/dfp_ads/add');
  $this
    ->assertResponse(200);
  $edit = array(
    'machinename' => 'amp_ad',
    'slot' => 'AMP Ad',
    'size' => '300x250',
    'targeting[0][target]' => 'position',
    'targeting[0][value]' => '1',
  );
  $this
    ->drupalPost(NULL, $edit, t('Save'));

  // Create Sticky DFP tag.
  $this
    ->drupalGet('admin/structure/dfp_ads/add');
  $this
    ->assertResponse(200);
  $edit = array(
    'machinename' => 'amp_sticky_ad',
    'slot' => 'AMP Sticky Ad',
    'size' => '320x50',
    'amp_sticky' => '1',
  );
  $this
    ->drupalPost(NULL, $edit, t('Save'));

  // Blocks placement.
  $this
    ->drupalGet('/admin/structure/block/manage/dfp/amp_ad/configure');
  $this
    ->assertResponse(200);
  $edit = array(
    'regions[ampsubtheme_example]' => 'content',
  );
  $this
    ->drupalPost(NULL, $edit, t('Save block'));
  $this
    ->drupalGet('/admin/structure/block/manage/dfp/amp_sticky_ad/configure');
  $this
    ->assertResponse(200);
  $edit = array(
    'regions[ampsubtheme_example]' => 'content',
  );
  $this
    ->drupalPost(NULL, $edit, t('Save block'));

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

  // Check the full display.
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertResponse(200);
  $this
    ->assertNoRaw('<amp-ad');

  // Check the AMP display.
  $this
    ->drupalGet('node/' . $node->nid, array(
    'query' => array(
      'amp' => TRUE,
    ),
  ));
  $this
    ->assertResponse(200);
  $this
    ->assertPattern('|script src="https:\\/\\/cdn.ampproject.org\\/v0\\/amp-ad-0.1.js" async.*\\scustom-element="amp-ad"|');
  $this
    ->assertPattern('|amp-ad type="doubleclick"[\\s].*layout="responsive"[\\s].*height="250"[\\s].*width="300"[\\s].*data-slot="\\/1\\/"[\\s].*json=\'{"targeting":{"position":"1"}}\'|');
  $this
    ->assertPattern('|script src="https:\\/\\/cdn.ampproject.org\\/v0\\/amp-sticky-ad-1.0.js" async.*\\scustom-element="amp-sticky-ad"|');
  $this
    ->assertPattern('|amp-ad type="doubleclick"[\\s].*height="50"[\\s].*width="320"[\\s].*data-slot="\\/1\\/sticky"[\\s]|');
  $this
    ->assertRaw('</amp-ad>');
}