protected function OEmbedTestTrait::hijackProviderEndpoints in Drupal 10
Same name and namespace in other branches
- 8 core/modules/media/tests/src/Traits/OEmbedTestTrait.php \Drupal\Tests\media\Traits\OEmbedTestTrait::hijackProviderEndpoints()
- 9 core/modules/media/tests/src/Traits/OEmbedTestTrait.php \Drupal\Tests\media\Traits\OEmbedTestTrait::hijackProviderEndpoints()
Ensures that all oEmbed provider endpoints defined in the fixture providers.json will use the media_test_oembed.resource.get route as their URL.
This requires the media_test_oembed module in order to work.
1 call to OEmbedTestTrait::hijackProviderEndpoints()
- OEmbedFormatterTest::testRender in core/
modules/ media/ tests/ src/ Functional/ FieldFormatter/ OEmbedFormatterTest.php - Tests the oEmbed field formatter.
File
- core/
modules/ media/ tests/ src/ Traits/ OEmbedTestTrait.php, line 71
Class
- OEmbedTestTrait
- Contains helper functions for testing oEmbed functionality in isolation.
Namespace
Drupal\Tests\media\TraitsCode
protected function hijackProviderEndpoints() {
$providers = $this
->getFixturesDirectory() . '/providers.json';
$providers = file_get_contents($providers);
$providers = Json::decode($providers);
$endpoint_url = Url::fromRoute('media_test_oembed.resource.get')
->setAbsolute()
->toString();
/** @var \Drupal\media_test_oembed\ProviderRepository $provider_repository */
$provider_repository = $this->container
->get('media.oembed.provider_repository');
foreach ($providers as &$provider) {
foreach ($provider['endpoints'] as &$endpoint) {
$endpoint['url'] = $endpoint_url;
}
$provider_repository
->setProvider(new Provider($provider['provider_name'], $provider['provider_url'], $provider['endpoints']));
}
}