ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
SetCookieTest.php
Go to the documentation of this file.
1<?php
2
3namespace Dflydev\FigCookies;
4
6{
11 public function it_parses_from_set_cookie_string($cookieString, SetCookie $expectedSetCookie)
12 {
13 $setCookie = SetCookie::fromSetCookieString($cookieString);
14
15 $this->assertEquals($expectedSetCookie, $setCookie);
16 $this->assertEquals($cookieString, (string) $setCookie);
17 }
18
20 {
21 return [
22 [
23 'someCookie=',
24 SetCookie::create('someCookie'),
25 ],
26 [
27 'someCookie=someValue',
28 SetCookie::create('someCookie')
29 ->withValue('someValue')
30 ],
31 [
32 'LSID=DQAAAK%2FEaem_vYg; Path=/accounts; Expires=Wed, 13 Jan 2021 22:23:01 GMT; Secure; HttpOnly',
33 SetCookie::create('LSID')
34 ->withValue('DQAAAK/Eaem_vYg')
35 ->withPath('/accounts')
36 ->withExpires('Wed, 13 Jan 2021 22:23:01 GMT')
37 ->withSecure(true)
38 ->withHttpOnly(true)
39 ],
40 [
41 'HSID=AYQEVn%2F.DKrdst; Domain=.foo.com; Path=/; Expires=Wed, 13 Jan 2021 22:23:01 GMT; HttpOnly',
42 SetCookie::create('HSID')
43 ->withValue('AYQEVn/.DKrdst')
44 ->withDomain('.foo.com')
45 ->withPath('/')
46 ->withExpires('Wed, 13 Jan 2021 22:23:01 GMT')
47 ->withHttpOnly(true)
48 ],
49 [
50 'SSID=Ap4P%2F.GTEq; Domain=foo.com; Path=/; Expires=Wed, 13 Jan 2021 22:23:01 GMT; Secure; HttpOnly',
51 SetCookie::create('SSID')
52 ->withValue('Ap4P/.GTEq')
53 ->withDomain('foo.com')
54 ->withPath('/')
55 ->withExpires('Wed, 13 Jan 2021 22:23:01 GMT')
56 ->withSecure(true)
57 ->withHttpOnly(true)
58 ],
59 [
60 'lu=Rg3vHJZnehYLjVg7qi3bZjzg; Domain=.example.com; Path=/; Expires=Tue, 15 Jan 2013 21:47:38 GMT; HttpOnly',
62 ->withValue('Rg3vHJZnehYLjVg7qi3bZjzg')
63 ->withExpires('Tue, 15-Jan-2013 21:47:38 GMT')
64 ->withPath('/')
65 ->withDomain('.example.com')
66 ->withHttpOnly(true)
67 ],
68 [
69 'lu=Rg3vHJZnehYLjVg7qi3bZjzg; Domain=.example.com; Path=/; Max-Age=500; Secure; HttpOnly',
71 ->withValue('Rg3vHJZnehYLjVg7qi3bZjzg')
72 ->withMaxAge(500)
73 ->withPath('/')
74 ->withDomain('.example.com')
75 ->withSecure(true)
76 ->withHttpOnly(true)
77 ],
78 [
79 'lu=Rg3vHJZnehYLjVg7qi3bZjzg; Domain=.example.com; Path=/; Expires=Tue, 15 Jan 2013 21:47:38 GMT; Max-Age=500; Secure; HttpOnly',
81 ->withValue('Rg3vHJZnehYLjVg7qi3bZjzg')
82 ->withExpires('Tue, 15-Jan-2013 21:47:38 GMT')
83 ->withMaxAge(500)
84 ->withPath('/')
85 ->withDomain('.example.com')
86 ->withSecure(true)
87 ->withHttpOnly(true)
88 ],
89 [
90 'lu=Rg3vHJZnehYLjVg7qi3bZjzg; Domain=.example.com; Path=/; Expires=Tue, 15 Jan 2013 21:47:38 GMT; Max-Age=500; Secure; HttpOnly',
92 ->withValue('Rg3vHJZnehYLjVg7qi3bZjzg')
93 ->withExpires(1358286458)
94 ->withMaxAge(500)
95 ->withPath('/')
96 ->withDomain('.example.com')
97 ->withSecure(true)
98 ->withHttpOnly(true)
99 ],
100 [
101 'lu=Rg3vHJZnehYLjVg7qi3bZjzg; Domain=.example.com; Path=/; Expires=Tue, 15 Jan 2013 21:47:38 GMT; Max-Age=500; Secure; HttpOnly',
103 ->withValue('Rg3vHJZnehYLjVg7qi3bZjzg')
104 ->withExpires(new \DateTime('Tue, 15-Jan-2013 21:47:38 GMT'))
105 ->withMaxAge(500)
106 ->withPath('/')
107 ->withDomain('.example.com')
108 ->withSecure(true)
109 ->withHttpOnly(true)
110 ],
111 ];
112 }
113
117 public function it_expires_cookies()
118 {
119 $setCookie = SetCookie::createExpired('expire_immediately');
120
121 $this->assertLessThan(time(), $setCookie->getExpires());
122 }
123
128 {
129 $setCookie = SetCookie::createRememberedForever('remember_forever');
130
131 $fourYearsFromNow = (new \DateTime('+4 years'))->getTimestamp();
132 $this->assertGreaterThan($fourYearsFromNow, $setCookie->getExpires());
133 }
134}
An exception for terminatinating execution or to throw for unit testing.
it_parses_from_set_cookie_string($cookieString, SetCookie $expectedSetCookie)
static create($name, $value=null)
Definition: SetCookie.php:173
static createRememberedForever($name, $value=null)
Definition: SetCookie.php:178