You are here

public function AcquiadamConfigFormTest::testProcessBatchItems in Media: Acquia DAM 8

Tests a batch processing.

@covers ::processBatchItems @covers ::finishBatchOperation

Throws

\Drupal\Component\Plugin\Exception\PluginException

File

tests/src/Unit/AcquiadamConfigFormTest.php, line 128

Class

AcquiadamConfigFormTest
Config form test.

Namespace

Drupal\Tests\media_acquiadam\Unit

Code

public function testProcessBatchItems() {

  // Generate a set of test media entity ids.
  $media_ids = range(1, 12);
  $total_media_ids = count($media_ids);
  $context = [];
  $queue_worker_expected_arguments = array_map(function ($value) {
    return [
      [
        'media_id' => $value,
      ],
    ];
  }, $media_ids);
  $this->queueWorker
    ->expects($this
    ->any())
    ->method('processItem')
    ->withConsecutive(...$queue_worker_expected_arguments)
    ->willReturn(TRUE);

  // Emulate the three consecutive batch runs.
  foreach (range(1, 3) as $run) {

    // Perform a batch run and make necessary assertions.
    $this->acquiaDamConfig
      ->processBatchItems($media_ids, $context);
    $this
      ->assertBatchRun($context, $run, $total_media_ids);
  }

  // Verify the batch finish operation.
  $this->state
    ->expects($this
    ->exactly(3))
    ->method('set')
    ->withConsecutive([
    $this
      ->equalTo('media_acquiadam.notifications_starttime'),
    $this
      ->equalTo(1560000000),
  ], [
    $this
      ->equalTo('media_acquiadam.notifications_endtime'),
    $this
      ->equalTo(NULL),
  ], [
    $this
      ->equalTo('media_acquiadam.notifications_next_page'),
    $this
      ->equalTo(NULL),
  ]);
  $this->acquiaDamConfig
    ->finishBatchOperation(NULL, $context['results'], []);
}