You are here

protected function PhoneInternationalFieldTest::setUp in International Phone 8

Same name and namespace in other branches
  1. 8.2 tests/src/Functional/PhoneInternationalFieldTest.php \Drupal\Tests\phone_international\Functional\PhoneInternationalFieldTest::setUp()
  2. 3.x tests/src/Functional/PhoneInternationalFieldTest.php \Drupal\Tests\phone_international\Functional\PhoneInternationalFieldTest::setUp()

Overrides BrowserTestBase::setUp

File

tests/src/Functional/PhoneInternationalFieldTest.php, line 80

Class

PhoneInternationalFieldTest
Simple test to ensure that main page loads with module enabled.

Namespace

Drupal\Tests\phone_international\Functional

Code

protected function setUp() {
  parent::setUp();
  $this
    ->drupalCreateContentType([
    'type' => 'article',
  ]);
  $this->webUser = $this
    ->drupalCreateUser([
    'create article content',
    'edit own article content',
  ]);
  $this
    ->drupalLogin($this->webUser);

  // Add the telephone field to the article content type.
  FieldStorageConfig::create([
    'field_name' => 'field_phone_international',
    'entity_type' => 'node',
    'type' => 'phone_international',
  ])
    ->save();
  FieldConfig::create([
    'field_name' => 'field_phone_international',
    'label' => 'International Phone Number',
    'entity_type' => 'node',
    'bundle' => 'article',
  ])
    ->save();

  /** @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface $display_repository */
  $display_repository = Drupal::service('entity_display.repository');
  $display_repository
    ->getFormDisplay('node', 'article')
    ->setComponent('field_phone_international', [
    'type' => 'phone_international_widget',
    'settings' => [
      'geolocation' => 'PT',
      'initial_country' => 0,
    ],
  ])
    ->save();
  $display_repository
    ->getViewDisplay('node', 'article')
    ->setComponent('field_phone_international', [
    'type' => 'phone_international_formatter',
    'weight' => 1,
  ])
    ->save();
}