You are here

public function ContentHubEntityExportControllerTest::testTrackExportedEntity in Acquia Content Hub 8

Tests trackExportedEntity method.

@covers ::trackExportedEntity

Throws

\Exception

File

tests/src/Unit/Controller/ContentHubEntityExportControllerTest.php, line 207

Class

ContentHubEntityExportControllerTest
Unit test for ContentHubEntityExportController class.

Namespace

Drupal\Tests\acquia_contenthub\Unit\Controller

Code

public function testTrackExportedEntity() {
  $entity = $this
    ->createContentHubEntity();
  $entity_dependency = new ContentHubEntityDependency($entity);
  $entity_dependency
    ->setStatus(Node::PUBLISHED);
  $cdf = (array) $entity_dependency
    ->getRawEntity();
  $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',
  ];
  $contentHubEntitiesTracking = $this
    ->getContentHubEntitiesTrackingService();
  $contentHubEntitiesTracking
    ->setExportedEntity($entity->entity_type, $entity->entity_id, $entity->entity_uuid, $entity->modified, $entity->origin);
  $node = $this
    ->getMockBuilder('\\Drupal\\node\\Entity\\Node')
    ->disableOriginalConstructor()
    ->getMock();
  $node
    ->method('id')
    ->willReturn(1);
  $this->entityRepository
    ->method('loadEntityByUuid')
    ->willReturn($node);
  $this->contentHubEntitiesTracking
    ->expects($this::exactly(2))
    ->method('setExportedEntity')
    ->willReturn($contentHubEntitiesTracking);
  $this->contentHubEntitiesTracking
    ->expects($this::exactly(2))
    ->method('getSiteOrigin')
    ->willReturn('00000000-0000-0000-0000-000000000000');
  $this->contentHubEntitiesTracking
    ->expects($this::exactly(4))
    ->method('save');
  $this->contentHubEntityExportController
    ->trackExportedEntity($cdf, FALSE);
  $this
    ->assertEquals(FALSE, $contentHubEntitiesTracking
    ->isExported());
  $this->contentHubEntityExportController
    ->trackExportedEntity($cdf, TRUE);
  $this
    ->assertEquals(TRUE, $contentHubEntitiesTracking
    ->isExported());
  $contentHubEntitiesTracking = $this
    ->getContentHubEntitiesTrackingService();
  $contentHubEntitiesTracking
    ->setExportedEntity($entity->entity_type, $entity->entity_id, $entity->entity_uuid, $entity->modified, $entity->origin);
  $this->contentHubEntitiesTracking
    ->expects($this::exactly(2))
    ->method('loadExportedByUuid')
    ->willReturn($contentHubEntitiesTracking);
  $this->contentHubEntityExportController
    ->trackExportedEntity($cdf, FALSE);
  $this
    ->assertEquals(FALSE, $contentHubEntitiesTracking
    ->isExported());
  $this->contentHubEntityExportController
    ->trackExportedEntity($cdf, TRUE);
  $this
    ->assertEquals(TRUE, $contentHubEntitiesTracking
    ->isExported());
}