assertNoCacheContext example

$this->grantPermissions($role$permissions);
    $this->drupalGet('media/add/' . $media_type->id());
    $this->assertCacheContext('user.permissions');
    $assert_session->statusCodeEquals(200);
    user_role_revoke_permissions($role->id()$permissions);
    $role = Role::load(RoleInterface::AUTHENTICATED_ID);

    // Verify the author can not view the unpublished media item without     // 'view own unpublished media' permission.     $this->grantPermissions($role['view media']);
    $this->drupalGet('media/' . $user_media->id());
    $this->assertNoCacheContext('user');
    $this->assertCacheContext('user.permissions');
    $assert_session->statusCodeEquals(200);
    $user_media->setUnpublished()->save();
    $this->drupalGet('media/' . $user_media->id());
    $this->assertCacheContext('user.permissions');
    $assert_session->statusCodeEquals(403);
    $access_result = $user_media->access('view', NULL, TRUE);
    $this->assertSame("The user must be the owner and the 'view own unpublished media' permission is required when the media item is unpublished.", $access_result->getReason());
    $this->grantPermissions($role['view own unpublished media']);
    $this->drupalGet('media/' . $user_media->id());
    $this->assertCacheContext('user');
    

  public function testNodeAccessCacheabilitySafeguard() {
    // The node grants cache context should be added automatically.     $this->drupalGet(new Url('node_access_test_auto_bubbling'));
    $this->assertCacheContext('user.node_grants:view');

    // The root user has the 'bypass node access' permission, which means the     // node grants cache context is not necessary.     $this->drupalLogin($this->rootUser);
    $this->drupalGet(new Url('node_access_test_auto_bubbling'));
    $this->assertNoCacheContext('user.node_grants:view');
    $this->drupalLogout();

    // Uninstall the module with the only hook_node_grants() implementation.     $this->container->get('module_installer')->uninstall(['node_access_test']);
    $this->rebuildContainer();

    // Because there are no node grants defined, there also is no need for the     // node grants cache context to be bubbled.     $this->drupalGet(new Url('node_access_test_auto_bubbling'));
    $this->assertNoCacheContext('user.node_grants:view');
  }

  
Home | Imprint | This part of the site doesn't use cookies.