UserProtectionTest.php in User protect 8
File
tests/src/Functional/UserProtectionTest.php
View source
<?php
namespace Drupal\Tests\userprotect\Functional;
class UserProtectionTest extends UserProtectBrowserTestBase {
protected $account;
protected function setUp() {
parent::setUp();
$this->account = $this
->drupalCreateUser([
'administer users',
'administer permissions',
]);
$this
->drupalLogin($this->account);
}
public function testNameProtection() {
$protected_account = $this
->createProtectedUser([
'user_name',
]);
$this
->drupalGet('user/' . $protected_account
->id() . '/edit');
$this
->assertSession()
->fieldNotExists('name');
}
public function testMailProtection() {
$protected_account = $this
->createProtectedUser([
'user_mail',
]);
$this
->drupalGet('user/' . $protected_account
->id() . '/edit');
$this
->assertSession()
->fieldDisabled('mail');
}
public function testPassProtection() {
$protected_account = $this
->createProtectedUser([
'user_pass',
]);
$this
->drupalGet('user/' . $protected_account
->id() . '/edit');
$this
->assertSession()
->fieldNotExists('pass[pass1]');
$this
->assertSession()
->fieldNotExists('pass[pass2]');
}
public function testStatusProtection() {
$protected_account = $this
->createProtectedUser([
'user_status',
]);
$this
->drupalGet('user/' . $protected_account
->id() . '/edit');
$this
->assertSession()
->fieldNotExists('status');
}
public function testRolesProtection() {
$protected_account = $this
->createProtectedUser([
'user_roles',
]);
$rid1 = $this
->drupalCreateRole([]);
$protected_account
->addRole($rid1);
$protected_account
->save();
$rid2 = $this
->drupalCreateRole([]);
$protected_account = $this
->reloadEntity($protected_account);
$this
->assertTrue($protected_account
->hasRole($rid1));
$this
->assertFalse($protected_account
->hasRole($rid2));
$this
->assertSession()
->fieldNotExists(sprintf('roles[%s]', $rid2));
}
}