public function AvatarKitManagerTest::testUnsavedUser in Avatar Kit 8
Test unsaved user (such as user registration form)
File
- tests/
src/ Kernel/ AvatarKitManagerTest.php, line 168
Class
- AvatarKitManagerTest
- Tests Avatar Manager.
Namespace
Drupal\Tests\avatars\KernelCode
public function testUnsavedUser() {
$generator_1 = AvatarGenerator::create([
'label' => $this
->randomMachineName(),
'id' => $this
->randomMachineName(),
'plugin' => 'avatars_test_static',
]);
$generator_1
->setStatus(TRUE)
->save();
$this
->installConfig([
'user',
]);
$this
->installEntitySchema('avatars_preview');
// The anonymous role must be granted access to at least on generator
// otherwise nothing will tested.
Role::load(RoleInterface::ANONYMOUS_ID)
->grantPermission('avatars avatar_generator user ' . $generator_1
->id())
->save();
// Make sure no 'name' is set so an exception is thrown if a user was to be
// saved.
$user = User::create();
$user_count_before = count(User::loadMultiple());
$this->avatarManager
->refreshAllAvatars($user);
// Ensure the temporary user was not saved because the entity reference
// field for avatar_preview will attempt to save it.
$this
->assertEquals($user_count_before, count(User::loadMultiple()));
}