function UrlResolverTest::testDiscoverResourceUrlParsesHtml
Same name and namespace in other branches
- 11.x core/modules/media/tests/src/Unit/UrlResolverTest.php \Drupal\Tests\media\Unit\UrlResolverTest::testDiscoverResourceUrlParsesHtml()
Tests that discoverResourceUrl parses HTML responses.
Attributes
#[TestWith([
'https://example.com/some-page',
'https://example.com/oembed?url=test',
])]
#[TestWith([
'https://evil.com/some-page',
FALSE,
])]
#[TestWith([
'look-ma-no-host',
FALSE,
])]
File
-
core/
modules/ media/ tests/ src/ Unit/ UrlResolverTest.php, line 70
Class
- UrlResolverTest
- Tests the oEmbed URL resolver.
Namespace
Drupal\Tests\media\UnitCode
public function testDiscoverResourceUrlParsesHtml(string $url, string|bool $expected) : 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($url);
$this->assertSame($expected, $result);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.