function UrlResolverTest::testUrlDiscovery

Same name and namespace in other branches
  1. 10 core/modules/media/tests/src/Functional/UrlResolverTest.php \Drupal\Tests\media\Functional\UrlResolverTest::testUrlDiscovery()
  2. 11.x core/modules/media/tests/src/Functional/UrlResolverTest.php \Drupal\Tests\media\Functional\UrlResolverTest::testUrlDiscovery()
  3. 9 core/modules/media/tests/src/Functional/UrlResolverTest.php \Drupal\Tests\media\Functional\UrlResolverTest::testUrlDiscovery()
  4. 8.9.x core/modules/media/tests/src/Functional/UrlResolverTest.php \Drupal\Tests\media\Functional\UrlResolverTest::testUrlDiscovery()

Tests URL resolution when the URL is discovered by scanning the asset.

@legacy-covers ::discoverResourceUrl @legacy-covers ::getProviderByUrl @legacy-covers ::getResourceUrl

Attributes

#[DataProvider('providerUrlDiscovery')]

Parameters

string $url: The asset URL to resolve.

string $resource_url: The expected oEmbed resource URL of the asset.

File

core/modules/media/tests/src/Functional/UrlResolverTest.php, line 138

Class

UrlResolverTest
Tests the oEmbed URL resolver service.

Namespace

Drupal\Tests\media\Functional

Code

public function testUrlDiscovery(string $url, string $resource_url) : void {
  $settings['settings']['media_oembed_discovery_trusted_host_patterns'] = (object) [
    'value' => [
      \preg_quote(\parse_url($this->baseUrl, \PHP_URL_HOST)),
    ],
    'required' => TRUE,
  ];
  $this->writeSettings($settings);
  $this->rebuildAll();
  $fully_qualified_url = $this->getFixturesUrl() . '/' . $url;
  $this->assertSame(\sprintf($resource_url, UrlHelper::buildQuery([
    'url' => $fully_qualified_url,
  ])), $this->container
    ->get('media.oembed.url_resolver')
    ->getResourceUrl($fully_qualified_url));
}

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