ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
CookieJarWrapperTest.php
Go to the documentation of this file.
1 <?php
8 namespace ILIAS\HTTP\Cookies;
9 
11 
12 require_once('./libs/composer/vendor/autoload.php');
13 
25 {
26 
30  private static $cookieFactory;
34  private static $cookieJarFactory;
35 
36 
37  public static function setUpBeforeClass() : void
38  {
39  parent::setUpBeforeClass(); // TODO: Change the autogenerated stub
40  self::$cookieFactory = new CookieFactoryImpl();
41  self::$cookieJarFactory = new CookieJarFactoryImpl();
42  }
43 
44 
49  {
50  $cookieName = "YummyCookie";
51  $cookieValue = "MilkAndChocolate";
52  $cookie = self::$cookieFactory->create($cookieName, $cookieValue);
53  $cookieJar = self::$cookieJarFactory->fromCookieStrings([]);
54 
55  $newCookieJar = $cookieJar->with($cookie);
56 
57  $this->assertFalse($cookieJar->has($cookieName));
58  $this->assertTrue($newCookieJar->has($cookieName));
59 
60  $this->assertNotEquals($cookieJar, $newCookieJar);
61  }
62 
63 
68  {
69  $cookieName = "YummyCookie";
70  $cookieValue = "MilkAndChocolate";
71 
72  //create a new jar with one cookie
73  $cookieJar = self::$cookieJarFactory->fromCookieStrings([ $cookieName . '=' . $cookieValue . ';' ]);
74 
75  //remove cookie
76  $newCookieJar = $cookieJar->without($cookieName);
77 
78  //old jar should hold the cookie
79  $this->assertTrue($cookieJar->has($cookieName));
80 
81  //new jar should no longer hold the cookie
82  $this->assertFalse($newCookieJar->has($cookieName));
83 
84  //check that both are not equal (checked because the has function could fail due to a change in the future)
85  $this->assertNotEquals($cookieJar, $newCookieJar);
86  }
87 }
Class CookieJarWrapperTest.
Definition: Cookie.php:3