ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
FigRequestCookiesTest.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Dflydev\FigCookies;
4 
6 {
10  public function it_gets_cookies()
11  {
12  $request = (new FigCookieTestingRequest())
13  ->withHeader(Cookies::COOKIE_HEADER, 'theme=light; sessionToken=RAPELCGRQ; hello=world')
14  ;
15 
16  $this->assertEquals(
17  'RAPELCGRQ',
18  FigRequestCookies::get($request, 'sessionToken')->getValue()
19  );
20  }
21 
25  public function it_sets_cookies()
26  {
27  $request = (new FigCookieTestingRequest())
28  ->withHeader(Cookies::COOKIE_HEADER, 'theme=light; sessionToken=RAPELCGRQ; hello=world')
29  ;
30 
31  $request = FigRequestCookies::set($request, Cookie::create('hello', 'WORLD!'));
32 
33  $this->assertEquals(
34  'theme=light; sessionToken=RAPELCGRQ; hello=WORLD%21',
35  $request->getHeaderLine('Cookie')
36  );
37  }
38 
42  public function it_modifies_cookies()
43  {
44  $request = (new FigCookieTestingRequest())
45  ->withHeader(Cookies::COOKIE_HEADER, 'theme=light; sessionToken=RAPELCGRQ; hello=world')
46  ;
47 
48  $request = FigRequestCookies::modify($request, 'hello', function (Cookie $cookie) {
49  return $cookie->withValue(strtoupper($cookie->getName()));
50  });
51 
52  $this->assertEquals(
53  'theme=light; sessionToken=RAPELCGRQ; hello=HELLO',
54  $request->getHeaderLine('Cookie')
55  );
56  }
57 
61  public function it_removes_cookies()
62  {
63  $request = (new FigCookieTestingRequest())
64  ->withHeader(Cookies::COOKIE_HEADER, 'theme=light; sessionToken=RAPELCGRQ; hello=world')
65  ;
66 
67  $request = FigRequestCookies::remove($request, 'sessionToken');
68 
69  $this->assertEquals(
70  'theme=light; hello=world',
71  $request->getHeaderLine('Cookie')
72  );
73  }
74 }
static get(RequestInterface $request, $name, $value=null)
static create($name, $value=null)
Create a Cookie.
Definition: Cookie.php:73
const COOKIE_HEADER
The name of the Cookie header.
Definition: Cookies.php:12
static set(RequestInterface $request, Cookie $cookie)
static modify(RequestInterface $request, $name, $modify)
static remove(RequestInterface $request, $name)
withValue($value=null)
Definition: Cookie.php:47