amp_analytics.test in Accelerated Mobile Pages (AMP) 7
Tests for amp_analytics.module.
File
modules/amp_analytics/tests/amp_analytics.testView source
<?php
/**
* @file
* Tests for amp_analytics.module.
*/
class AmpAnalyticsTestCase extends DrupalWebTestCase {
protected $profile = 'standard';
protected $admin_user;
public static function getInfo() {
return array(
'name' => 'AMP Analytics',
'description' => 'Tests for the AMP Analytics module.',
'group' => 'AMP',
);
}
protected function setUp() {
// Enable AMP module.
parent::setUp('field_ui', 'amp_test', 'amp_analytics');
theme_enable(array(
'amptheme',
'ampsubtheme_example',
));
// Create Admin user.
$this->admin_user = $this
->drupalCreateUser(array(
'administer content types',
'administer fields',
'administer site configuration',
));
$this
->drupalLogin($this->admin_user);
// @todo Install the AMP theme.
//theme_enable(array('amptheme', 'ampsubtheme_example'));
}
/**
* Test AMP analytics.
*/
public function testAmpAnalytics() {
// Login as an admin user.
$this
->drupalLogin($this->admin_user);
// Configure AMP analytics.
$this
->drupalGet('admin/config/content/amp/analytics');
$this
->assertResponse(200);
$edit = [
"amp_google_analytics_id" => 'UA-11111-1',
];
$this
->drupalPost(NULL, $edit, t('Save configuration'));
// Create a node to test AMP metadata.
$node = $this
->drupalCreateNode(array(
'type' => 'article',
));
// 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'));
// Check the full display.
$this
->drupalGet('node/' . $node->nid);
$this
->assertResponse(200);
$this
->assertNoRaw('<amp-analytics type="googleanalytics">');
// 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-analytics-0.1.js" async.*\\scustom-element="amp-analytics"|');
$this
->assertRaw('<amp-analytics type="googleanalytics">');
$this
->assertRaw('<script type="application/json">');
$this
->assertRaw('{"vars":{"account":"UA-11111-1"},"triggers":{"trackAmpview":{"on":"visible","request":"pageview"}}}');
$this
->assertRaw('</amp-analytics>');
}
}
Classes
Name | Description |
---|---|
AmpAnalyticsTestCase | @file Tests for amp_analytics.module. |