View source
<?php
namespace Drupal\Tests\address_map_link\Functional;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\node\Entity\NodeType;
use Drupal\Tests\BrowserTestBase;
class AddressMapLinkConfigureTest extends BrowserTestBase {
public static $modules = [
'system',
'language',
'user',
'field',
'field_ui',
'node',
'address',
'address_map_link',
];
protected $node;
protected $adminUser;
protected $field;
protected $formDisplay;
protected $nodeAddUrl;
protected $nodeDisplayEditUrl;
protected $nodeViewDisplay;
public function setUp() {
parent::setUp();
$type = NodeType::create([
'name' => 'Article',
'type' => 'article',
]);
$type
->save();
$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);
$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();
$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();
$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';
}
public function testConfigureAddressMapLink() {
$field_name = $this->field
->getName();
$this
->drupalGet($this->nodeDisplayEditUrl);
$this
->assertNotEmpty((bool) $this
->xpath('//select[@name="fields[' . $field_name . '][type]"]'), 'Address field formatter shown as required.');
$this
->assertTrue($this
->contains('Linked Address: Not Linked'));
$this
->assertTrue($this
->contains('Map Link Type'), 'true');
$this
->assertTrue($this
->contains('Map Link Position'), 'true');
}
}