public function ToolbarAdminMenuTest::testNonCurrentUserAccountUpdates in Drupal 9
Same name and namespace in other branches
- 8 core/modules/toolbar/tests/src/Functional/ToolbarAdminMenuTest.php \Drupal\Tests\toolbar\Functional\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/ tests/ src/ Functional/ ToolbarAdminMenuTest.php, line 243
Class
- ToolbarAdminMenuTest
- Tests the caching of the admin menu subtree items.
Namespace
Drupal\Tests\toolbar\FunctionalCode
public 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([
'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
->assertSession()
->statusCodeEquals(200);
$admin_user_2_hash = $this
->getSubtreesHash();
// Assign the role to the user.
$this
->drupalGet('user/' . $admin_user_id . '/edit');
$this
->submitForm([
"roles[{$rid}]" => $rid,
], 'Save');
$this
->assertSession()
->pageTextContains('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
->assertNotEmpty($new_subtree_hash, 'A valid hash value for the admin menu subtrees was created.');
$this
->assertEquals($new_subtree_hash, $admin_user_2_hash, 'The user-specific subtree menu hash has not been updated.');
}