public function UnsavedUserFieldAccessTest::testNameAccessForUnsavedUser in User protect 8
Tests field access for an unsaved user's name.
File
- tests/
src/ Functional/ UnsavedUserFieldAccessTest.php, line 66
Class
- UnsavedUserFieldAccessTest
- Tests field access for an unsaved user.
Namespace
Drupal\Tests\userprotect\FunctionalCode
public function testNameAccessForUnsavedUser() {
$module_handler = $this->container
->get('module_handler');
$module_installer = $this->container
->get('module_installer');
// Create an unsaved user entity.
$unsavedUserEntity = User::create([]);
// The logged in user should have the privileges to edit the unsaved user's
// name.
$this
->assertTrue($unsavedUserEntity
->isAnonymous(), 'Unsaved user is considered anonymous when userprotect is installed.');
$this
->assertTrue($unsavedUserEntity
->get('name')
->access('edit'), 'Logged in user is allowed to edit name field when userprotect is installed.');
// Uninstall userprotect and verify that logged in user has privileges to
// edit the unsaved user's name.
$module_installer
->uninstall([
'userprotect_test',
'userprotect',
]);
// Workaround https://www.drupal.org/node/2021959
// See \Drupal\Core\Test\FunctionalTestSetupTrait::rebuildContainer.
$this
->rebuildContainer();
$module_handler = $this->container
->get('module_handler');
$this
->assertFalse($module_handler
->moduleExists('userprotect'), 'Userprotect uninstalled successfully.');
$this
->assertTrue($unsavedUserEntity
->isAnonymous(), 'Unsaved user is considered anonymous when userprotect is uninstalled.');
$this
->assertTrue($unsavedUserEntity
->get('name')
->access('edit'), 'Logged in user is allowed to edit name field when userprotect is uninstalled.');
}