You are here

protected function TestBase::setUp in Double Field 4.x

Same name in this branch
  1. 4.x tests/src/Functional/TestBase.php \Drupal\Tests\double_field\Functional\TestBase::setUp()
  2. 4.x tests/src/FunctionalJavascript/TestBase.php \Drupal\Tests\double_field\FunctionalJavascript\TestBase::setUp()
Same name and namespace in other branches
  1. 8.3 tests/src/Functional/TestBase.php \Drupal\Tests\double_field\Functional\TestBase::setUp()

Overrides BrowserTestBase::setUp

1 call to TestBase::setUp()
DateTimezoneTest::setUp in tests/src/Functional/DateTimezoneTest.php
1 method overrides TestBase::setUp()
DateTimezoneTest::setUp in tests/src/Functional/DateTimezoneTest.php

File

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

Class

TestBase
Tests the creation of text fields.

Namespace

Drupal\Tests\double_field\Functional

Code

protected function setUp() : void {
  parent::setUp();
  $this->fieldName = strtolower($this
    ->randomMachineName());
  $this->contentTypeId = $this
    ->drupalCreateContentType([
    'type' => $this
      ->randomMachineName(),
  ])
    ->id();
  $this->fieldAdminPath = "admin/structure/types/manage/{$this->contentTypeId}/fields/node.{$this->contentTypeId}.{$this->fieldName}";
  $this->fieldStorageAdminPath = $this->fieldAdminPath . '/storage';
  $permissions = [
    'administer content types',
    'administer node fields',
    'administer nodes',
    'administer node form display',
    'administer node display',
    "edit any {$this->contentTypeId} content",
    "delete any {$this->contentTypeId} content",
  ];
  $admin_user = $this
    ->drupalCreateUser($permissions, NULL, NULL, [
    'timezone' => 'Europe/Moscow',
  ]);
  $this
    ->drupalLogin($admin_user);

  // Create a field storage for testing.
  $storage_settings['storage'] = [
    'first' => [
      'type' => 'string',
      'maxlength' => 50,
      'precision' => 10,
      'scale' => 2,
      'datetime_type' => 'datetime',
    ],
    'second' => [
      'type' => 'string',
      'maxlength' => 50,
      'precision' => 10,
      'scale' => 2,
      'datetime_type' => 'datetime',
    ],
  ];
  $this->fieldStorage = FieldStorageConfig::create([
    'field_name' => $this->fieldName,
    'entity_type' => 'node',
    'type' => 'double_field',
    'settings' => $storage_settings,
  ]);
  $this->fieldStorage
    ->save();

  // Create a field storage for testing.
  $this->field = FieldConfig::create([
    'field_storage' => $this->fieldStorage,
    'bundle' => $this->contentTypeId,
    'required' => TRUE,
  ]);
  $this->field
    ->save();
  $this
    ->saveWidgetSettings([]);
  $this
    ->saveFormatterSettings('unformatted_list');
}