public function UserProtectionPermissionsTest::testEditOwnMail in User protect 8
Tests edit mail with permission "userprotect.mail.edit".
Tests if an user with the permission "userprotect.mail.edit" can edit its own mail.
File
- tests/
src/ Functional/ UserProtectionPermissionsTest.php, line 48
Class
- UserProtectionPermissionsTest
- Tests if "change own" User Protect permissions are respected.
Namespace
Drupal\Tests\userprotect\FunctionalCode
public function testEditOwnMail() {
// Create account that may edit its own mail address.
$account = $this
->drupalCreateUser([
'userprotect.mail.edit',
'userprotect.account.edit',
]);
$this
->drupalLogin($account);
$edit = [
'mail' => $this
->randomMachineName() . '@example.com',
];
$this
->drupalPostForm('user/' . $account
->id() . '/edit', $edit, t('Save'));
// Assert the mail address changed.
$account = $this
->reloadEntity($account);
$this
->assertEquals($edit['mail'], $account
->getEmail(), "The user has changed its own mail address.");
}