ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
FigResponseCookiesTest.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Dflydev\FigCookies;
4 
6 {
10  public function it_gets_cookies()
11  {
13 
15  ->withAddedHeader(SetCookies::SET_COOKIE_HEADER, SetCookie::create('theme', 'light'))
16  ->withAddedHeader(SetCookies::SET_COOKIE_HEADER, SetCookie::create('sessionToken', 'ENCRYPTED'))
17  ->withAddedHeader(SetCookies::SET_COOKIE_HEADER, SetCookie::create('hello', 'world'))
18  ;
19 
20  $this->assertEquals(
21  'ENCRYPTED',
22  FigResponseCookies::get($response, 'sessionToken')->getValue()
23  );
24  }
25 
29  public function it_sets_cookies()
30  {
32 
34  ->withAddedHeader(SetCookies::SET_COOKIE_HEADER, SetCookie::create('theme', 'light'))
35  ->withAddedHeader(SetCookies::SET_COOKIE_HEADER, SetCookie::create('sessionToken', 'ENCRYPTED'))
36  ->withAddedHeader(SetCookies::SET_COOKIE_HEADER, SetCookie::create('hello', 'world'))
37  ;
38 
40 
41  $this->assertEquals(
42  'theme=light,sessionToken=ENCRYPTED,hello=WORLD%21',
43  $response->getHeaderLine('Set-Cookie')
44  );
45  }
46 
50  public function it_modifies_cookies()
51  {
53 
55  ->withAddedHeader(SetCookies::SET_COOKIE_HEADER, SetCookie::create('theme', 'light'))
56  ->withAddedHeader(SetCookies::SET_COOKIE_HEADER, SetCookie::create('sessionToken', 'ENCRYPTED'))
57  ->withAddedHeader(SetCookies::SET_COOKIE_HEADER, SetCookie::create('hello', 'world'))
58  ;
59 
60  $response = FigResponseCookies::modify($response, 'hello', function (SetCookie $setCookie) {
61  return $setCookie->withValue(strtoupper($setCookie->getName()));
62  });
63 
64  $this->assertEquals(
65  'theme=light,sessionToken=ENCRYPTED,hello=HELLO',
66  $response->getHeaderLine('Set-Cookie')
67  );
68  }
69 
73  public function it_removes_cookies()
74  {
76 
78  ->withAddedHeader(SetCookies::SET_COOKIE_HEADER, SetCookie::create('theme', 'light'))
79  ->withAddedHeader(SetCookies::SET_COOKIE_HEADER, SetCookie::create('sessionToken', 'ENCRYPTED'))
80  ->withAddedHeader(SetCookies::SET_COOKIE_HEADER, SetCookie::create('hello', 'world'))
81  ;
82 
84 
85  $this->assertEquals(
86  'theme=light,hello=world',
87  $response->getHeaderLine('Set-Cookie')
88  );
89  }
90 }
static remove(ResponseInterface $response, $name)
static set(ResponseInterface $response, SetCookie $setCookie)
static create($name, $value=null)
Definition: SetCookie.php:173
const SET_COOKIE_HEADER
The name of the Set-Cookie header.
Definition: SetCookies.php:12
static modify(ResponseInterface $response, $name, $modify)
static get(ResponseInterface $response, $name, $value=null)
$response