3 namespace Drupal\Tests\media\Functional;
5 use Drupal\media\OEmbed\ProviderException;
8 * Tests the oEmbed provider repository.
10 * @covers \Drupal\media\OEmbed\ProviderRepository
14 class ProviderRepositoryTest extends MediaFunctionalTestBase {
17 * Tests that provider discovery fails if the provider database is empty.
19 * @param string $content
20 * The expected JSON content of the provider database.
22 * @dataProvider providerEmptyProviderList
24 public function testEmptyProviderList($content) {
25 $response = $this->prophesize('\GuzzleHttp\Psr7\Response');
26 $response->getBody()->willReturn($content);
28 $client = $this->createMock('\GuzzleHttp\Client');
29 $client->method('request')->withAnyParameters()->willReturn($response->reveal());
30 $this->container->set('http_client', $client);
32 $this->setExpectedException(ProviderException::class, 'Remote oEmbed providers database returned invalid or empty list.');
33 $this->container->get('media.oembed.provider_repository')->getAll();
37 * Data provider for testEmptyProviderList().
39 * @see ::testEmptyProviderList()
43 public function providerEmptyProviderList() {
45 'empty array' => ['[]'],
46 'empty string' => [''],
51 * Tests that provider discovery fails with a non-existent provider database.
53 * @param string $providers_url
54 * The URL of the provider database.
55 * @param string $exception_message
56 * The expected exception message.
58 * @dataProvider providerNonExistingProviderDatabase
60 public function testNonExistingProviderDatabase($providers_url, $exception_message) {
61 $this->config('media.settings')
62 ->set('oembed_providers_url', $providers_url)
65 $this->setExpectedException(ProviderException::class, $exception_message);
66 $this->container->get('media.oembed.provider_repository')->getAll();
70 * Data provider for testEmptyProviderList().
72 * @see ::testEmptyProviderList()
76 public function providerNonExistingProviderDatabase() {
79 'http://oembed1.com/providers.json',
80 'Could not retrieve the oEmbed provider database from http://oembed1.com/providers.json',
83 'http://oembed.com/providers1.json',
84 'Could not retrieve the oEmbed provider database from http://oembed.com/providers1.json',