ILIAS  release_8 Revision v8.23
CookieWrapperTest.php
Go to the documentation of this file.
1 <?php
8 namespace ILIAS\HTTP\Cookies;
9 
11 
12 /******************************************************************************
13  *
14  * This file is part of ILIAS, a powerful learning management system.
15  *
16  * ILIAS is licensed with the GPL-3.0, you should have received a copy
17  * of said license along with the source code.
18  *
19  * If this is not the case or you just want to try ILIAS, you'll find
20  * us at:
21  * https://www.ilias.de
22  * https://github.com/ILIAS-eLearning
23  *
24  *****************************************************************************/
35 class CookieWrapperTest extends TestCase
36 {
40  private $cookie;
44  private static $cookieFactory;
45 
46 
47  public static function setUpBeforeClass(): void
48  {
49  parent::setUpBeforeClass();
50  self::$cookieFactory = new CookieFactoryImpl();
51  }
52 
53 
54  protected function setUp(): void
55  {
56  parent::setUp();
57 
58  //setup the cookie we want to use for our tests.
59  $cookieName = "ilias";
60  $cookieValue = "theNewCookiesAreYummy";
61  $this->cookie = self::$cookieFactory->create($cookieName, $cookieValue);
62  }
63 
64 
69  {
70  $newValue = "yes!";
71  $newCookie = $this->cookie->withValue("yes!");
72  $this->assertEquals($newValue, $newCookie->getValue());
73  $this->assertNotEquals($this->cookie->getValue(), $newCookie->getValue());
74  }
75 
76 
81  {
82  $expires = 1000;
83  $newCookie = $this->cookie->withExpires($expires);
84 
85  $this->assertEquals($expires, $newCookie->getExpires());
86  $this->assertNotEquals($this->cookie->getExpires(), $newCookie->getExpires());
87  }
88 
89 
94  {
95  $newCookie = $this->cookie->rememberForLongTime();
96 
97  //remember forever 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  $newCookie = $this->cookie->expire();
108 
109  //expire changes the date of expiry so they should differ by quite a bit.
110  $this->assertNotEquals($this->cookie->getExpires(), $newCookie->getExpires());
111  }
112 
113 
118  {
119  $maxAge = 1000;
120  $newCookie = $this->cookie->withMaxAge($maxAge);
121 
122  $this->assertEquals($maxAge, $newCookie->getMaxAge());
123  $this->assertNotEquals($this->cookie->getMaxAge(), $newCookie->getMaxAge());
124  }
125 
126 
131  {
132  $path = '/ilias';
133  $newCookie = $this->cookie->withPath($path);
134 
135  $this->assertEquals($path, $newCookie->getPath());
136  $this->assertNotEquals($this->cookie->getPath(), $newCookie->getPath());
137  }
138 
139 
144  {
145  $domain = 'ilias.de';
146  $newCookie = $this->cookie->withDomain($domain);
147 
148  $this->assertEquals($domain, $newCookie->getDomain());
149  $this->assertNotEquals($this->cookie->getDomain(), $newCookie->getDomain());
150  }
151 
152 
157  {
158  $secure = true;
159  $newCookie = $this->cookie->withSecure($secure);
160 
161  $this->assertTrue($newCookie->getSecure());
162  $this->assertNotEquals($this->cookie->getSecure(), $newCookie->getSecure());
163  }
164 
165 
170  {
171  $httpOnly = true;
172  $newCookie = $this->cookie->withHttpOnly($httpOnly);
173 
174  $this->assertTrue($newCookie->getHttpOnly());
175  $this->assertNotEquals($this->cookie->getHttpOnly(), $newCookie->getHttpOnly());
176  }
177 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Cookie.php:19
$path
Definition: ltiservices.php:32