You are here

protected function AddressDefaultWidgetTest::setUp in Address 8

Overrides BrowserTestBase::setUp

File

tests/src/FunctionalJavascript/AddressDefaultWidgetTest.php, line 98

Class

AddressDefaultWidgetTest
Tests the default address widget.

Namespace

Drupal\Tests\address\FunctionalJavascript

Code

protected function setUp() : void {
  parent::setUp();

  // Create node bundle for tests.
  $type = NodeType::create([
    'name' => 'Article',
    'type' => 'article',
  ]);
  $type
    ->save();

  // Create user that will be used for tests.
  $this->adminUser = $this
    ->createUser([
    'create article content',
    'edit own article content',
    'administer content types',
    'administer node fields',
  ]);
  $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',
    'default_value' => [
      [
        'country_code' => 'US',
      ],
    ],
  ]);
  $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',
  ])
    ->save();
  $this->nodeAddUrl = 'node/add/article';
  $this->fieldConfigUrl = 'admin/structure/types/manage/article/fields/node.article.' . $this->field
    ->getName();
  $this->countryRepository = \Drupal::service('address.country_repository');
  $this->subdivisionRepository = \Drupal::service('address.subdivision_repository');
  $this->addressFormatRepository = \Drupal::service('address.address_format_repository');
}