function ExceptionStatusCodeCacheContextTest::testGetContext

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/Tests/Core/Cache/Context/ExceptionStatusCodeCacheContextTest.php \Drupal\Tests\Core\Cache\Context\ExceptionStatusCodeCacheContextTest::testGetContext()

Tests get context.

Attributes

#[DataProvider('providerTestGetContext')]

File

core/tests/Drupal/Tests/Core/Cache/Context/ExceptionStatusCodeCacheContextTest.php, line 29

Class

ExceptionStatusCodeCacheContextTest
Tests Drupal\Core\Cache\Context\CookiesCacheContext.

Namespace

Drupal\Tests\Core\Cache\Context

Code

public function testGetContext(?\Exception $exception, string $result) : void {
  $request_stack = new RequestStack();
  $request = Request::create('/', 'GET');
  if (isset($exception)) {
    $request->attributes
      ->set('exception', $exception);
  }
  $request_stack->push($request);
  $cache_context = new ExceptionStatusCodeCacheContext($request_stack);
  $this->assertSame($cache_context->getContext(), $result);
}

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