function UrlResolverTest::testDiscoverResourceUrlParsesHtml

Tests that discoverResourceUrl parses HTML responses.

File

core/modules/media/tests/src/Unit/UrlResolverTest.php, line 58

Class

UrlResolverTest
Tests the oEmbed URL resolver.

Namespace

Drupal\Tests\media\Unit

Code

public function testDiscoverResourceUrlParsesHtml() : void {
  $html_with_oembed = <<<HTML
  <!DOCTYPE html>
  <html>
  <head>
    <link rel="alternate" href="https://example.com/oembed?url=test" type="application/json+oembed">
  </head>
  <body></body>
  </html>
  HTML;
  $response = new Response(200, [
    'Content-Type' => 'text/html',
  ], $html_with_oembed);
  $mock_handler = new MockHandler([
    $response,
  ]);
  $client = new Client([
    'handler' => HandlerStack::create($mock_handler),
  ]);
  $url_resolver = $this->createTestableUrlResolver($client);
  $result = $url_resolver->discoverResourceUrl('https://example.com/some-page');
  $this->assertSame('https://example.com/oembed?url=test', $result);
}

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