ProviderRepositoryTest.php in Drupal 9
File
core/modules/media/tests/src/Functional/ProviderRepositoryTest.php
View source
<?php
namespace Drupal\Tests\media\Functional;
use Drupal\media\OEmbed\ProviderException;
use GuzzleHttp\Psr7\Utils;
class ProviderRepositoryTest extends MediaFunctionalTestBase {
protected $defaultTheme = 'stark';
public function testEmptyProviderList($content) {
$response = $this
->prophesize('\\GuzzleHttp\\Psr7\\Response');
$response
->getBody()
->willReturn(Utils::streamFor($content));
$client = $this
->createMock('\\GuzzleHttp\\Client');
$client
->method('request')
->withAnyParameters()
->willReturn($response
->reveal());
$this->container
->set('http_client', $client);
$this
->expectException(ProviderException::class);
$this
->expectExceptionMessage('Remote oEmbed providers database returned invalid or empty list.');
$this->container
->get('media.oembed.provider_repository')
->getAll();
}
public function providerEmptyProviderList() {
return [
'empty array' => [
'[]',
],
'empty string' => [
'',
],
];
}
public function testNonExistingProviderDatabase($providers_url, $exception_message) {
$this
->config('media.settings')
->set('oembed_providers_url', $providers_url)
->save();
$this
->expectException(ProviderException::class);
$this
->expectExceptionMessage($exception_message);
$this->container
->get('media.oembed.provider_repository')
->getAll();
}
public function providerNonExistingProviderDatabase() {
return [
[
'http://oembed1.com/providers.json',
'Could not retrieve the oEmbed provider database from http://oembed1.com/providers.json',
],
[
'http://oembed.com/providers1.json',
'Could not retrieve the oEmbed provider database from http://oembed.com/providers1.json',
],
];
}
}