You are here

function ToolbarAdminMenuTest::testNonCurrentUserAccountUpdates in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/toolbar/src/Tests/ToolbarAdminMenuTest.php \Drupal\toolbar\Tests\ToolbarAdminMenuTest::testNonCurrentUserAccountUpdates()

Tests that changes to a user account by another user clears the changed account's toolbar cached, not the user's who took the action.

File

core/modules/toolbar/src/Tests/ToolbarAdminMenuTest.php, line 216
Contains \Drupal\toolbar\Tests\ToolbarAdminMenuTest.

Class

ToolbarAdminMenuTest
Tests the caching of the admin menu subtree items.

Namespace

Drupal\toolbar\Tests

Code

function testNonCurrentUserAccountUpdates() {
  $admin_user_id = $this->adminUser
    ->id();
  $this->hash = $this
    ->getSubtreesHash();

  // adminUser2 will add a role to adminUser.
  $this
    ->drupalLogin($this->adminUser2);
  $rid = $this
    ->drupalCreateRole(array(
    'administer content types',
  ));

  // Get the subtree hash for adminUser2 to check later that it has not
  // changed. Request a new page to refresh the drupalSettings object.
  $this
    ->drupalGet('test-page');
  $this
    ->assertResponse(200);
  $admin_user_2_hash = $this
    ->getSubtreesHash();

  // Assign the role to the user.
  $this
    ->drupalPostForm('user/' . $admin_user_id . '/edit', array(
    "roles[{$rid}]" => $rid,
  ), t('Save'));
  $this
    ->assertText(t('The changes have been saved.'));

  // Log in adminUser and assert that the subtrees hash has changed.
  $this
    ->drupalLogin($this->adminUser);
  $this
    ->assertDifferentHash();

  // Log in adminUser2 to check that its subtrees hash has not changed.
  $this
    ->drupalLogin($this->adminUser2);
  $new_subtree_hash = $this
    ->getSubtreesHash();

  // Assert that the old adminUser subtree hash and the new adminUser
  // subtree hash are the same.
  $this
    ->assertTrue($new_subtree_hash, 'A valid hash value for the admin menu subtrees was created.');
  $this
    ->assertEqual($admin_user_2_hash, $new_subtree_hash, 'The user-specific subtree menu hash has not been updated.');
}