trait BasicAuthTestTrait (View source)

deprecated in drupal:8.3.0 and is removed from drupal:9.0.0. Use \Drupal\Tests\basic_auth\Traits\BasicAuthTestTrait instead.

Provides common functionality for Basic Authentication test classes.

Methods

string
basicAuthGet(Url|string $path, string $username, string $password, array $options = [])

Retrieves a Drupal path or an absolute path using basic authentication.

string
basicAuthPostForm(string $path, array $edit, string $submit, string $username, string $password, array $options = [], string $form_html_id = NULL, string $extra_post = NULL)

Executes a form submission using basic authentication.

array
getBasicAuthHeaders(string $username, string $password)

Returns HTTP headers that can be used for basic authentication in Curl.

Details

protected string basicAuthGet(Url|string $path, string $username, string $password, array $options = [])

Retrieves a Drupal path or an absolute path using basic authentication.

Parameters

Url|string $path

Drupal path or URL to load into the internal browser.

string $username

The username to use for basic authentication.

string $password

The password to use for basic authentication.

array $options

(optional) Options to be forwarded to the url generator.

Return Value

string

The retrieved HTML string, also available as $this->getRawContent().

protected string basicAuthPostForm(string $path, array $edit, string $submit, string $username, string $password, array $options = [], string $form_html_id = NULL, string $extra_post = NULL)

Executes a form submission using basic authentication.

Parameters

string $path

Location of the post form.

array $edit

Field data in an associative array.

string $submit

Value of the submit button whose click is to be emulated.

string $username

The username to use for basic authentication.

string $password

The password to use for basic authentication.

array $options

Options to be forwarded to the url generator.

string $form_html_id

(optional) HTML ID of the form to be submitted.

string $extra_post

(optional) A string of additional data to append to the POST submission.

Return Value

string

The retrieved HTML string.

See also

WebTestBase::drupalPostForm

protected array getBasicAuthHeaders(string $username, string $password)

Returns HTTP headers that can be used for basic authentication in Curl.

Parameters

string $username

The username to use for basic authentication.

string $password

The password to use for basic authentication.

Return Value

array

An array of raw request headers as used by curl_setopt().