You are here

public function FieldSettingsTest::testBaseFieldSettingsOnClone in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Field/FieldSettingsTest.php \Drupal\KernelTests\Core\Field\FieldSettingsTest::testBaseFieldSettingsOnClone()

Tests the base field settings on a cloned base field definition object.

File

core/tests/Drupal/KernelTests/Core/Field/FieldSettingsTest.php, line 52

Class

FieldSettingsTest
Tests field settings methods on field definition structures.

Namespace

Drupal\KernelTests\Core\Field

Code

public function testBaseFieldSettingsOnClone() {
  $base_field = BaseFieldDefinition::create('test_field');

  // Check that the default settings have been populated.
  $expected_settings = [
    'test_field_storage_setting' => 'dummy test string',
    'changeable' => 'a changeable field storage setting',
    'unchangeable' => 'an unchangeable field storage setting',
    'translatable_storage_setting' => 'a translatable field storage setting',
    'test_field_setting' => 'dummy test string',
    'translatable_field_setting' => 'a translatable field setting',
  ];
  $this
    ->assertEquals($expected_settings, $base_field
    ->getSettings());

  // Clone the base field object and change one single setting using
  // setSettings() on the cloned base field and check that it has been
  // changed only on the cloned object.
  $clone_base_field = clone $base_field;
  $expected_settings_clone = $expected_settings;
  $expected_settings_clone['changeable'] = $expected_settings['changeable'] . ' (clone)';
  $clone_base_field
    ->setSetting('changeable', $expected_settings_clone['changeable']);
  $this
    ->assertEquals($expected_settings, $base_field
    ->getSettings());
  $this
    ->assertEquals($expected_settings_clone, $clone_base_field
    ->getSettings());
}