function RESTTestBase::cookies

Calculates cookies used by guzzle later.

Return value

\GuzzleHttp\Cookie\CookieJarInterface The used CURL options in guzzle.

1 call to RESTTestBase::cookies()
RESTTestBase::httpRequest in core/modules/rest/src/Tests/RESTTestBase.php
Helper function to issue a HTTP request with simpletest's cURL.

File

core/modules/rest/src/Tests/RESTTestBase.php, line 103

Class

RESTTestBase
Test helper class that provides a REST client method to send HTTP requests.

Namespace

Drupal\rest\Tests

Code

protected function cookies() {
    $cookies = [];
    foreach ($this->cookies as $key => $cookie) {
        $cookies[$key][] = $cookie['value'];
    }
    $request = \Drupal::request();
    $cookies = NestedArray::mergeDeep($cookies, $this->extractCookiesFromRequest($request));
    $cookie_jar = new FileCookieJar($this->cookieFile);
    foreach ($cookies as $key => $cookie_values) {
        foreach ($cookie_values as $cookie_value) {
            // setcookie() sets the value of a cookie to be deleted, when its gonna
            // be removed.
            if ($cookie_value !== 'deleted') {
                $cookie_jar->setCookie(new SetCookie([
                    'Name' => $key,
                    'Value' => $cookie_value,
                    'Domain' => $request->getHost(),
                ]));
            }
        }
    }
    return $cookie_jar;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.