ResourceFetcherTest.php

Same filename in this branch
  1. 9 core/modules/media/tests/src/Unit/ResourceFetcherTest.php
  2. 9 core/modules/media/tests/src/Kernel/ResourceFetcherTest.php
Same filename and directory in other branches
  1. 8.9.x core/modules/media/tests/src/Functional/ResourceFetcherTest.php
  2. 10 core/modules/media/tests/src/Unit/ResourceFetcherTest.php
  3. 10 core/modules/media/tests/src/Functional/ResourceFetcherTest.php
  4. 11.x core/modules/media/tests/src/Unit/ResourceFetcherTest.php
  5. 11.x core/modules/media/tests/src/Functional/ResourceFetcherTest.php

Namespace

Drupal\Tests\media\Functional

File

core/modules/media/tests/src/Functional/ResourceFetcherTest.php

View source
<?php

namespace Drupal\Tests\media\Functional;

use Drupal\media\OEmbed\Resource;
use Drupal\Tests\media\Traits\OEmbedTestTrait;

/**
 * Tests the oEmbed resource fetcher service.
 *
 * @coversDefaultClass \Drupal\media\OEmbed\ResourceFetcher
 *
 * @group media
 */
class ResourceFetcherTest extends MediaFunctionalTestBase {
    use OEmbedTestTrait;
    
    /**
     * {@inheritdoc}
     */
    protected $defaultTheme = 'stark';
    
    /**
     * {@inheritdoc}
     */
    protected function setUp() : void {
        parent::setUp();
        $this->useFixtureProviders();
        $this->lockHttpClientToFixtures();
    }
    
    /**
     * Data provider for testFetchResource().
     *
     * @return array
     */
    public function providerFetchResource() {
        return [
            'JSON resource' => [
                'video_vimeo.json',
                'Vimeo',
                'Drupal Rap Video - Schipulcon09',
            ],
            'XML resource' => [
                'video_collegehumor.xml',
                'CollegeHumor',
                "Let's Not Get a Drink Sometime",
            ],
        ];
    }
    
    /**
     * Tests resource fetching.
     *
     * @param string $resource_url
     *   The URL of the resource to fetch, relative to the base URL.
     * @param string $provider_name
     *   The expected name of the resource provider.
     * @param string $title
     *   The expected title of the resource.
     *
     * @covers ::fetchResource
     *
     * @dataProvider providerFetchResource
     */
    public function testFetchResource($resource_url, $provider_name, $title) {
        
        /** @var \Drupal\media\OEmbed\Resource $resource */
        $resource = $this->container
            ->get('media.oembed.resource_fetcher')
            ->fetchResource($resource_url);
        $this->assertInstanceOf(Resource::class, $resource);
        $this->assertSame($provider_name, $resource->getProvider()
            ->getName());
        $this->assertSame($title, $resource->getTitle());
    }

}

Classes

Title Deprecated Summary
ResourceFetcherTest Tests the oEmbed resource fetcher service.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.