function OEmbedIframeControllerTest::testResponseCacheMaxAgeGreaterThanFiveYears

Same name and namespace in other branches
  1. main core/modules/media/tests/src/Kernel/OEmbedIframeControllerTest.php \Drupal\Tests\media\Kernel\OEmbedIframeControllerTest::testResponseCacheMaxAgeGreaterThanFiveYears()

Tests that the response max age is 5 years when the max age returned by the provider is greater than 5 years.

Return value

void No return value.

File

core/modules/media/tests/src/Kernel/OEmbedIframeControllerTest.php, line 200

Class

OEmbedIframeControllerTest
Tests Drupal\media\Controller\OEmbedIframeController.

Namespace

Drupal\Tests\media\Kernel

Code

public function testResponseCacheMaxAgeGreaterThanFiveYears() : void {
  $hash = $this->container
    ->get('media.oembed.iframe_url_helper')
    ->getHash('', 0, 0);
  $url_resolver = $this->prophesize(UrlResolverInterface::class);
  $resource_fetcher = $this->prophesize(ResourceFetcherInterface::class);
  $provider = new Provider('YouTube', 'https://youtube.com', [
    [
      'url' => 'https://youtube.com/foo',
    ],
  ]);
  $resource = Resource::rich('<iframe src="https://youtube.com/watch?feature=oembed"></iframe>', 320, 240, $provider, cache_age: 157680001);
  $resource_fetcher->fetchResource(Argument::cetera())
    ->willReturn($resource);
  $this->container
    ->set('media.oembed.url_resolver', $url_resolver->reveal());
  $this->container
    ->set('media.oembed.resource_fetcher', $resource_fetcher->reveal());
  $response = OEmbedIframeController::create($this->container)
    ->render(new Request([
    'url' => '',
    'hash' => $hash,
  ]));
  assert($response instanceof HtmlResponse);
  // The max age should be 5 years.
  $this->assertEquals(157680000, $response->getCacheableMetadata()
    ->getCacheMaxAge());
}

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