You are here

public function ContentHubEntitiesTrackingTest::testSetExportedEntity in Acquia Content Hub 8

Test for Exported Entities.

@covers ::setExportedEntity

File

tests/src/Unit/ContentHubEntitiesTrackingTest.php, line 104

Class

ContentHubEntitiesTrackingTest
PHPUnit tests for the ContentHubEntitiesTracking class.

Namespace

Drupal\Tests\acquia_contenthub\Unit

Code

public function testSetExportedEntity() {
  $entity = (object) [
    'entity_type' => 'node',
    'entity_id' => 1,
    'entity_uuid' => '00000000-0000-0000-0000-000000000000',
    'modified' => '2016-12-09T20:51:45+00:00',
    'origin' => '11111111-1111-1111-1111-111111111111',
  ];
  $this->contentHubEntitiesTracking = $this
    ->getContentHubEntitiesTrackingService();
  $this->contentHubEntitiesTracking
    ->setExportedEntity($entity->entity_type, $entity->entity_id, $entity->entity_uuid, $entity->modified, $entity->origin);

  // Running basic tests.
  $this
    ->assertEquals($entity->entity_type, $this->contentHubEntitiesTracking
    ->getEntityType());
  $this
    ->assertEquals($entity->entity_id, $this->contentHubEntitiesTracking
    ->getEntityId());
  $this
    ->assertEquals($entity->entity_uuid, $this->contentHubEntitiesTracking
    ->getUuid());
  $this
    ->assertEquals($entity->modified, $this->contentHubEntitiesTracking
    ->getModified());
  $this
    ->assertEquals($entity->origin, $this->contentHubEntitiesTracking
    ->getOrigin());
  $this
    ->assertTrue($this->contentHubEntitiesTracking
    ->isInitiated());
  $this
    ->assertFalse($this->contentHubEntitiesTracking
    ->isExported());
  $this
    ->assertFalse($this->contentHubEntitiesTracking
    ->isReindex());
  $this->contentHubEntitiesTracking
    ->setExported();
  $this
    ->assertFalse($this->contentHubEntitiesTracking
    ->isInitiated());
  $this
    ->assertFalse($this->contentHubEntitiesTracking
    ->isReindex());
  $this
    ->assertFalse($this->contentHubEntitiesTracking
    ->isQueued());
  $this
    ->assertTrue($this->contentHubEntitiesTracking
    ->isExported());
  $modified = '2017-11-04T20:51:45+00:00';
  $this->contentHubEntitiesTracking
    ->setModified($modified);
  $this
    ->assertEquals($modified, $this->contentHubEntitiesTracking
    ->getModified());

  // Assigning a Database Entity.
  $database_entity = [
    'entity_type' => 'node',
    'entity_id' => 1,
    'entity_uuid' => '00000000-0000-0000-0000-111111112222',
    'modified' => '2016-12-09T20:51:45+00:00',
    'origin' => '11111111-1111-1111-1111-111111111111',
    'status_export' => ContentHubEntitiesTracking::INITIATED,
    'status_import' => '',
  ];
  $this->contentHubEntitiesTracking = $this
    ->getContentHubEntitiesTrackingService($database_entity);

  // Trying to load an imported entity should return false.
  $this
    ->assertFalse($this->contentHubEntitiesTracking
    ->loadImportedByUuid($database_entity['entity_uuid']));

  // Loading an exported entity should work.
  $this->contentHubEntitiesTracking
    ->loadExportedByUuid($database_entity['entity_uuid']);
  $this
    ->assertEquals($database_entity['entity_type'], $this->contentHubEntitiesTracking
    ->getEntityType());
  $this
    ->assertEquals($database_entity['entity_id'], $this->contentHubEntitiesTracking
    ->getEntityId());
  $this
    ->assertEquals($database_entity['entity_uuid'], $this->contentHubEntitiesTracking
    ->getUuid());
  $this
    ->assertEquals($database_entity['modified'], $this->contentHubEntitiesTracking
    ->getModified());
  $this
    ->assertEquals($database_entity['origin'], $this->contentHubEntitiesTracking
    ->getOrigin());
  $this
    ->assertTrue($this->contentHubEntitiesTracking
    ->isInitiated());
  $this
    ->assertFalse($this->contentHubEntitiesTracking
    ->isQueued());
  $this
    ->assertFalse($this->contentHubEntitiesTracking
    ->isExported());
  $this->contentHubEntitiesTracking
    ->setQueued();
  $this
    ->assertTrue($this->contentHubEntitiesTracking
    ->isQueued());
  $this
    ->assertFalse($this->contentHubEntitiesTracking
    ->isExported());
  $this
    ->assertFalse($this->contentHubEntitiesTracking
    ->isInitiated());
}