ILIAS  trunk Revision v11.0_alpha-2662-g519ff7d528f
CookieWrapperTest.php
Go to the documentation of this file.
1 <?php
2 
25 namespace ILIAS\HTTP\Cookies;
26 
33 
39 #[BackupGlobals(false)]
40 #[BackupStaticProperties(false)]
41 #[PreserveGlobalState(false)]
42 class CookieWrapperTest extends TestCase
43 {
47  private Cookie $cookie;
49 
50 
51  public static function setUpBeforeClass(): void
52  {
53  parent::setUpBeforeClass();
54  self::$cookieFactory = new CookieFactoryImpl();
55  }
56 
57 
58  protected function setUp(): void
59  {
60  parent::setUp();
61 
62  //setup the cookie we want to use for our tests.
63  $cookieName = "ilias";
64  $cookieValue = "theNewCookiesAreYummy";
65  $this->cookie = self::$cookieFactory->create($cookieName, $cookieValue);
66  }
67 
68 
69  #[Test]
71  {
72  $newValue = "yes!";
73  $newCookie = $this->cookie->withValue("yes!");
74  $this->assertSame($newValue, $newCookie->getValue());
75  $this->assertNotEquals($this->cookie->getValue(), $newCookie->getValue());
76  }
77 
78 
79  #[Test]
81  {
82  $expires = 1000;
83  $newCookie = $this->cookie->withExpires($expires);
84 
85  $this->assertSame($expires, $newCookie->getExpires());
86  $this->assertNotSame($this->cookie->getExpires(), $newCookie->getExpires());
87  }
88 
89 
90  #[Test]
92  {
93  $newCookie = $this->cookie->rememberForLongTime();
94 
95  //remember forever changes the date of expiry so they should differ by quite a bit.
96  $this->assertNotSame($this->cookie->getExpires(), $newCookie->getExpires());
97  }
98 
99 
100  #[Test]
102  {
103  $newCookie = $this->cookie->expire();
104 
105  //expire changes the date of expiry so they should differ by quite a bit.
106  $this->assertNotSame($this->cookie->getExpires(), $newCookie->getExpires());
107  }
108 
109 
110  #[Test]
112  {
113  $maxAge = 1000;
114  $newCookie = $this->cookie->withMaxAge($maxAge);
115 
116  $this->assertSame($maxAge, $newCookie->getMaxAge());
117  $this->assertNotSame($this->cookie->getMaxAge(), $newCookie->getMaxAge());
118  }
119 
120 
121  #[Test]
123  {
124  $path = '/ilias';
125  $newCookie = $this->cookie->withPath($path);
126 
127  $this->assertSame($path, $newCookie->getPath());
128  $this->assertNotEquals($this->cookie->getPath(), $newCookie->getPath());
129  }
130 
131 
132  #[Test]
134  {
135  $domain = 'ilias.de';
136  $newCookie = $this->cookie->withDomain($domain);
137 
138  $this->assertSame($domain, $newCookie->getDomain());
139  $this->assertNotEquals($this->cookie->getDomain(), $newCookie->getDomain());
140  }
141 
142 
143  #[Test]
145  {
146  $secure = true;
147  $newCookie = $this->cookie->withSecure($secure);
148 
149  $this->assertTrue($newCookie->getSecure());
150  $this->assertNotSame($this->cookie->getSecure(), $newCookie->getSecure());
151  }
152 
153 
154  #[Test]
156  {
157  $httpOnly = true;
158  $newCookie = $this->cookie->withHttpOnly($httpOnly);
159 
160  $this->assertTrue($newCookie->getHttpOnly());
161  $this->assertNotSame($this->cookie->getHttpOnly(), $newCookie->getHttpOnly());
162  }
163 }
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:29
static CookieFactoryImpl $cookieFactory