function EntityListBuilderTest::testCacheContexts

Same name in other branches
  1. 9 core/modules/system/tests/src/Functional/Entity/EntityListBuilderTest.php \Drupal\Tests\system\Functional\Entity\EntityListBuilderTest::testCacheContexts()
  2. 8.9.x core/modules/system/tests/src/Functional/Entity/EntityListBuilderTest.php \Drupal\Tests\system\Functional\Entity\EntityListBuilderTest::testCacheContexts()
  3. 10 core/modules/system/tests/src/Functional/Entity/EntityListBuilderTest.php \Drupal\Tests\system\Functional\Entity\EntityListBuilderTest::testCacheContexts()

Tests that the correct cache contexts are set.

File

core/modules/system/tests/src/Functional/Entity/EntityListBuilderTest.php, line 65

Class

EntityListBuilderTest
Tests entity list builder functionality.

Namespace

Drupal\Tests\system\Functional\Entity

Code

public function testCacheContexts() : void {
    
    /** @var \Drupal\Core\Entity\EntityListBuilderInterface $list_builder */
    $list_builder = $this->container
        ->get('entity_type.manager')
        ->getListBuilder('entity_test');
    $build = $list_builder->render();
    $this->container
        ->get('renderer')
        ->renderRoot($build);
    $this->assertEqualsCanonicalizing([
        'entity_test_view_grants',
        'languages:' . LanguageInterface::TYPE_INTERFACE,
        'theme',
        'url.query_args.pagers:0',
        'user.permissions',
    ], $build['#cache']['contexts']);
}

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