protected function AmpTestContext::setUp in Accelerated Mobile Pages (AMP) 7
Sets up a Drupal site for running functional and integration tests.
Generates a random database prefix and installs Drupal with the specified installation profile in DrupalWebTestCase::$profile into the prefixed database. Afterwards, installs any additional modules specified by the test.
After installation all caches are flushed and several configuration values are reset to the values of the parent site executing the test, since the default values may be incompatible with the environment in which tests are being executed.
Parameters
...: List of modules to enable for the duration of the test. This can be either a single array or a variable number of string arguments.
Overrides DrupalWebTestCase::setUp
See also
DrupalWebTestCase::prepareDatabasePrefix()
DrupalWebTestCase::changeDatabasePrefix()
DrupalWebTestCase::prepareEnvironment()
File
- modules/
amp_context/ tests/ amp_context.test, line 21 - Tests for amp_context.module.
Class
- AmpTestContext
- @file Tests for amp_context.module.
Code
protected function setUp() {
// Enable modules.
parent::setUp('field_ui', 'amp_test', 'context_ui', 'amp_context');
theme_enable(array(
'amptheme',
'ampsubtheme_example',
));
// Clean registry to make plugin available.
registry_update();
// Create Admin user.
$this->adminUser = $this
->drupalCreateUser(array(
'access administration pages',
'administer content types',
'administer site configuration',
'administer contexts',
'administer fields',
'create article content',
));
$this
->drupalLogin($this->adminUser);
// 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 a context programmatically.
ctools_include('export');
$context = ctools_export_new_object('context');
$context->name = 'is_amp_page';
$context->description = 'Evaluates if the current page is an AMP page';
$context->tag = 'AMP';
$context->conditions = array(
'is_amp_request' => array(
'values' => array(
1 => 1,
),
),
);
$context->reactions = array(
'debug' => array(
'debug' => TRUE,
),
);
context_save($context);
// Create a sitewide context.
ctools_include('export');
$context = ctools_export_new_object('context');
$context->name = 'sitewide';
$context->description = 'Sitewide context';
$context->tag = 'AMP';
$context->conditions = array(
'sitewide' => array(
'values' => array(
1 => 1,
),
),
);
$context->reactions = array(
'debug' => array(
'debug' => TRUE,
),
);
context_save($context);
}