You are here

protected function ExportTest::validateBaseCdfObject in Acquia Content Hub 8.2

Performs basic CDF Object validation.

8 calls to ExportTest::validateBaseCdfObject()
ExportTest::validateFieldCdfObject in tests/src/Kernel/ExportTest.php
Validates field CDF object.
ExportTest::validateFieldStorageCdfObject in tests/src/Kernel/ExportTest.php
Validates field storage CDF object.
ExportTest::validateFileCdfObject in tests/src/Kernel/ExportTest.php
Validates file CDFObject.
ExportTest::validateNodeCdfObject in tests/src/Kernel/ExportTest.php
Validated "node with a text field" CDF object.
ExportTest::validateNodeTypeCdfObject in tests/src/Kernel/ExportTest.php
Validates node type CDF object.

... See full list

File

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

Class

ExportTest
Tests entity exports.

Namespace

Drupal\Tests\acquia_contenthub\Kernel

Code

protected function validateBaseCdfObject() {
  $cdf = $this->cdfObject;
  $this
    ->assertNotEmpty($cdf);
  $entity_type = $cdf
    ->getAttribute('entity_type')
    ->getValue()[Language::LANGCODE_NOT_SPECIFIED];
  $storage = \Drupal::service('entity_type.manager')
    ->getStorage($entity_type)
    ->loadByProperties([
    'uuid' => $cdf
      ->getUuid(),
  ]);
  $wrapper = new DependentEntityWrapper(current($storage));

  // Validate Origin attribute.
  $origin = $cdf
    ->getOrigin();
  $this
    ->assertEquals('00000000-0000-0001-0000-123456789123', $origin);

  // Validate date values.
  $iso8601_regex = '/^(?:[1-9]\\d{3}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1\\d|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[1-9]\\d(?:0[48]|[2468][048]|[13579][26])|(?:[2468][048]|[13579][26])00)-02-29)T(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:Z|[+-][01]\\d:[0-5]\\d)$/';
  $date_created = $cdf
    ->getCreated();
  $date_created_is_valid = preg_match($iso8601_regex, $date_created);
  $this
    ->assertNotEmpty($date_created_is_valid);
  $date_modified = $cdf
    ->getModified();
  $date_modified_is_valid = preg_match($iso8601_regex, $date_modified);
  $this
    ->assertNotEmpty($date_modified_is_valid);

  // Validate UUID.
  $uuid = $cdf
    ->getUuid();
  $this
    ->assertTrue(Uuid::isValid($uuid));

  // Validate "base_url" attribute.
  $base_url = $this
    ->getCdfAttribute($cdf, 'base_url');
  $url = Url::fromUserInput('/', [
    'absolute' => TRUE,
  ]);
  $url = $url
    ->toString();
  $this
    ->assertEquals($url, $base_url);

  // Validate "hash" attribute.
  $hash = $this
    ->getCdfAttribute($cdf, 'hash');
  $this
    ->assertEquals($wrapper
    ->getHash(), $hash);

  // Validate "data" attribute.
  $this
    ->assertNotEmpty($this
    ->getCdfDataAttribute($cdf));
}