/
FlashMessageListenerTest.php
73 lines (59 loc) · 2.46 KB
/
FlashMessageListenerTest.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
64
65
66
67
68
69
70
71
72
73
<?php
/*
* This file is part of the FOSHttpCacheBundle package.
*
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace FOS\HttpCacheBundle\Tests\Functional\EventListener;
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class FlashMessageListenerTest extends WebTestCase
{
use MockeryPHPUnitIntegration;
public function testFlashMessageCookieIsSet()
{
$client = static::createClient();
$client->request('GET', '/flash');
$response = $client->getResponse();
$this->assertEquals('flash', $response->getContent());
$cookies = $response->headers->getCookies();
$this->assertGreaterThanOrEqual(1, $cookies, implode(',', $cookies));
$found = false;
foreach ($cookies as $cookie) {
if ('flash_cookie_name' !== $cookie->getName()) {
continue;
}
$this->assertEquals('/', $cookie->getPath());
$this->assertNull($cookie->getDomain());
$this->assertTrue($cookie->isSecure());
$this->assertJsonStringEqualsJsonString(json_encode(['notice' => ['Flash Message!']]), $cookie->getValue());
$found = true;
}
$this->assertTrue($found, 'Cookie "flash_cookie_name" not found in response cookies');
}
public function testFlashMessageCookieIsSetOnRedirect()
{
$client = static::createClient();
$client->followRedirects(true);
$client->setMaxRedirects(2);
$client->request('GET', '/flash-redirect');
$response = $client->getResponse();
$cookies = $response->headers->getCookies();
$this->assertGreaterThanOrEqual(1, $cookies, implode(',', $cookies));
$found = false;
foreach ($cookies as $cookie) {
if ('flash_cookie_name' !== $cookie->getName()) {
continue;
}
$this->assertEquals('/', $cookie->getPath());
$this->assertNull($cookie->getDomain());
$this->assertTrue($cookie->isSecure());
$this->assertJsonStringEqualsJsonString(json_encode(['notice' => ['Flash Message!', 'Flash Message!']]), $cookie->getValue());
$found = true;
}
$this->assertTrue($found, 'Cookie "flash_cookie_name" not found in response cookies');
}
}