ProtectionRuleBypassTest.php in User protect 8
File
tests/src/Kernel/ProtectionRuleBypassTest.php
View source
<?php
namespace Drupal\Tests\userprotect\Kernel;
class ProtectionRuleBypassTest extends UserProtectKernelTestBase {
protected $accessController;
protected function setUp() {
parent::setUp();
$this->accessController = \Drupal::entityTypeManager()
->getAccessControlHandler('user');
}
public function testRoleNameEditProtectionBypass() {
$this
->doRoleProtectionBypassTest('user_name', 'user_name');
}
public function testRoleMailEditProtectionBypass() {
$this
->doRoleProtectionBypassTest('user_mail', 'user_mail');
}
public function testRolePassEditProtectionBypass() {
$this
->doRoleProtectionBypassTest('user_pass', 'user_pass');
}
public function testRoleEditProtectionBypass() {
$this
->doRoleProtectionBypassTest('user_edit', 'update');
}
public function testRoleDeleteProtectionBypass() {
$this
->doRoleProtectionBypassTest('user_delete', 'delete');
}
protected function doRoleProtectionBypassTest($plugin, $operation) {
$rid = $this
->createProtectedRole([
$plugin,
]);
$protected_account = $this
->drupalCreateUser();
$protected_account
->addRole($rid);
$account = $this
->drupalCreateUser([
'administer users',
'userprotect.dummy.bypass',
]);
$this
->assertTrue($this->accessController
->access($protected_account, $operation, $account));
}
public function testUserNameEditProtectionBypass() {
$this
->doUserProtectionBypassTest('user_name', 'user_name');
}
public function testUserMailEditProtectionBypass() {
$this
->doUserProtectionBypassTest('user_mail', 'user_mail');
}
public function testUserPassEditProtectionBypass() {
$this
->doUserProtectionBypassTest('user_pass', 'user_pass');
}
public function testUserEditProtectionBypass() {
$this
->doUserProtectionBypassTest('user_edit', 'update');
}
public function testUserDeleteProtectionBypass() {
$this
->doUserProtectionBypassTest('user_delete', 'delete');
}
protected function doUserProtectionBypassTest($plugin, $operation) {
$protected_account = $this
->createProtectedUser([
$plugin,
]);
$account = $this
->drupalCreateUser([
'administer users',
'userprotect.dummy.bypass',
]);
$this
->assertTrue($this->accessController
->access($protected_account, $operation, $account));
}
}