function ProviderRepositoryTest::testInvalidResponse

Same name and namespace in other branches
  1. 9 core/modules/media/tests/src/Unit/ProviderRepositoryTest.php \Drupal\Tests\media\Unit\ProviderRepositoryTest::testInvalidResponse()
  2. 11.x core/modules/media/tests/src/Unit/ProviderRepositoryTest.php \Drupal\Tests\media\Unit\ProviderRepositoryTest::testInvalidResponse()

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[[api-linebreak]]

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');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.