function ProviderRepositoryTest::testSuccessfulFetch

Same name 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 \Drupal\media\OEmbed\ProviderRepository

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.