You are here

public function ContentHubReindexTest::testSetExportedEntitiesToReindex in Acquia Content Hub 8

Test the setExportedEntitiesToReindex function.

@covers ::setExportedEntitiesToReindex

File

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

Class

ContentHubReindexTest
@coversDefaultClass \Drupal\acquia_contenthub\Controller\ContentHubReindex

Namespace

Drupal\Tests\acquia_contenthub\Unit\Controller

Code

public function testSetExportedEntitiesToReindex() {
  $entities = $this
    ->getEntitiesData();
  $this->contentHubEntitiesTracking
    ->expects($this
    ->once())
    ->method('setExportedEntitiesForReindex')
    ->with('node')
    ->willReturn(TRUE);
  $this->contentHubEntitiesTracking
    ->expects($this
    ->once())
    ->method('getEntitiesToReindex')
    ->willReturn($entities);
  foreach ($entities as $key => $entity) {
    $this->clientManager
      ->expects($this
      ->at($key))
      ->method('createRequest')
      ->with('deleteEntity', [
      $entity->entity_uuid,
    ])
      ->willReturn(TRUE);
  }
  $this->clientManager
    ->expects($this
    ->at(count($entities)))
    ->method('createRequest')
    ->with('reindex')
    ->willReturn([
    'success' => TRUE,
  ]);

  // Initially the system is not set to reindex.
  $this
    ->assertTrue($this->contentHubReindex
    ->isReindexNone());
  $this->contentHubReindex
    ->setExportedEntitiesToReindex('node');
  $this
    ->assertTrue($this->contentHubReindex
    ->isReindexSent());
}