You are here

public function ContentHubEntitiesTrackingTest::testSetImportedEntity in Acquia Content Hub 8

Test for Imported Entities.

@covers ::setImportedEntity

File

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

Class

ContentHubEntitiesTrackingTest
PHPUnit tests for the ContentHubEntitiesTracking class.

Namespace

Drupal\Tests\acquia_contenthub\Unit

Code

public function testSetImportedEntity() {
  $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
    ->setImportedEntity($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
    ->isAutoUpdate());
  $this
    ->assertFalse($this->contentHubEntitiesTracking
    ->hasLocalChange());
  $this
    ->assertFalse($this->contentHubEntitiesTracking
    ->isPendingSync());
  $this->contentHubEntitiesTracking
    ->setLocalChange();
  $this
    ->assertFalse($this->contentHubEntitiesTracking
    ->isAutoUpdate());
  $this
    ->assertTrue($this->contentHubEntitiesTracking
    ->hasLocalChange());
  $this
    ->assertFalse($this->contentHubEntitiesTracking
    ->isPendingSync());
  $this->contentHubEntitiesTracking
    ->setPendingSync();
  $this
    ->assertFalse($this->contentHubEntitiesTracking
    ->isAutoUpdate());
  $this
    ->assertTrue($this->contentHubEntitiesTracking
    ->hasLocalChange());
  $this
    ->assertTrue($this->contentHubEntitiesTracking
    ->isPendingSync());
  $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-111111111111',
    'modified' => '2016-12-09T20:51:45+00:00',
    'origin' => '11111111-1111-1111-1111-111111111111',
    'status_export' => '',
    'status_import' => ContentHubEntitiesTracking::AUTO_UPDATE_DISABLED,
  ];
  $this->contentHubEntitiesTracking = $this
    ->getContentHubEntitiesTrackingService($database_entity);

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

  // Trying to load an imported entity should work.
  $this->contentHubEntitiesTracking
    ->loadImportedByUuid($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
    ->assertFalse($this->contentHubEntitiesTracking
    ->isAutoUpdate());
  $this
    ->assertFalse($this->contentHubEntitiesTracking
    ->hasLocalChange());
  $this
    ->assertFalse($this->contentHubEntitiesTracking
    ->isPendingSync());
}