ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
Dflydev\FigCookies\SetCookiesTest Class Reference
+ Inheritance diagram for Dflydev\FigCookies\SetCookiesTest:
+ Collaboration diagram for Dflydev\FigCookies\SetCookiesTest:

Public Member Functions

 it_creates_from_response ($setCookieStrings, array $expectedSetCookies)
 
 it_creates_from_set_cookie_strings ($setCookieStrings, array $expectedSetCookies)
 
 it_knows_which_set_cookies_are_available ($setCookieStrings, array $expectedSetCookies)
 
 it_gets_set_cookie_by_name ($setCookieStrings, $setCookieName, SetCookie $expectedSetCookie=null)
 
 it_renders_added_and_removed_set_cookies_header ()
 
 it_gets_and_updates_set_cookie_value_on_request ()
 
 provideSetCookieStringsAndExpectedSetCookiesData ()
 
 provideGetsSetCookieByNameData ()
 

Data Fields

const INTERFACE_PSR_HTTP_MESSAGE_RESPONSE = 'Psr\Http\Message\ResponseInterface'
 

Detailed Description

Definition at line 5 of file SetCookiesTest.php.

Member Function Documentation

◆ it_creates_from_response()

Dflydev\FigCookies\SetCookiesTest::it_creates_from_response (   $setCookieStrings,
array  $expectedSetCookies 
)
Parameters
string[]$setCookieStrings
SetCookie[]$expectedSetCookies
Test:
@dataProvider provideSetCookieStringsAndExpectedSetCookiesData

Definition at line 16 of file SetCookiesTest.php.

17 {
18 $response = $this->prophesize(static::INTERFACE_PSR_HTTP_MESSAGE_RESPONSE);
19 $response->getHeader(SetCookies::SET_COOKIE_HEADER)->willReturn($setCookieStrings);
20
21 $setCookies = SetCookies::fromResponse($response->reveal());
22
23 $this->assertEquals($expectedSetCookies, $setCookies->getAll());
24 }
const SET_COOKIE_HEADER
The name of the Set-Cookie header.
Definition: SetCookies.php:12
static fromResponse(ResponseInterface $response)
Create SetCookies from a Response.
Definition: SetCookies.php:124
$response

References $response, Dflydev\FigCookies\SetCookies\fromResponse(), and Dflydev\FigCookies\SetCookies\SET_COOKIE_HEADER.

+ Here is the call graph for this function:

◆ it_creates_from_set_cookie_strings()

Dflydev\FigCookies\SetCookiesTest::it_creates_from_set_cookie_strings (   $setCookieStrings,
array  $expectedSetCookies 
)
Parameters
string[]$setCookieStrings
SetCookie[]$expectedSetCookies
Test:
@dataProvider provideSetCookieStringsAndExpectedSetCookiesData

Definition at line 33 of file SetCookiesTest.php.

34 {
35 $setCookies = SetCookies::fromSetCookieStrings($setCookieStrings);
36
37 $this->assertEquals($expectedSetCookies, $setCookies->getAll());
38 }
static fromSetCookieStrings($setCookieStrings)
Create SetCookies from a collection of SetCookie header value strings.
Definition: SetCookies.php:111

References Dflydev\FigCookies\SetCookies\fromSetCookieStrings().

+ Here is the call graph for this function:

◆ it_gets_and_updates_set_cookie_value_on_request()

Dflydev\FigCookies\SetCookiesTest::it_gets_and_updates_set_cookie_value_on_request ( )
Test:

Definition at line 94 of file SetCookiesTest.php.

95 {
96 //
97 // Example of naive cookie encryption middleware.
98 //
99 // Shows how to access and manipulate cookies using PSR-7 Response
100 // instances from outside the Response object itself.
101 //
102
103 // Simulate a response coming in with several cookies.
104 $response = (new FigCookieTestingResponse())
106 ->withAddedHeader(SetCookies::SET_COOKIE_HEADER, 'sessionToken=ENCRYPTED')
107 ->withAddedHeader(SetCookies::SET_COOKIE_HEADER, 'hello=world')
108 ;
109
110 // Get our set cookies from the response.
111 $setCookies = SetCookies::fromResponse($response);
112
113 // Ask for the encrypted session token.
114 $decryptedSessionToken = $setCookies->get('sessionToken');
115
116 // Get the encrypted value from the cookie and decrypt it.
117 $decryptedValue = $decryptedSessionToken->getValue();
118 $encryptedValue = str_rot13($decryptedValue);
119
120 // Create a new set cookie with the encrypted value.
121 $encryptedSessionToken = $decryptedSessionToken->withValue($encryptedValue);
122
123 // Include our encrypted session token with the rest of our cookies.
124 $setCookies = $setCookies->with($encryptedSessionToken);
125
126 // Render our cookies, along with the newly decrypted session token, into a response.
127 $response = $setCookies->renderIntoSetCookieHeader($response);
128
129 // From this point on, any response based on this one can get the encrypted version
130 // of the session token.
131 $this->assertEquals(
132 ['theme=light', 'sessionToken=RAPELCGRQ', 'hello=world'],
134 );
135 }

References $response, Dflydev\FigCookies\SetCookies\fromResponse(), Dflydev\FigCookies\SetCookies\SET_COOKIE_HEADER, and Dflydev\FigCookies\withAddedHeader().

+ Here is the call graph for this function:

◆ it_gets_set_cookie_by_name()

Dflydev\FigCookies\SetCookiesTest::it_gets_set_cookie_by_name (   $setCookieStrings,
  $setCookieName,
SetCookie  $expectedSetCookie = null 
)
Test:
@dataProvider provideGetsSetCookieByNameData

