ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
CookieWrapperTest.php
Go to the documentation of this file.
1<?php
8namespace ILIAS\HTTP\Cookies;
9
10require_once('./libs/composer/vendor/autoload.php');
11
23{
24
28 private $cookie;
32 private static $cookieFactory;
33
34
35 public static function setUpBeforeClass()
36 {
37 parent::setUpBeforeClass();
38 self::$cookieFactory = new CookieFactoryImpl();
39 }
40
41
42 protected function setUp()
43 {
44 parent::setUp();
45
46 //setup the cookie we want to use for our tests.
47 $cookieName = "ilias";
48 $cookieValue = "theNewCookiesAreYummy";
49 $this->cookie = self::$cookieFactory->create($cookieName, $cookieValue);
50 }
51
52
57 {
58 $newValue = "yes!";
59 $newCookie = $this->cookie->withValue("yes!");
60 $this->assertEquals($newValue, $newCookie->getValue());
61 $this->assertNotEquals($this->cookie->getValue(), $newCookie->getValue());
62 }
63
64
69 {
70 $expires = 1000;
71 $newCookie = $this->cookie->withExpires($expires);
72
73 $this->assertEquals($expires, $newCookie->getExpires());
74 $this->assertNotEquals($this->cookie->getExpires(), $newCookie->getExpires());
75 }
76
77
82 {
83 $newCookie = $this->cookie->rememberForLongTime();
84
85 //remember forever changes the date of expiry so they should differ by quite a bit.
86 $this->assertNotEquals($this->cookie->getExpires(), $newCookie->getExpires());
87 }
88
89
94 {
95 $newCookie = $this->cookie->expire();
96
97 //expire changes the date of expiry so they should differ by quite a bit.
98 $this->assertNotEquals($this->cookie->getExpires(), $newCookie->getExpires());
99 }
100
101
106 {
107 $maxAge = 1000;
108 $newCookie = $this->cookie->withMaxAge($maxAge);
109
110 $this->assertEquals($maxAge, $newCookie->getMaxAge());
111 $this->assertNotEquals($this->cookie->getMaxAge(), $newCookie->getMaxAge());
112 }
113
114
119 {
120 $path = '/ilias';
121 $newCookie = $this->cookie->withPath($path);
122
123 $this->assertEquals($path, $newCookie->getPath());
124 $this->assertNotEquals($this->cookie->getPath(), $newCookie->getPath());
125 }
126
127
132 {
133 $domain = 'ilias.de';
134 $newCookie = $this->cookie->withDomain($domain);
135
136 $this->assertEquals($domain, $newCookie->getDomain());
137 $this->assertNotEquals($this->cookie->getDomain(), $newCookie->getDomain());
138 }
139
140
145 {
146 $secure = true;
147 $newCookie = $this->cookie->withSecure($secure);
148
149 $this->assertTrue($newCookie->getSecure());
150 $this->assertNotEquals($this->cookie->getSecure(), $newCookie->getSecure());
151 }
152
153
158 {
159 $httpOnly = true;
160 $newCookie = $this->cookie->withHttpOnly($httpOnly);
161
162 $this->assertTrue($newCookie->getHttpOnly());
163 $this->assertNotEquals($this->cookie->getHttpOnly(), $newCookie->getHttpOnly());
164 }
165}
$path
Definition: aliased.php:25
if(!array_key_exists('domain', $_REQUEST)) $domain
Definition: resume.php:8
An exception for terminatinating execution or to throw for unit testing.
Class CookieJarWrapperTest.
Definition: Cookie.php:3
$cookieName