forked from codeigniter4/CodeIgniter4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommonFunctionsSendTest.php
More file actions
52 lines (41 loc) · 1.17 KB
/
Copy pathCommonFunctionsSendTest.php
File metadata and controls
52 lines (41 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
class CommonFunctionsSendTest extends \CIUnitTestCase
{
protected function setUp()
{
parent::setUp();
unset($_ENV['foo'], $_SERVER['foo']);
}
//--------------------------------------------------------------------
/**
* Make sure cookies are set by RedirectResponse this way
* See https://github.com/codeigniter4/CodeIgniter4/issues/1393
*
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function testRedirectResponseCookiesSent()
{
$login_time = time();
$routes = service('routes');
$routes->add('user/login', 'Auth::verify', ['as' => 'login']);
$response = redirect()->route('login')
->setCookie('foo', 'onething', YEAR)
->setCookie('login_time', $login_time, YEAR);
$response->pretend(false);
$this->assertTrue($response->hasCookie('foo', 'onething'));
$this->assertTrue($response->hasCookie('login_time'));
$response->setBody('Hello');
// send it
ob_start();
$response->send();
$buffer = ob_clean();
if (ob_get_level() > 0)
{
ob_end_clean();
}
// and what actually got sent?
$this->assertHeaderEmitted('Set-Cookie: foo=onething;');
$this->assertHeaderEmitted('Set-Cookie: login_time');
}
}