trait AssertConfigEntityImportTrait

Same name in this branch
  1. 8.9.x core/modules/config/tests/src/Traits/AssertConfigEntityImportTrait.php \Drupal\Tests\config\Traits\AssertConfigEntityImportTrait
Same name in other branches
  1. 9 core/modules/config/tests/src/Traits/AssertConfigEntityImportTrait.php \Drupal\Tests\config\Traits\AssertConfigEntityImportTrait
  2. 10 core/modules/config/tests/src/Traits/AssertConfigEntityImportTrait.php \Drupal\Tests\config\Traits\AssertConfigEntityImportTrait
  3. 11.x core/modules/config/tests/src/Traits/AssertConfigEntityImportTrait.php \Drupal\Tests\config\Traits\AssertConfigEntityImportTrait

Provides test assertions for testing config entity synchronization.

Can be used by test classes that extend \Drupal\simpletest\WebTestBase or \Drupal\KernelTests\KernelTestBase.

Hierarchy

Deprecated

in drupal:8.4.1 and is removed from drupal:9.0.0. Use \Drupal\Tests\config\Traits\AssertConfigEntityImportTrait.

See also

https://www.drupal.org/node/2916197

File

core/modules/config/src/Tests/AssertConfigEntityImportTrait.php, line 20

Namespace

Drupal\config\Tests
View source
trait AssertConfigEntityImportTrait {
    
    /**
     * Asserts that a config entity can be imported without changing it.
     *
     * @param \Drupal\Core\Config\Entity\ConfigEntityInterface $entity
     *   The config entity to test importing.
     */
    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());
    }

}

Members

Title Sort descending Modifiers Object type Summary
AssertConfigEntityImportTrait::assertConfigEntityImport public function Asserts that a config entity can be imported without changing it.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.