ILIAS  trunk Revision v11.0_alpha-1715-g7fc467680fb
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
CookieJarWrapperTest.php
Go to the documentation of this file.
1 <?php
24 namespace ILIAS\HTTP\Cookies;
25 
32 
38 #[BackupGlobals(false)]
39 #[BackupStaticProperties(false)]
40 #[PreserveGlobalState(false)]
41 class CookieJarWrapperTest extends TestCase
42 {
45 
46 
47  public static function setUpBeforeClass(): void
48  {
49  parent::setUpBeforeClass(); // TODO: Change the autogenerated stub
50  self::$cookieFactory = new CookieFactoryImpl();
51  self::$cookieJarFactory = new CookieJarFactoryImpl();
52  }
53 
54 
55  #[Test]
56  public function testWithDoesNotChangeTheCurrentObject(): void
57  {
58  $cookieName = "YummyCookie";
59  $cookieValue = "MilkAndChocolate";
60  $cookie = self::$cookieFactory->create($cookieName, $cookieValue);
61  $cookieJar = self::$cookieJarFactory->fromCookieStrings([]);
62 
63  $newCookieJar = $cookieJar->with($cookie);
64 
65  $this->assertFalse($cookieJar->has($cookieName));
66  $this->assertTrue($newCookieJar->has($cookieName));
67 
68  $this->assertNotEquals($cookieJar, $newCookieJar);
69  }
70 
71 
72  #[Test]
74  {
75  $cookieName = "YummyCookie";
76  $cookieValue = "MilkAndChocolate";
77 
78  //create a new jar with one cookie
79  $cookieJar = self::$cookieJarFactory->fromCookieStrings([ $cookieName . '=' . $cookieValue . ';' ]);
80 
81  //remove cookie
82  $newCookieJar = $cookieJar->without($cookieName);
83 
84  //old jar should hold the cookie
85  $this->assertTrue($cookieJar->has($cookieName));
86 
87  //new jar should no longer hold the cookie
88  $this->assertFalse($newCookieJar->has($cookieName));
89 
90  //check that both are not equal (checked because the has function could fail due to a change in the future)
91  $this->assertNotEquals($cookieJar, $newCookieJar);
92  }
93 }
static CookieJarFactoryImpl $cookieJarFactory
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Cookie.php:19