3 namespace Drupal\Tests\media\Functional;
5 use Drupal\Tests\media\Traits\OEmbedTestTrait;
8 * Tests the oEmbed URL resolver service.
10 * @coversDefaultClass \Drupal\media\OEmbed\UrlResolver
14 class UrlResolverTest extends MediaFunctionalTestBase {
21 protected function setUp() {
23 $this->lockHttpClientToFixtures();
24 $this->useFixtureProviders();
28 * Data provider for testEndpointMatching().
30 * @see ::testEndpointMatching()
34 public function providerEndpointMatching() {
36 'match by endpoint: Twitter' => [
37 'https://twitter.com/Dries/status/999985431595880448',
38 'https://publish.twitter.com/oembed?url=https%3A//twitter.com/Dries/status/999985431595880448',
40 'match by endpoint: Vimeo' => [
41 'https://vimeo.com/14782834',
42 'https://vimeo.com/api/oembed.json?url=https%3A//vimeo.com/14782834',
44 'match by endpoint: CollegeHumor' => [
45 'http://www.collegehumor.com/video/40002870/lets-not-get-a-drink-sometime',
46 'http://www.collegehumor.com/oembed.json?url=http%3A//www.collegehumor.com/video/40002870/lets-not-get-a-drink-sometime',
52 * Tests resource URL resolution when the asset URL can be matched to a
55 * @covers ::getProviderByUrl
56 * @covers ::getResourceUrl
59 * The asset URL to resolve.
60 * @param string $resource_url
61 * The expected oEmbed resource URL of the asset.
63 * @dataProvider providerEndpointMatching
65 public function testEndpointMatching($url, $resource_url) {
68 $this->container->get('media.oembed.url_resolver')->getResourceUrl($url)
73 * Tests that hook_oembed_resource_url_alter() is invoked.
75 * @depends testEndpointMatching
77 public function testResourceUrlAlterHook() {
78 $this->container->get('module_installer')->install(['media_test_oembed']);
80 $resource_url = $this->container->get('media.oembed.url_resolver')
81 ->getResourceUrl('https://vimeo.com/14782834');
83 $this->assertContains('altered=1', parse_url($resource_url, PHP_URL_QUERY));
87 * Data provider for testUrlDiscovery().
89 * @see ::testUrlDiscovery()
93 public function providerUrlDiscovery() {
97 'https://vimeo.com/api/oembed.json?url=video_vimeo.html',
100 'video_collegehumor.html',
101 // The endpoint does not explicitly declare that it supports XML, so
102 // only JSON support is assumed, which is why the discovered URL
103 // contains '.json'. However, the fetched HTML file contains a
104 // relationship to an XML representation of the resource, with the
105 // application/xml+oembed MIME type.
106 'http://www.collegehumor.com/oembed.json?url=video_collegehumor.html',
112 * Tests URL resolution when the resource URL must be actively discovered by
113 * scanning the asset.
116 * The asset URL to resolve.
117 * @param string $resource_url
118 * The expected oEmbed resource URL of the asset.
120 * @covers ::discoverResourceUrl
121 * @covers ::getProviderByUrl
122 * @covers ::getResourceUrl
124 * @dataProvider providerUrlDiscovery
126 public function testUrlDiscovery($url, $resource_url) {
128 $this->container->get('media.oembed.url_resolver')->getResourceUrl($url),