function UserEditTest::testAdminSelfBlocking

Tests that an admin cannot edit their own account status.

File

core/modules/user/tests/src/Functional/UserEditTest.php, line 266

Class

UserEditTest
Tests user edit page.

Namespace

Drupal\Tests\user\Functional

Code

public function testAdminSelfBlocking() : void {
  // Create an admin user with permission to manage other users.
  $admin = $this->drupalCreateUser([
    'administer users',
  ]);
  $user = $this->drupalCreateUser();
  // Log in as the admin and attempt to edit their own profile.
  $this->drupalLogin($admin);
  $this->drupalGet("user/" . $admin->id() . "/edit");
  // Ensure the status field is not rendered.
  $this->assertSession()
    ->fieldNotExists('edit-status-0');
  $this->assertSession()
    ->fieldNotExists('edit-status-1');
  // Test editing another user to ensure the status field is rendered.
  $this->drupalGet("user/" . $user->id() . "/edit");
  $this->assertSession()
    ->fieldExists('edit-status-0');
  $this->assertSession()
    ->fieldEnabled('edit-status-0');
  $this->assertSession()
    ->fieldEnabled('edit-status-1');
}

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