Chris@17: lockHttpClientToFixtures(); Chris@17: $this->useFixtureProviders(); Chris@17: } Chris@17: Chris@17: /** Chris@17: * Data provider for testEndpointMatching(). Chris@17: * Chris@17: * @see ::testEndpointMatching() Chris@17: * Chris@17: * @return array Chris@17: */ Chris@17: public function providerEndpointMatching() { Chris@17: return [ Chris@17: 'match by endpoint: Twitter' => [ Chris@17: 'https://twitter.com/Dries/status/999985431595880448', Chris@17: 'https://publish.twitter.com/oembed?url=https%3A//twitter.com/Dries/status/999985431595880448', Chris@17: ], Chris@17: 'match by endpoint: Vimeo' => [ Chris@17: 'https://vimeo.com/14782834', Chris@17: 'https://vimeo.com/api/oembed.json?url=https%3A//vimeo.com/14782834', Chris@17: ], Chris@17: 'match by endpoint: CollegeHumor' => [ Chris@17: 'http://www.collegehumor.com/video/40002870/lets-not-get-a-drink-sometime', Chris@17: 'http://www.collegehumor.com/oembed.json?url=http%3A//www.collegehumor.com/video/40002870/lets-not-get-a-drink-sometime', Chris@17: ], Chris@17: ]; Chris@17: } Chris@17: Chris@17: /** Chris@17: * Tests resource URL resolution when the asset URL can be matched to a Chris@17: * provider endpoint. Chris@17: * Chris@17: * @covers ::getProviderByUrl Chris@17: * @covers ::getResourceUrl Chris@17: * Chris@17: * @param string $url Chris@17: * The asset URL to resolve. Chris@17: * @param string $resource_url Chris@17: * The expected oEmbed resource URL of the asset. Chris@17: * Chris@17: * @dataProvider providerEndpointMatching Chris@17: */ Chris@17: public function testEndpointMatching($url, $resource_url) { Chris@17: $this->assertSame( Chris@17: $resource_url, Chris@17: $this->container->get('media.oembed.url_resolver')->getResourceUrl($url) Chris@17: ); Chris@17: } Chris@17: Chris@17: /** Chris@17: * Tests that hook_oembed_resource_url_alter() is invoked. Chris@17: * Chris@17: * @depends testEndpointMatching Chris@17: */ Chris@17: public function testResourceUrlAlterHook() { Chris@17: $this->container->get('module_installer')->install(['media_test_oembed']); Chris@17: Chris@17: $resource_url = $this->container->get('media.oembed.url_resolver') Chris@17: ->getResourceUrl('https://vimeo.com/14782834'); Chris@17: Chris@17: $this->assertContains('altered=1', parse_url($resource_url, PHP_URL_QUERY)); Chris@17: } Chris@17: Chris@17: /** Chris@17: * Data provider for testUrlDiscovery(). Chris@17: * Chris@17: * @see ::testUrlDiscovery() Chris@17: * Chris@17: * @return array Chris@17: */ Chris@17: public function providerUrlDiscovery() { Chris@17: return [ Chris@17: 'JSON resource' => [ Chris@17: 'video_vimeo.html', Chris@17: 'https://vimeo.com/api/oembed.json?url=video_vimeo.html', Chris@17: ], Chris@17: 'XML resource' => [ Chris@17: 'video_collegehumor.html', Chris@17: // The endpoint does not explicitly declare that it supports XML, so Chris@17: // only JSON support is assumed, which is why the discovered URL Chris@17: // contains '.json'. However, the fetched HTML file contains a Chris@17: // relationship to an XML representation of the resource, with the Chris@17: // application/xml+oembed MIME type. Chris@17: 'http://www.collegehumor.com/oembed.json?url=video_collegehumor.html', Chris@17: ], Chris@17: ]; Chris@17: } Chris@17: Chris@17: /** Chris@17: * Tests URL resolution when the resource URL must be actively discovered by Chris@17: * scanning the asset. Chris@17: * Chris@17: * @param string $url Chris@17: * The asset URL to resolve. Chris@17: * @param string $resource_url Chris@17: * The expected oEmbed resource URL of the asset. Chris@17: * Chris@17: * @covers ::discoverResourceUrl Chris@17: * @covers ::getProviderByUrl Chris@17: * @covers ::getResourceUrl Chris@17: * Chris@17: * @dataProvider providerUrlDiscovery Chris@17: */ Chris@17: public function testUrlDiscovery($url, $resource_url) { Chris@17: $this->assertSame( Chris@17: $this->container->get('media.oembed.url_resolver')->getResourceUrl($url), Chris@17: $resource_url Chris@17: ); Chris@17: } Chris@17: Chris@17: }