function FieldImportChangeTest::testImportChange

Tests importing an updated field instance.

File

drupal/core/modules/field/lib/Drupal/field/Tests/FieldImportChangeTest.php, line 33
Contains \Drupal\field\Tests\FieldImportChangeTest.

Class

FieldImportChangeTest
Tests updating fields and instances as part of config import.

Namespace

Drupal\field\Tests

Code

function testImportChange() {
  $field_id = 'field_test_import';
  $instance_id = "test_entity.test_bundle.{$field_id}";
  $instance_config_name = "field.instance.{$instance_id}";

  // Import default config.
  $this
    ->installConfig(array(
    'field_test_config',
  ));
  $active = $this->container
    ->get('config.storage');
  $staging = $this->container
    ->get('config.storage.staging');
  $this
    ->copyConfig($active, $staging);

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

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

  // Check that the updated config was correctly imported.
  $instance = entity_load('field_instance', $instance_id);
  $this
    ->assertEqual($instance['label'], $new_label, 'Instance label updated');
}