function OEmbedIframeControllerTest::testResponseCacheMaxAgeUponResourceException

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

Tests that the response max age is set to 0 when a ResourceException is raised while fetching the resource.

Return value

void No return value.

File

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

Class

OEmbedIframeControllerTest
Tests Drupal\media\Controller\OEmbedIframeController.

Namespace

Drupal\Tests\media\Kernel

Code

public function testResponseCacheMaxAgeUponResourceException() : 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);
  $resource_fetcher->fetchResource(Argument::cetera())
    ->willThrow(new ResourceException('Error while fetching resource.', 'https://youtube.com/foo'));
  $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(0, $response->getCacheableMetadata()
    ->getCacheMaxAge());
}

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