You are here

protected function DynamicEntityReferenceWidgetTest::setUp in Dynamic Entity Reference 8

Same name and namespace in other branches
  1. 8.2 tests/src/Functional/DynamicEntityReferenceWidgetTest.php \Drupal\Tests\dynamic_entity_reference\Functional\DynamicEntityReferenceWidgetTest::setUp()

Sets up a Drupal site for running functional and integration tests.

Overrides BrowserTestBase::setUp

File

tests/src/Functional/DynamicEntityReferenceWidgetTest.php, line 64

Class

DynamicEntityReferenceWidgetTest
Tests dynamic entity reference field widgets.

Namespace

Drupal\Tests\dynamic_entity_reference\Functional

Code

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

  // Create default content type.
  $this
    ->drupalCreateContentType([
    'type' => 'reference_content',
  ]);
  $this
    ->drupalCreateContentType([
    'type' => 'referenced_content',
  ]);

  // Create admin user.
  $this->adminUser = $this
    ->drupalCreateUser($this->permissions);
  $field_name = mb_strtolower($this
    ->randomMachineName());
  $field_storage = FieldStorageConfig::create([
    'field_name' => $field_name,
    'entity_type' => 'node',
    'type' => 'dynamic_entity_reference',
    'settings' => [
      'exclude_entity_types' => FALSE,
      'entity_type_ids' => [
        'node',
      ],
    ],
  ]);
  $field_storage
    ->save();
  FieldConfig::create([
    'field_storage' => $field_storage,
    'bundle' => 'reference_content',
    'settings' => [
      'node' => [
        'handler' => 'default',
        'handler_settings' => [
          'target_bundles' => [
            'referenced_content',
          ],
          'sort' => [
            'field' => '_none',
          ],
        ],
      ],
    ],
  ])
    ->save();
  $this->fieldName = $field_name;
}