You are here

public function FileUrlFieldItemTest::testSelectionHandlerSettings in File URL 2.0.x

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

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

See also

\Drupal\Tests\field\Kernel\EntityReference\EntityReferenceItemTest::testSelectionHandlerSettings()

File

tests/src/Kernel/FileUrlFieldItemTest.php, line 27

Class

FileUrlFieldItemTest
Tests the file_url field item.

Namespace

Drupal\Tests\file_url\Kernel

Code

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

  // Do not specify any value for the 'handler' setting in order to verify
  // that the default handler with the correct derivative is used.
  $field = FieldConfig::create([
    'field_storage' => $field_storage,
    'bundle' => 'entity_test',
  ]);
  $field
    ->save();
  $field = FieldConfig::load($field
    ->id());
  $this
    ->assertEquals($field
    ->getSetting('handler'), 'file_url_default:file');
}