You are here

protected function RestRegisterUserTest::createRequestBody in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/user/tests/src/Functional/RestRegisterUserTest.php \Drupal\Tests\user\Functional\RestRegisterUserTest::createRequestBody()

Create the request body.

Parameters

string $name: Name.

bool $include_password: Include Password.

bool $include_email: Include Email.

Return value

array Return the request body.

1 call to RestRegisterUserTest::createRequestBody()
RestRegisterUserTest::registerRequest in core/modules/user/tests/src/Functional/RestRegisterUserTest.php
Make a REST user registration request.

File

core/modules/user/tests/src/Functional/RestRegisterUserTest.php, line 159

Class

RestRegisterUserTest
Tests user registration via REST resource.

Namespace

Drupal\Tests\user\Functional

Code

protected function createRequestBody($name, $include_password = TRUE, $include_email = TRUE) {
  global $base_url;
  $request_body = [
    '_links' => [
      'type' => [
        "href" => $base_url . "/rest/type/user/user",
      ],
    ],
    'langcode' => [
      [
        'value' => 'en',
      ],
    ],
    'name' => [
      [
        'value' => $name,
      ],
    ],
  ];
  if ($include_email) {
    $request_body['mail'] = [
      [
        'value' => $name . self::USER_EMAIL_DOMAIN,
      ],
    ];
  }
  if ($include_password) {
    $request_body['pass']['value'] = 'SuperSecretPassword';
  }
  return $request_body;
}