You are here

public function FieldImportChangeTest::testImportChange in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/field/tests/src/Kernel/FieldImportChangeTest.php \Drupal\Tests\field\Kernel\FieldImportChangeTest::testImportChange()
  2. 9 core/modules/field/tests/src/Kernel/FieldImportChangeTest.php \Drupal\Tests\field\Kernel\FieldImportChangeTest::testImportChange()

Tests importing an updated field.

File

core/modules/field/tests/src/Kernel/FieldImportChangeTest.php, line 28

Class

FieldImportChangeTest
Update field storage and fields during config change method invocation.

Namespace

Drupal\Tests\field\Kernel

Code

public function testImportChange() {
  $this
    ->installConfig([
    'field_test_config',
  ]);
  $field_storage_id = 'field_test_import';
  $field_id = "entity_test.entity_test.{$field_storage_id}";
  $field_config_name = "field.field.{$field_id}";
  $active = $this->container
    ->get('config.storage');
  $sync = $this->container
    ->get('config.storage.sync');
  $this
    ->copyConfig($active, $sync);

  // Save as files in the sync directory.
  $field = $active
    ->read($field_config_name);
  $new_label = 'Test update import field';
  $field['label'] = $new_label;
  $sync
    ->write($field_config_name, $field);

  // Import the content of the sync directory.
  $this
    ->configImporter()
    ->import();

  // Check that the updated config was correctly imported.
  $field = FieldConfig::load($field_id);
  $this
    ->assertEquals($new_label, $field
    ->getLabel(), 'field label updated');
}