You are here

public function ContentHubReindexTest::testReExportEntities in Acquia Content Hub 8

Test the reExportEntities function.

@covers ::reExportEntities

File

tests/src/Unit/Controller/ContentHubReindexTest.php, line 348

Class

ContentHubReindexTest
@coversDefaultClass \Drupal\acquia_contenthub\Controller\ContentHubReindex

Namespace

Drupal\Tests\acquia_contenthub\Unit\Controller

Code

public function testReExportEntities() {
  $limit = 3;
  $entities_list = $this
    ->getEntitiesData();
  $this->contentHubEntitiesTracking
    ->expects($this
    ->once())
    ->method('getEntitiesToReindex')
    ->willReturn($entities_list);
  $entity = $this
    ->createMock('Drupal\\Core\\Entity\\EntityInterface');
  foreach ($entities_list as $key => $entity_data) {
    if ($key < $limit) {
      $this->entityStorage
        ->expects($this
        ->at($key))
        ->method('load')
        ->with($entity_data->entity_id)
        ->willReturn($entity);
      $this->entityManager
        ->expects($this
        ->at($key))
        ->method('enqueueCandidateEntity')
        ->with($entity)
        ->willReturn(NULL);
    }
  }
  $context = [];
  ContentHubReindex::reExportEntities($limit, $context);
  $expected_context = [
    'sandbox' => [
      'progress' => 3,
      'max' => 5,
    ],
    'results' => [
      0 => 1,
      1 => 2,
      2 => 3,
    ],
    'message' => 'Exporting entities: @entities',
  ];
  $this
    ->assertEquals($expected_context['sandbox'], $context['sandbox']);
  $this
    ->assertEquals($expected_context['results'], $context['results']);
  $this
    ->assertEquals($expected_context['message'], $context['message']
    ->getUntranslatedString());
}