class ExceptionStatusCodeCacheContextTest
Same name and namespace in other branches
- main core/tests/Drupal/Tests/Core/Cache/Context/ExceptionStatusCodeCacheContextTest.php \Drupal\Tests\Core\Cache\Context\ExceptionStatusCodeCacheContextTest
Tests Drupal\Core\Cache\Context\CookiesCacheContext.
Attributes
#[CoversClass(ExceptionStatusCodeCacheContext::class)]
#[Group('Cache')]
Hierarchy
- class \Drupal\Tests\UnitTestCase uses \Drupal\Tests\DrupalTestCaseTrait, \Drupal\Tests\PhpUnitCompatibilityTrait, \Prophecy\PhpUnit\ProphecyTrait, \Drupal\TestTools\Extension\DeprecationBridge\ExpectDeprecationTrait, \Drupal\Tests\RandomGeneratorTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\Core\Cache\Context\ExceptionStatusCodeCacheContextTest extends \Drupal\Tests\UnitTestCase
Expanded class hierarchy of ExceptionStatusCodeCacheContextTest
File
-
core/
tests/ Drupal/ Tests/ Core/ Cache/ Context/ ExceptionStatusCodeCacheContextTest.php, line 22
Namespace
Drupal\Tests\Core\Cache\ContextView source
class ExceptionStatusCodeCacheContextTest extends UnitTestCase {
/**
* Tests get context.
*/
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);
}
/**
* Provides a list of cookies and expected cache contexts.
*/
public static function providerTestGetContext() : array {
return [
[
new NotFoundHttpException(),
'404',
],
[
new AccessDeniedHttpException(),
'403',
],
[
new BadRequestHttpException(),
'400',
],
[
new MethodNotAllowedHttpException([
'POST',
]),
'405',
],
[
NULL,
'0',
],
];
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.