You are here

public function ProviderRepositoryTest::testInvalidResponse in Drupal 9

Tests handling of invalid JSON when fetching the provider database.

@dataProvider providerInvalidResponse

Parameters

int $expiration_offset: An offset to add to the current time to determine when the primed data, if any, expires.

File

core/modules/media/tests/src/Unit/ProviderRepositoryTest.php, line 139

Class

ProviderRepositoryTest
@coversDefaultClass \Drupal\media\OEmbed\ProviderRepository

Namespace

Drupal\Tests\media\Unit

Code

public function testInvalidResponse(int $expiration_offset) : void {
  $provider = $this
    ->prophesize('\\Drupal\\media\\OEmbed\\Provider')
    ->reveal();

  // This stored data should be returned, irrespective of whether it's fresh.
  $this->keyValue
    ->set('oembed_providers', [
    'data' => [
      'YouTube' => $provider,
    ],
    'expires' => $this->currentTime + $expiration_offset,
  ]);
  $response = new Response(200, [], "This certainly isn't valid JSON.");
  $this->responses
    ->append($response, $response);
  $this
    ->assertSame($provider, $this->repository
    ->get('YouTube'));

  // When there is no stored data, we should get an exception.
  $this->keyValue
    ->delete('oembed_providers');
  $this
    ->expectException(ProviderException::class);
  $this->repository
    ->get('YouTube');
}