1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tests\Enjoys\Cookie; |
4
|
|
|
|
5
|
|
|
use Enjoys\Cookie\Options; |
6
|
|
|
use PHPUnit\Framework\TestCase; |
7
|
|
|
|
8
|
|
|
class OptionsTest extends TestCase |
9
|
|
|
{ |
10
|
|
|
|
11
|
|
|
public function testSetHttponly() |
12
|
|
|
{ |
13
|
|
|
$options = new Options(); |
14
|
|
|
$this->assertSame(false, $options->getOptions()['httponly']); |
15
|
|
|
$options->setHttponly(true); |
16
|
|
|
$this->assertSame(true, $options->getOptions()['httponly']); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
public function testSetDomain() |
20
|
|
|
{ |
21
|
|
|
$options = new Options(); |
22
|
|
|
$options->setDomain(false); |
23
|
|
|
$this->assertSame(false, $options->getOptions()['domain']); |
24
|
|
|
$options->setDomain('domain.com'); |
25
|
|
|
$this->assertSame('domain.com', $options->getOptions()['domain']); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function testSetSameSite() |
29
|
|
|
{ |
30
|
|
|
$options = new Options(); |
31
|
|
|
$this->assertArrayNotHasKey('samesite', $options->getOptions()); |
32
|
|
|
$options->setSameSite('Lax'); |
33
|
|
|
$this->assertSame('Lax', $options->getOptions()['samesite']); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function testSetPath() |
37
|
|
|
{ |
38
|
|
|
$options = new Options(); |
39
|
|
|
$this->assertSame('', $options->getOptions()['path']); |
40
|
|
|
$options->setPath('/'); |
41
|
|
|
$this->assertSame('/', $options->getOptions()['path']); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function testSetSecure() |
45
|
|
|
{ |
46
|
|
|
$options = new Options(); |
47
|
|
|
$this->assertSame(false, $options->getOptions()['secure']); |
48
|
|
|
$options->setSecure(true); |
49
|
|
|
$this->assertSame(true, $options->getOptions()['secure']); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function testSetExpires() |
53
|
|
|
{ |
54
|
|
|
$options = new Options(); |
55
|
|
|
$this->assertSame(-1, $options->getOptions()['expires']); |
56
|
|
|
$options->setExpires(100500); |
57
|
|
|
$this->assertSame(100500, $options->getOptions()['expires']); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function testGetOptionsWithAddedCustomOptions() |
61
|
|
|
{ |
62
|
|
|
$options = new Options(); |
63
|
|
|
$options->setSecure(true); |
64
|
|
|
$this->assertSame(false, $options->getOptions(['secure' => false])['secure']); |
65
|
|
|
|
66
|
|
|
$options->setPath('/'); |
67
|
|
|
$this->assertSame('/path', $options->getOptions(['path' => '/path'])['path']); |
68
|
|
|
|
69
|
|
|
$options->setHttponly(true); |
70
|
|
|
$this->assertSame(false, $options->getOptions(['httponly' => false])['httponly']); |
71
|
|
|
|
72
|
|
|
$options->setSameSite('Strict'); |
73
|
|
|
$this->assertSame('Lax', $options->getOptions(['samesite' => 'Lax'])['samesite']); |
74
|
|
|
|
75
|
|
|
$options->setDomain(false); |
76
|
|
|
$this->assertSame('example.com', $options->getOptions(['domain' => 'example.com'])['domain']); |
77
|
|
|
|
78
|
|
|
$options->setExpires(100500); |
79
|
|
|
$this->assertSame(100500, $options->getOptions(['expires' => 0])['expires']); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
} |
83
|
|
|
|