Definition at line 62 of file SetCookiesTest.php.

63 {
64 $setCookies = SetCookies::fromSetCookieStrings($setCookieStrings);
65
66 $this->assertEquals($expectedSetCookie, $setCookies->get($setCookieName));
67 }

References Dflydev\FigCookies\SetCookies\fromSetCookieStrings().

+ Here is the call graph for this function:

◆ it_knows_which_set_cookies_are_available()

Dflydev\FigCookies\SetCookiesTest::it_knows_which_set_cookies_are_available (   $setCookieStrings,
array  $expectedSetCookies 
)
Parameters
string[]$setCookieStrings
SetCookie[]$expectedSetCookies
Test:
@dataProvider provideSetCookieStringsAndExpectedSetCookiesData

Definition at line 47 of file SetCookiesTest.php.

48 {
49 $setCookies = SetCookies::fromSetCookieStrings($setCookieStrings);
50
51 foreach ($expectedSetCookies as $expectedSetCookie) {
52 $this->assertTrue($setCookies->has($expectedSetCookie->getName()));
53 }
54
55 $this->assertFalse($setCookies->has('i know this cookie does not exist'));
56 }

References Dflydev\FigCookies\SetCookies\fromSetCookieStrings().

+ Here is the call graph for this function:

◆ it_renders_added_and_removed_set_cookies_header()

Dflydev\FigCookies\SetCookiesTest::it_renders_added_and_removed_set_cookies_header ( )
Test:

Definition at line 72 of file SetCookiesTest.php.

73 {
74 $setCookies = SetCookies::fromSetCookieStrings(['theme=light', 'sessionToken=abc123', 'hello=world'])
75 ->with(SetCookie::create('theme', 'blue'))
76 ->without('sessionToken')
77 ->with(SetCookie::create('who', 'me'))
78 ;
79
80 $originalResponse = new FigCookieTestingResponse();
81 $response = $setCookies->renderIntoSetCookieHeader($originalResponse);
82
83 $this->assertNotEquals($response, $originalResponse);
84
85 $this->assertEquals(
86 ['theme=blue', 'hello=world', 'who=me'],
88 );
89 }
static create($name, $value=null)
Definition: SetCookie.php:173

References $response, Dflydev\FigCookies\SetCookie\create(), Dflydev\FigCookies\SetCookies\fromSetCookieStrings(), and Dflydev\FigCookies\SetCookies\SET_COOKIE_HEADER.

+ Here is the call graph for this function:

◆ provideGetsSetCookieByNameData()

Dflydev\FigCookies\SetCookiesTest::provideGetsSetCookieByNameData ( )

Definition at line 182 of file SetCookiesTest.php.

183 {
184 return [
185 [
186 [
187 'a=AAA',
188 'b=BBB',
189 'c=CCC',
190 ],
191 'b',
192 SetCookie::create('b', 'BBB'),
193 ],
194 [
195 [
196 'a=AAA',
197 'b=BBB',
198 'c=CCC',
199 'LSID=DQAAAK%2FEaem_vYg; Path=/accounts; Expires=Wed, 13 Jan 2021 22:23:01 GMT; Secure; HttpOnly',
200 ],
201 'LSID',
202 SetCookie::create('LSID')
203 ->withValue('DQAAAK/Eaem_vYg')
204 ->withPath('/accounts')
205 ->withExpires('Wed, 13 Jan 2021 22:23:01 GMT')
206 ->withSecure(true)
207 ->withHttpOnly(true),
208 ],
209 [
210 [
211 'a=AAA',
212 'b=BBB',
213 'c=CCC',
214 ],
215 'LSID',
216 null,
217 ],
218 ];
219 }

References Dflydev\FigCookies\SetCookie\create().

+ Here is the call graph for this function:

◆ provideSetCookieStringsAndExpectedSetCookiesData()

Dflydev\FigCookies\SetCookiesTest::provideSetCookieStringsAndExpectedSetCookiesData ( )

Definition at line 137 of file SetCookiesTest.php.

138 {
139 return [
140 [
141 [],
142 [],
143 ],
144 [
145 [
146 'someCookie=',
147 ],
148 [
149 SetCookie::create('someCookie'),
150 ],
151 ],
152 [
153 [
154 'someCookie=someValue',
155 'LSID=DQAAAK%2FEaem_vYg; Path=/accounts; Expires=Wed, 13 Jan 2021 22:23:01 GMT; Secure; HttpOnly',
156 ],
157 [
158 SetCookie::create('someCookie', 'someValue'),
159 SetCookie::create('LSID')
160 ->withValue('DQAAAK/Eaem_vYg')
161 ->withPath('/accounts')
162 ->withExpires('Wed, 13 Jan 2021 22:23:01 GMT')
163 ->withSecure(true)
164 ->withHttpOnly(true),
165 ],
166 ],
167 [
168 [
169 'a=AAA',
170 'b=BBB',
171 'c=CCC',
172 ],
173 [
174 SetCookie::create('a', 'AAA'),
175 SetCookie::create('b', 'BBB'),
176 SetCookie::create('c', 'CCC'),
177 ],
178 ],
179 ];
180 }

References Dflydev\FigCookies\SetCookie\create().

+ Here is the call graph for this function:

Field Documentation

◆ INTERFACE_PSR_HTTP_MESSAGE_RESPONSE

const Dflydev\FigCookies\SetCookiesTest::INTERFACE_PSR_HTTP_MESSAGE_RESPONSE = 'Psr\Http\Message\ResponseInterface'

Definition at line 7 of file SetCookiesTest.php.


The documentation for this class was generated from the following file: