You are here

public function DynamicEntityReferenceItemTest::testSelectionHandlerSettings in Dynamic Entity Reference 8.2

Same name and namespace in other branches
  1. 8 tests/src/Kernel/DynamicEntityReferenceItemTest.php \Drupal\Tests\dynamic_entity_reference\Kernel\DynamicEntityReferenceItemTest::testSelectionHandlerSettings()

Tests that the 'handler' field setting stores the proper plugin ID.

File

tests/src/Kernel/DynamicEntityReferenceItemTest.php, line 344

Class

DynamicEntityReferenceItemTest
Tests the new entity API for the dynamic entity reference field type.

Namespace

Drupal\Tests\dynamic_entity_reference\Kernel

Code

public function testSelectionHandlerSettings() {
  $field_name = mb_strtolower($this
    ->randomMachineName());
  $field_storage = FieldStorageConfig::create([
    'field_name' => $field_name,
    'entity_type' => 'entity_test',
    'type' => 'dynamic_entity_reference',
    'settings' => [
      'exclude_entity_types' => FALSE,
      'entity_type_ids' => [
        'entity_test',
      ],
    ],
  ]);
  $field_storage
    ->save();

  // Do not specify any value for the 'handler' setting in order to verify
  // that the default value is properly used.
  $field = FieldConfig::create([
    'field_storage' => $field_storage,
    'bundle' => 'entity_test',
  ]);
  $field
    ->save();
  $field = FieldConfig::load($field
    ->id());
  $field_settings = $field
    ->getSettings();
  $this
    ->assertTrue($field_settings['entity_test']['handler'] == 'default:entity_test');
  $field_settings['entity_test']['handler'] = 'views';
  $field
    ->setSettings($field_settings);
  $field
    ->save();
  $field = FieldConfig::load($field
    ->id());
  $field_settings = $field
    ->getSettings();
  $this
    ->assertTrue($field_settings['entity_test']['handler'] == 'views');
}