You are here

public function AssertConfigEntityImportTrait::assertConfigEntityImport in Drupal 8

Same name in this branch
  1. 8 core/modules/config/src/Tests/AssertConfigEntityImportTrait.php \Drupal\config\Tests\AssertConfigEntityImportTrait::assertConfigEntityImport()
  2. 8 core/modules/config/tests/src/Traits/AssertConfigEntityImportTrait.php \Drupal\Tests\config\Traits\AssertConfigEntityImportTrait::assertConfigEntityImport()
Same name and namespace in other branches
  1. 9 core/modules/config/tests/src/Traits/AssertConfigEntityImportTrait.php \Drupal\Tests\config\Traits\AssertConfigEntityImportTrait::assertConfigEntityImport()
  2. 10 core/modules/config/tests/src/Traits/AssertConfigEntityImportTrait.php \Drupal\Tests\config\Traits\AssertConfigEntityImportTrait::assertConfigEntityImport()

Asserts that a config entity can be imported without changing it.

Parameters

\Drupal\Core\Config\Entity\ConfigEntityInterface $entity: The config entity to test importing.

1 call to AssertConfigEntityImportTrait::assertConfigEntityImport()
EntityReferenceIntegrationTest::testSupportedEntityTypesAndWidgets in core/modules/field/tests/src/Functional/EntityReference/EntityReferenceIntegrationTest.php
Tests the entity reference field with all its supported field widgets.

File

core/modules/config/tests/src/Traits/AssertConfigEntityImportTrait.php, line 21

Class

AssertConfigEntityImportTrait
Provides test assertions for testing config entity synchronization.

Namespace

Drupal\Tests\config\Traits

Code

public function assertConfigEntityImport(ConfigEntityInterface $entity) {

  // Save original config information.
  $entity_uuid = $entity
    ->uuid();
  $entity_type_id = $entity
    ->getEntityTypeId();
  $original_data = $entity
    ->toArray();

  // Copy everything to sync.
  $this
    ->copyConfig(\Drupal::service('config.storage'), \Drupal::service('config.storage.sync'));

  // Delete the configuration from active. Don't worry about side effects of
  // deleting config like fields cleaning up field storages. The coming import
  // should recreate everything as necessary.
  $entity
    ->delete();
  $this
    ->configImporter()
    ->reset()
    ->import();
  $imported_entity = \Drupal::service('entity.repository')
    ->loadEntityByUuid($entity_type_id, $entity_uuid);
  $this
    ->assertIdentical($original_data, $imported_entity
    ->toArray());
}