function ProviderRepositoryTest::testSuccessfulFetch

Same name and namespace in other branches
  1. 9 core/modules/media/tests/src/Unit/ProviderRepositoryTest.php \Drupal\Tests\media\Unit\ProviderRepositoryTest::testSuccessfulFetch()
  2. 11.x core/modules/media/tests/src/Unit/ProviderRepositoryTest.php \Drupal\Tests\media\Unit\ProviderRepositoryTest::testSuccessfulFetch()

Tests that a successful fetch stores the provider database in key-value.

File

core/modules/media/tests/src/Unit/ProviderRepositoryTest.php, line 98

Class

ProviderRepositoryTest
@coversDefaultClass <a href="/api/drupal/core%21modules%21media%21src%21OEmbed%21ProviderRepository.php/class/ProviderRepository/10" title="Retrieves and caches information about oEmbed providers." class="local">\Drupal\media\OEmbed\ProviderRepository</a>

Namespace

Drupal\Tests\media\Unit

Code

public function testSuccessfulFetch() : void {
    $body = <<<END
[
  {
    "provider_name": "YouTube",
    "provider_url": "https:\\/\\/www.youtube.com\\/",
    "endpoints": [
      {
        "schemes": [
          "https:\\/\\/*.youtube.com\\/watch*",
          "https:\\/\\/*.youtube.com\\/v\\/*"
        ],
        "url": "https:\\/\\/www.youtube.com\\/oembed",
        "discovery": true
      }
    ]
  }
]
END;
    $response = new Response(200, [], $body);
    $this->responses
        ->append($response);
    $provider = $this->repository
        ->get('YouTube');
    $stored_data = [
        'data' => [
            'YouTube' => $provider,
        ],
        'expires' => $this->currentTime + 604800,
    ];
    $this->assertSame($stored_data, $this->keyValue
        ->get('oembed_providers'));
}

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