function OEmbedIframeControllerTest::testResponseCacheMaxAge

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

Tests that the response max age is set to the same value as that of the resource.

Return value

void No return value.

File

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

Class

OEmbedIframeControllerTest
Tests Drupal\media\Controller\OEmbedIframeController.

Namespace

Drupal\Tests\media\Kernel

Code

public function testResponseCacheMaxAge() : 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: 1234);
  $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);
  $this->assertEquals(1234, $response->getCacheableMetadata()
    ->getCacheMaxAge());
}

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