Further Drupal 8.6.4 changes. Some core files were not committed before a commit...
[yaffs-website] / web / core / modules / media / tests / src / Functional / ResourceFetcherTest.php
1 <?php
2
3 namespace Drupal\Tests\media\Functional;
4
5 use Drupal\media\OEmbed\Resource;
6 use Drupal\Tests\media\Traits\OEmbedTestTrait;
7
8 /**
9  * Tests the oEmbed resource fetcher service.
10  *
11  * @coversDefaultClass \Drupal\media\OEmbed\ResourceFetcher
12  *
13  * @group media
14  */
15 class ResourceFetcherTest extends MediaFunctionalTestBase {
16
17   use OEmbedTestTrait;
18
19   /**
20    * {@inheritdoc}
21    */
22   protected function setUp() {
23     parent::setUp();
24     $this->useFixtureProviders();
25     $this->lockHttpClientToFixtures();
26   }
27
28   /**
29    * Data provider for testFetchResource().
30    *
31    * @return array
32    */
33   public function providerFetchResource() {
34     return [
35       'JSON resource' => [
36         'video_vimeo.json',
37         'Vimeo',
38         'Drupal Rap Video - Schipulcon09',
39       ],
40       'XML resource' => [
41         'video_collegehumor.xml',
42         'CollegeHumor',
43         "Let's Not Get a Drink Sometime",
44       ],
45     ];
46   }
47
48   /**
49    * Tests resource fetching.
50    *
51    * @param string $resource_url
52    *   The URL of the resource to fetch, relative to the base URL.
53    * @param string $provider_name
54    *   The expected name of the resource provider.
55    * @param string $title
56    *   The expected title of the resource.
57    *
58    * @covers ::fetchResource
59    *
60    * @dataProvider providerFetchResource
61    */
62   public function testFetchResource($resource_url, $provider_name, $title) {
63     /** @var \Drupal\media\OEmbed\Resource $resource */
64     $resource = $this->container->get('media.oembed.resource_fetcher')
65       ->fetchResource($resource_url);
66
67     $this->assertInstanceOf(Resource::class, $resource);
68     $this->assertSame($provider_name, $resource->getProvider()->getName());
69     $this->assertSame($title, $resource->getTitle());
70   }
71
72 }