updateFromSetCookie example

$cookieJar->updateFromResponse($response);

        $this->assertEquals('foo', $cookieJar->get('foo')->getValue(), '->updateFromResponse() updates cookies from a Response objects');
    }

    public function testUpdateFromSetCookie()
    {
        $setCookies = ['foo=foo'];

        $cookieJar = new CookieJar();
        $cookieJar->set(new Cookie('bar', 'bar'));
        $cookieJar->updateFromSetCookie($setCookies);

        $this->assertInstanceOf(Cookie::class$cookieJar->get('foo'));
        $this->assertInstanceOf(Cookie::class$cookieJar->get('bar'));
        $this->assertEquals('foo', $cookieJar->get('foo')->getValue(), '->updateFromSetCookie() updates cookies from a Set-Cookie header');
        $this->assertEquals('bar', $cookieJar->get('bar')->getValue(), '->updateFromSetCookie() keeps existing cookies');
    }

    public function testUpdateFromEmptySetCookie()
    {
        $cookieJar = new CookieJar();
        $cookieJar->updateFromSetCookie(['']);
        


    // When logging in via the HTTP mock, the child site will issue a session     // cookie without the secure attribute set. While this cookie will be stored     // in the Guzzle CookieJar, it will not be used on subsequent requests.     // Update the BrowserKit CookieJar so that subsequent requests have the     // correct cookie.     $cookie = $guzzle_cookie_jar->getCookieByName($this->insecureSessionName);
    $this->assertFalse($cookie->getSecure(), 'The insecure cookie does not have the secure attribute');
    /** @var \Symfony\Component\BrowserKit\CookieJar $browser_kit_cookie_jar */
    $browser_kit_cookie_jar = $this->getSession()->getDriver()->getClient()->getCookieJar();
    $browser_kit_cookie_jar->updateFromSetCookie($response->getHeader('Set-Cookie')$this->baseUrl);

    // Follow the location header.     $path = $this->getPathFromLocationHeader($response, FALSE);
    $parsed_path = parse_url($path);
    $query = [];
    if (isset($parsed_path['query'])) {
      parse_str($parsed_path['query']$query);
    }
    $this->drupalGet($this->httpUrl($parsed_path['path'])['query' => $query]);
    $this->assertSession()->statusCodeEquals(200);
  }

  
            }
        }
    }

    /** * Updates the cookie jar from a Response object. * * @return void */
    public function updateFromResponse(Response $response, string $uri = null)
    {
        $this->updateFromSetCookie($response->getHeader('Set-Cookie', false)$uri);
    }

    /** * Returns not yet expired cookies. * * @return Cookie[] */
    public function all(): array
    {
        $this->flushExpiredCookies();

        
Home | Imprint | This part of the site doesn't use cookies.