You are here

class UserCacheTagsTest in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/user/tests/src/Functional/UserCacheTagsTest.php \Drupal\Tests\user\Functional\UserCacheTagsTest
  2. 9 core/modules/user/tests/src/Functional/UserCacheTagsTest.php \Drupal\Tests\user\Functional\UserCacheTagsTest

Tests the User entity's cache tags.

@group user

Hierarchy

Expanded class hierarchy of UserCacheTagsTest

File

core/modules/user/tests/src/Functional/UserCacheTagsTest.php, line 15

Namespace

Drupal\Tests\user\Functional
View source
class UserCacheTagsTest extends EntityWithUriCacheTagsTestBase {

  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'user',
  ];

  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'stark';

  /**
   * {@inheritdoc}
   */
  protected function setUp() : void {
    parent::setUp();

    // Give anonymous users permission to view user profiles, so that we can
    // verify the cache tags of cached versions of user profile pages.
    $user_role = Role::load(RoleInterface::ANONYMOUS_ID);
    $user_role
      ->grantPermission('access user profiles');
    $user_role
      ->save();
  }

  /**
   * {@inheritdoc}
   */
  protected function createEntity() {

    // Create a "Llama" user.
    $user = User::create([
      'name' => 'Llama',
      'status' => TRUE,
    ]);
    $user
      ->save();
    return $user;
  }

  /**
   * {@inheritdoc}
   */
  protected function getAdditionalCacheTagsForEntityListing() {
    return [
      'user:0',
      'user:1',
    ];
  }

}

Members