protected function AmpTestBase::setUp in Accelerated Mobile Pages (AMP) 8.3
Same name and namespace in other branches
- 8.2 tests/src/Functional/AmpTestBase.php \Drupal\Tests\amp\Functional\AmpTestBase::setUp()
Overrides BrowserTestBase::setUp
1 call to AmpTestBase::setUp()
- AmpFormatterTestBase::setUp in tests/
src/ Functional/ AmpFormatterTestBase.php
1 method overrides AmpTestBase::setUp()
- AmpFormatterTestBase::setUp in tests/
src/ Functional/ AmpFormatterTestBase.php
File
- tests/
src/ Functional/ AmpTestBase.php, line 108
Class
- AmpTestBase
- Base AMP testing setup.
Namespace
Drupal\Tests\amp\FunctionalCode
protected function setUp() {
parent::setUp();
$this->fixturesPath = str_replace('/tests/src/Functional', '/tests/fixtures', dirname(__FILE__));
// Set up full html filter.
$full_html_format = FilterFormat::create([
'format' => 'full_html',
'name' => 'Full HTML',
'weight' => 1,
'filters' => [],
]);
$full_html_format
->save();
user_role_grant_permissions('authenticated', [
$full_html_format
->getPermissionName(),
]);
// Install the theme.
// @see https://www.drupal.org/node/2232651
$this->container
->get('theme_installer')
->install([
'bartik',
'seven',
'ampsubtheme_example',
]);
$this->container
->get('config.factory')
->getEditable('system.theme')
->set('default', 'bartik')
->set('admin', 'seven')
->save();
// Populate variables.
$this->contentType = strtolower($this
->randomMachineName());
$this->displayRepository = \Drupal::service('entity_display.repository');
// Create node type.
$this
->createContentType([
'type' => $this->contentType,
'name' => $this->contentType,
]);
// Login as an admin user.
$this->adminUser = $this
->drupalCreateUser($this->permissions);
// Enable user pictures on nodes.
$this
->config('system.theme.global')
->set('features.node_user_picture', TRUE)
->save();
$this
->drupalLogin($this->adminUser);
$this
->assertTrue($full_html_format
->access('use', $this->adminUser), 'Admin user may use permission: ' . $full_html_format
->getPermissionName());
// Configure AMP.
$amp_settings_url = Url::fromRoute("amp.settings")
->toString();
$this
->drupalGet($amp_settings_url);
$edit = [
'amptheme' => 'ampsubtheme_example',
];
$this
->submitForm($edit, t('Save configuration'));
// Enable AMP display on node content.
$node_type_url = Url::fromRoute("entity.entity_view_display.node.default", [
'node_type' => $this->contentType,
])
->toString();
$this
->drupalGet($node_type_url);
$this
->assertSession()
->statusCodeEquals(200);
$edit = [
'display_modes_custom[amp]' => 'amp',
];
$this
->submitForm($edit, t('Save'));
// Configure view modes and field formatters.
$this->displayRepository
->getViewDisplay('node', $this->contentType, 'amp')
->setComponent('body', [
'type' => 'amp_text',
'settings' => [],
])
->save();
$this->displayRepository
->getViewDisplay('user', 'user', 'compact')
->removeComponent('member_for')
->save();
// Make sure Metatag canonical link is NOT configured, it does not
// behave properly in tests, although it works on actual sites.
\Drupal::configFactory()
->getEditable('metatag.metatag_defaults.node')
->set('tags.canonical_url', '')
->save(TRUE);
}