public function AddressMapLinkConfigureTest::setUp in Address Map (& Directions) Link 8
Overrides BrowserTestBase::setUp
File
- tests/
src/ Functional/ AddressMapLinkConfigureTest.php, line 88
Class
- AddressMapLinkConfigureTest
- Class AddressMapLinkConfigureTest.
Namespace
Drupal\Tests\address_map_link\FunctionalCode
public function setUp() {
parent::setUp();
// Create content type.
$type = NodeType::create([
'name' => 'Article',
'type' => 'article',
]);
$type
->save();
// Create user that will be used for tests.
$this->adminUser = $this
->drupalCreateUser([
'create article content',
'edit own article content',
'administer content types',
'administer node fields',
'administer node display',
'administer display modes',
]);
$this
->drupalLogin($this->adminUser);
// Add the address field to the article content type.
$field_storage = FieldStorageConfig::create([
'field_name' => 'field_address',
'entity_type' => 'node',
'type' => 'address',
]);
$field_storage
->save();
$this->field = FieldConfig::create([
'field_storage' => $field_storage,
'bundle' => 'article',
'label' => 'Address',
]);
$this->field
->save();
// Set article's form display.
$this->formDisplay = EntityFormDisplay::load('node.article.default');
if (!$this->formDisplay) {
EntityFormDisplay::create([
'targetEntityType' => 'node',
'bundle' => 'article',
'mode' => 'default',
'status' => TRUE,
])
->save();
$this->formDisplay = EntityFormDisplay::load('node.article.default');
}
$this->formDisplay
->setComponent($this->field
->getName(), [
'type' => 'address_default',
'settings' => [
'default_country' => 'US',
],
])
->save();
// Configure default display mode settings.
$this->nodeViewDisplay = EntityViewDisplay::load('node.article.default');
if (!$this->nodeViewDisplay) {
EntityViewDisplay::create([
'targetEntityType' => 'node',
'bundle' => 'article',
'mode' => 'default',
'status' => TRUE,
'content' => [
$this->field
->getName() => [
'type' => 'address_plain',
'settings' => [],
'label' => 'hidden',
'third_party_settings' => [],
'weight' => 0,
],
],
])
->save();
$this->nodeViewDisplay = EntityViewDisplay::load('node.article.default');
}
$this->nodeAddUrl = 'node/add/article';
$this->nodeDisplayEditUrl = 'admin/structure/types/manage/article/display';
}