X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fmedia%2Ftests%2Fsrc%2FFunctional%2FUrlResolverTest.php;fp=web%2Fcore%2Fmodules%2Fmedia%2Ftests%2Fsrc%2FFunctional%2FUrlResolverTest.php;h=1dfe5d6abee925765cf9479305cc13321b0e1aa9;hp=0000000000000000000000000000000000000000;hb=0bf8d09d2542548982e81a441b1f16e75873a04f;hpb=74df008bdbb3a11eeea356744f39b802369bda3c diff --git a/web/core/modules/media/tests/src/Functional/UrlResolverTest.php b/web/core/modules/media/tests/src/Functional/UrlResolverTest.php new file mode 100644 index 000000000..1dfe5d6ab --- /dev/null +++ b/web/core/modules/media/tests/src/Functional/UrlResolverTest.php @@ -0,0 +1,133 @@ +lockHttpClientToFixtures(); + $this->useFixtureProviders(); + } + + /** + * Data provider for testEndpointMatching(). + * + * @see ::testEndpointMatching() + * + * @return array + */ + public function providerEndpointMatching() { + return [ + 'match by endpoint: Twitter' => [ + 'https://twitter.com/Dries/status/999985431595880448', + 'https://publish.twitter.com/oembed?url=https%3A//twitter.com/Dries/status/999985431595880448', + ], + 'match by endpoint: Vimeo' => [ + 'https://vimeo.com/14782834', + 'https://vimeo.com/api/oembed.json?url=https%3A//vimeo.com/14782834', + ], + 'match by endpoint: CollegeHumor' => [ + 'http://www.collegehumor.com/video/40002870/lets-not-get-a-drink-sometime', + 'http://www.collegehumor.com/oembed.json?url=http%3A//www.collegehumor.com/video/40002870/lets-not-get-a-drink-sometime', + ], + ]; + } + + /** + * Tests resource URL resolution when the asset URL can be matched to a + * provider endpoint. + * + * @covers ::getProviderByUrl + * @covers ::getResourceUrl + * + * @param string $url + * The asset URL to resolve. + * @param string $resource_url + * The expected oEmbed resource URL of the asset. + * + * @dataProvider providerEndpointMatching + */ + public function testEndpointMatching($url, $resource_url) { + $this->assertSame( + $resource_url, + $this->container->get('media.oembed.url_resolver')->getResourceUrl($url) + ); + } + + /** + * Tests that hook_oembed_resource_url_alter() is invoked. + * + * @depends testEndpointMatching + */ + public function testResourceUrlAlterHook() { + $this->container->get('module_installer')->install(['media_test_oembed']); + + $resource_url = $this->container->get('media.oembed.url_resolver') + ->getResourceUrl('https://vimeo.com/14782834'); + + $this->assertContains('altered=1', parse_url($resource_url, PHP_URL_QUERY)); + } + + /** + * Data provider for testUrlDiscovery(). + * + * @see ::testUrlDiscovery() + * + * @return array + */ + public function providerUrlDiscovery() { + return [ + 'JSON resource' => [ + 'video_vimeo.html', + 'https://vimeo.com/api/oembed.json?url=video_vimeo.html', + ], + 'XML resource' => [ + 'video_collegehumor.html', + // The endpoint does not explicitly declare that it supports XML, so + // only JSON support is assumed, which is why the discovered URL + // contains '.json'. However, the fetched HTML file contains a + // relationship to an XML representation of the resource, with the + // application/xml+oembed MIME type. + 'http://www.collegehumor.com/oembed.json?url=video_collegehumor.html', + ], + ]; + } + + /** + * Tests URL resolution when the resource URL must be actively discovered by + * scanning the asset. + * + * @param string $url + * The asset URL to resolve. + * @param string $resource_url + * The expected oEmbed resource URL of the asset. + * + * @covers ::discoverResourceUrl + * @covers ::getProviderByUrl + * @covers ::getResourceUrl + * + * @dataProvider providerUrlDiscovery + */ + public function testUrlDiscovery($url, $resource_url) { + $this->assertSame( + $this->container->get('media.oembed.url_resolver')->getResourceUrl($url), + $resource_url + ); + } + +}