forked from laravel/framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCookieTest.php
More file actions
executable file
·82 lines (73 loc) · 2.96 KB
/
CookieTest.php
File metadata and controls
executable file
·82 lines (73 loc) · 2.96 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
use Mockery as m;
use Illuminate\Cookie\CookieJar;
use Symfony\Component\HttpFoundation\Request;
class CookieTest extends PHPUnit_Framework_TestCase
{
public function tearDown()
{
m::close();
}
public function testCookiesAreCreatedWithProperOptions()
{
$cookie = $this->getCreator();
$cookie->setDefaultPathAndDomain('foo', 'bar');
$c = $cookie->make('color', 'blue', 10, '/path', '/domain', true, false);
$this->assertEquals('blue', $c->getValue());
$this->assertFalse($c->isHttpOnly());
$this->assertTrue($c->isSecure());
$this->assertEquals('/domain', $c->getDomain());
$this->assertEquals('/path', $c->getPath());
$c2 = $cookie->forever('color', 'blue', '/path', '/domain', true, false);
$this->assertEquals('blue', $c2->getValue());
$this->assertFalse($c2->isHttpOnly());
$this->assertTrue($c2->isSecure());
$this->assertEquals('/domain', $c2->getDomain());
$this->assertEquals('/path', $c2->getPath());
$c3 = $cookie->forget('color');
$this->assertNull($c3->getValue());
$this->assertTrue($c3->getExpiresTime() < time());
}
public function testCookiesAreCreatedWithProperOptionsUsingDefaultPathAndDomain()
{
$cookie = $this->getCreator();
$cookie->setDefaultPathAndDomain('/path', '/domain');
$c = $cookie->make('color', 'blue', 10, null, null, true, false);
$this->assertEquals('blue', $c->getValue());
$this->assertFalse($c->isHttpOnly());
$this->assertTrue($c->isSecure());
$this->assertEquals('/domain', $c->getDomain());
$this->assertEquals('/path', $c->getPath());
}
public function testQueuedCookies()
{
$cookie = $this->getCreator();
$this->assertEmpty($cookie->getQueuedCookies());
$this->assertFalse($cookie->hasQueued('foo'));
$cookie->queue($cookie->make('foo', 'bar'));
$this->assertArrayHasKey('foo', $cookie->getQueuedCookies());
$this->assertTrue($cookie->hasQueued('foo'));
$this->assertInstanceOf('Symfony\Component\HttpFoundation\Cookie', $cookie->queued('foo'));
$cookie->queue('qu', 'ux');
$this->assertArrayHasKey('qu', $cookie->getQueuedCookies());
$this->assertTrue($cookie->hasQueued('qu'));
$this->assertInstanceOf('Symfony\Component\HttpFoundation\Cookie', $cookie->queued('qu'));
}
public function testUnqueue()
{
$cookie = $this->getCreator();
$cookie->queue($cookie->make('foo', 'bar'));
$this->assertArrayHasKey('foo', $cookie->getQueuedCookies());
$cookie->unqueue('foo');
$this->assertEmpty($cookie->getQueuedCookies());
}
public function getCreator()
{
return new CookieJar(Request::create('/foo', 'GET'), [
'path' => '/path',
'domain' => '/domain',
'secure' => true,
'httpOnly' => false,
]);
}
}