You are here

protected function ImportExportTestBase::assertExportedConfigEntities in Acquia Content Hub 8.2

Executes assertions on a set of exported configuration entities.

Parameters

int $delta: Delta.

string $type: Exported entity type.

string $uuid: Exported entity UUID.

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

Throws

\Exception

1 call to ImportExportTestBase::assertExportedConfigEntities()
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 347

Class

ImportExportTestBase
Base for testing exports and imports.

Namespace

Drupal\Tests\acquia_contenthub\Kernel

Code

protected function assertExportedConfigEntities(int $delta, string $type, string $uuid, CdfExpectations $expectation = NULL) : void {
  $entity = $this
    ->getEntity($type, $uuid, $expectation);
  $wrapper = new DependentEntityWrapper($entity);
  $stack = new DependencyStack();
  $this
    ->getCalculator()
    ->calculateDependencies($wrapper, $stack);
  $entities = NestedArray::mergeDeep([
    $wrapper
      ->getUuid() => $wrapper,
  ], $stack
    ->getDependenciesByUuid(array_keys($wrapper
    ->getDependencies())));
  $data = $this
    ->getSerializer()
    ->serializeEntities(...array_values($entities));
  $document = new CDFDocument(...$data);

  /** @var \Acquia\ContentHubClient\CDF\CDFObject[] $cdf_objects */
  $cdf_objects = [];

  // Reindex objects for easier assertions.
  foreach ($document
    ->getEntities() as $cdf_object) {
    $cdf_objects[$cdf_object
      ->getUuid()] = $cdf_object;
  }
  $count = 0;
  $fixtures = json_decode($this
    ->getFixtureString($delta), TRUE);
  foreach ($fixtures['entities'] as $fixture) {
    $cdf_object = $cdf_objects[$fixture['uuid']] ?? $cdf_objects[$entity
      ->uuid()];
    $object = $this
      ->decodeDataByObjectType($cdf_object
      ->getMetadata()['data'], $cdf_object
      ->getType());
    $fixture = $this
      ->decodeDataByObjectType($fixture['metadata']['data'], $fixture['type']);

    // Exclude UUID keys.
    $langcode = $this->container
      ->get('language_manager')
      ->getDefaultLanguage()
      ->getId();
    unset($object[$langcode]['uuid']);
    unset($fixture[$langcode]['uuid']);
    $this
      ->assertEquals($fixture, $object);
    $count++;
  }
  $this
    ->assertEquals($count, count($cdf_objects));
}