forked from codeigniter4/CodeIgniter4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCommonFunctionsSendTest.php
63 lines (53 loc) · 1.61 KB
/
CommonFunctionsSendTest.php
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
53
54
55
56
57
58
59
60
61
62
63
<?php
/**
* This file is part of CodeIgniter 4 framework.
*
* (c) CodeIgniter Foundation <[email protected]>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace CodeIgniter;
use CodeIgniter\Test\CIUnitTestCase;
/**
* @internal
*
* @group SeparateProcess
*/
final class CommonFunctionsSendTest extends CIUnitTestCase
{
protected function setUp(): void
{
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(): void
{
$loginTime = time();
$routes = service('routes');
$routes->add('user/login', 'Auth::verify', ['as' => 'login']);
$response = redirect()->route('login')
->setCookie('foo', 'onething', YEAR)
->setCookie('login_time', (string) $loginTime, 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();
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');
}
}