You are here

protected function ImportExportTestBase::getEntity in Acquia Content Hub 8.2

Returns Entity object.

Parameters

string $type: Entity type.

string $uuid: Entity UUID.

\Drupal\Tests\acquia_contenthub\Kernel\Stubs\CdfExpectations $expectation: The Expectation object.

Return value

\Drupal\Core\Entity\EntityInterface Entity.

Throws

\Drupal\Core\Entity\EntityStorageException

\Exception

See also

CdfExpectations::setEntityLoader()

2 calls to ImportExportTestBase::getEntity()
ImportExportTestBase::assertExportedConfigEntities in tests/src/Kernel/ImportExportTestBase.php
Executes assertions on a set of exported configuration entities.
ImportExportTestBase::configEntityImportExport in tests/src/Kernel/ImportExportTestBase.php
Executes the set of import/export tests on a configuration entity.

File

tests/src/Kernel/ImportExportTestBase.php, line 256

Class

ImportExportTestBase
Base for testing exports and imports.

Namespace

Drupal\Tests\acquia_contenthub\Kernel

Code

protected function getEntity($type, $uuid, CdfExpectations $expectation = NULL) : EntityInterface {

  /** @var \Drupal\Core\Entity\EntityRepositoryInterface $repository */
  $repository = $this->container
    ->get('entity.repository');
  $entity = $repository
    ->loadEntityByUuid($type, $uuid);
  if ($entity) {
    return $entity;
  }

  // Some configuration entities may change UUID value on import, such as
  // "view" configuration entity. So give them a chance to be loaded via
  // a custom entity loader (fallback) provided in the expectation definition.
  if ($expectation && ($entity_loader = $expectation
    ->getEntityLoader())) {
    $entity = call_user_func($entity_loader);
    if ($entity) {
      return $entity;
    }
  }
  throw new \Exception(sprintf('Failed to load entity of %s type by uuid=%s.', $type, $uuid));
}