You are here

public function AssetRefreshManagerTest::testInterruptedFetch in Media: Acquia DAM 8

Tests an "interrupted API fetch (a result set exceeds the limit)" scenario.

@dataProvider providerTestInterruptedFetch

Parameters

array $request_query_options: The list of request query options.

array $response: The stub of Notifications API response.

array $expected_asset_ids: The list of expected asset ids.

int $expected_total: The expected number of media entities to add to the queue.

File

tests/src/Unit/AssetRefreshManagerTest.php, line 227

Class

AssetRefreshManagerTest
AssetRefreshManager Service test.

Namespace

Drupal\Tests\media_acquiadam\Unit

Code

public function testInterruptedFetch(array $request_query_options, array $response, array $expected_asset_ids, int $expected_total) {
  $this->state
    ->method('get')
    ->willReturnMap([
    [
      'media_acquiadam.notifications_next_page',
      NULL,
      NULL,
    ],
    [
      'media_acquiadam.notifications_starttime',
      NULL,
      self::LAST_READ_TIMESTAMP,
    ],
    [
      'media_acquiadam.notifications_endtime',
      self::REQUEST_TIME,
      self::REQUEST_TIME,
    ],
    [
      'media_acquiadam.notifications_endtime',
      NULL,
      1234,
    ],
  ]);
  $this
    ->setupApiResponseStub($request_query_options, $response);
  $this
    ->setupMediaEntityExpectations($expected_asset_ids, $expected_total);
  $this->state
    ->method('set')
    ->withConsecutive([
    'media_acquiadam.notifications_next_page',
    2,
  ], [
    'media_acquiadam.notifications_endtime',
    self::REQUEST_TIME,
  ]);
  $actual = $this->assetRefreshManager
    ->updateQueue($this
    ->getAssetIdFieldsStub());
  $this
    ->assertEquals(3, $actual);
}