You are here

protected function ProfileTestTrait::createProfile in Profile 8

Create a user, and optionally a profile.

Parameters

\Drupal\profile\Entity\ProfileTypeInterface $profile_type: A profile type for the created profile entity.

\Drupal\user\UserInterface $user: A user to create a profile.

Return value

\Drupal\profile\Entity\ProfileInterface A profile for a user.

3 calls to ProfileTestTrait::createProfile()
ProfileRoleAccessTest::testProfileOperations in tests/src/Kernel/ProfileRoleAccessTest.php
Tests profile operations role access checks.
ProfileViewTest::testProfileRelationship in tests/src/Kernel/ProfileViewTest.php
Tests views relationship with multiple referenced entities.
UserTest::testAnonymousEdit in tests/src/Functional/UserTest.php
Tests that a profile belonging to an anonymous user can be edited.

File

src/ProfileTestTrait.php, line 59

Class

ProfileTestTrait
Provides methods to create additional profiles and profile_types.

Namespace

Drupal\profile

Code

protected function createProfile(ProfileTypeInterface $profile_type, UserInterface $user) {
  $profile = Profile::create([
    'type' => $profile_type
      ->id(),
    'uid' => $user
      ->id(),
  ]);
  $profile
    ->save();
  return $profile;
}