ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
CookieWrapperTest.php
Go to the documentation of this file.
1<?php
8namespace ILIAS\HTTP\Cookies;
9
10use PHPUnit\Framework\TestCase;
11
12require_once('./libs/composer/vendor/autoload.php');
13
24class CookieWrapperTest extends TestCase
25{
26
30 private $cookie;
34 private static $cookieFactory;
35
36
37 public static function setUpBeforeClass() : void
38 {
39 parent::setUpBeforeClass();
40 self::$cookieFactory = new CookieFactoryImpl();
41 }
42
43
44 protected function setUp() : void
45 {
46 parent::setUp();
47
48 //setup the cookie we want to use for our tests.
49 $cookieName = "ilias";
50 $cookieValue = "theNewCookiesAreYummy";
51 $this->cookie = self::$cookieFactory->create($cookieName, $cookieValue);
52 }
53
54
59 {
60 $newValue = "yes!";
61 $newCookie = $this->cookie->withValue("yes!");
62 $this->assertEquals($newValue, $newCookie->getValue());
63 $this->assertNotEquals($this->cookie->getValue(), $newCookie->getValue());
64 }
65
66
71 {
72 $expires = 1000;
73 $newCookie = $this->cookie->withExpires($expires);
74
75 $this->assertEquals($expires, $newCookie->getExpires());
76 $this->assertNotEquals($this->cookie->getExpires(), $newCookie->getExpires());
77 }
78
79
84 {
85 $newCookie = $this->cookie->rememberForLongTime();
86
87 //remember forever changes the date of expiry so they should differ by quite a bit.
88 $this->assertNotEquals($this->cookie->getExpires(), $newCookie->getExpires());
89 }
90
91
96 {
97 $newCookie = $this->cookie->expire();
98
99 //expire changes the date of expiry so they should differ by quite a bit.
100 $this->assertNotEquals($this->cookie->getExpires(), $newCookie->getExpires());
101 }
102
103
108 {
109 $maxAge = 1000;
110 $newCookie = $this->cookie->withMaxAge($maxAge);
111
112 $this->assertEquals($maxAge, $newCookie->getMaxAge());
113 $this->assertNotEquals($this->cookie->getMaxAge(), $newCookie->getMaxAge());
114 }
115
116
121 {
122 $path = '/ilias';
123 $newCookie = $this->cookie->withPath($path);
124
125 $this->assertEquals($path, $newCookie->getPath());
126 $this->assertNotEquals($this->cookie->getPath(), $newCookie->getPath());
127 }
128
129
134 {
135 $domain = 'ilias.de';
136 $newCookie = $this->cookie->withDomain($domain);
137
138 $this->assertEquals($domain, $newCookie->getDomain());
139 $this->assertNotEquals($this->cookie->getDomain(), $newCookie->getDomain());
140 }
141
142
147 {
148 $secure = true;
149 $newCookie = $this->cookie->withSecure($secure);
150
151 $this->assertTrue($newCookie->getSecure());
152 $this->assertNotEquals($this->cookie->getSecure(), $newCookie->getSecure());
153 }
154
155
160 {
161 $httpOnly = true;
162 $newCookie = $this->cookie->withHttpOnly($httpOnly);
163
164 $this->assertTrue($newCookie->getHttpOnly());
165 $this->assertNotEquals($this->cookie->getHttpOnly(), $newCookie->getHttpOnly());
166 }
167}
An exception for terminatinating execution or to throw for unit testing.
Class CookieJarWrapperTest.
Definition: Cookie.php:3