You are here

protected function ExportTest::validateFieldCdfObject in Acquia Content Hub 8.2

Validates field CDF object.

Parameters

string $id_expected: Expected field id.

array $dependencies_expected: Expected list of dependencies (modules).

string $type_expected: Expected field type.

string $bundle_expected: Expected bundle.

array $settings_expected: Expected list of specific settings.

See also

\Drupal\Tests\acquia_contenthub\Kernel\ExportTest::createFieldStorages()

\Drupal\Tests\acquia_contenthub\Kernel\ExportTest::createNodeTypes()

File

tests/src/Kernel/ExportTest.php, line 2047

Class

ExportTest
Tests entity exports.

Namespace

Drupal\Tests\acquia_contenthub\Kernel

Code

protected function validateFieldCdfObject($id_expected, array $dependencies_expected, $type_expected, $bundle_expected, array $settings_expected) {
  $this
    ->validateBaseCdfObject();
  $cdf = $this->cdfObject;

  // Validate Type attribute.
  $type = $cdf
    ->getType();
  $this
    ->assertEquals('drupal8_config_entity', $type);

  // Validate Metadata attribute.
  $metadata = $cdf
    ->getMetadata();
  $this
    ->assertNotEmpty($metadata['dependencies']['entity']);
  $uuids = array_keys($metadata['dependencies']['entity']);
  foreach ($uuids as $uuid) {
    $has_field_dependency = in_array($uuid, $this->fieldUuids, TRUE);
    $has_node_type_dependency = in_array($uuid, $this->nodeTypeUuids, TRUE);
    $has_valid_dependency = $has_field_dependency || $has_node_type_dependency;
    $this
      ->assertTrue($has_valid_dependency);
  }
  unset($metadata['dependencies']['entity']);
  $metadata_expected = [
    'default_language' => 'en',
    'dependencies' => [
      'module' => array_merge($dependencies_expected, [
        'field',
      ]),
    ],
  ];
  unset($metadata['data']);
  $this
    ->assertEquals($metadata_expected, $metadata);

  // Validate "Data" attribute.
  $data = $this
    ->getCdfDataAttribute($cdf);
  $data_expected = [
    'en' => [
      'uuid' => $cdf
        ->getUuid(),
      'langcode' => 'en',
      'status' => TRUE,
      'dependencies' => [
        'config' => [
          'field.storage.node.' . $id_expected,
          'node.type.' . $bundle_expected,
        ],
      ],
      'id' => 'node.test_content_type.' . $id_expected,
      'field_name' => $id_expected,
      'entity_type' => 'node',
      'bundle' => $bundle_expected,
      'label' => $id_expected,
      'description' => '',
      'required' => FALSE,
      'translatable' => TRUE,
      'default_value' => [],
      'default_value_callback' => '',
      'settings' => $settings_expected,
      'field_type' => $type_expected,
    ],
  ];
  $this
    ->assertEquals($data_expected, $data);

  // Validate entity type.
  $entity_type = $this
    ->getCdfAttribute($cdf, 'entity_type');
  $this
    ->assertEquals('field_config', $entity_type);

  // Validate field id.
  $id = $this
    ->getCdfAttribute($cdf, 'label', 'en');
  $this
    ->assertEquals($id_expected, $id);
}