ILIAS  release_8 Revision v8.24
CookieJarWrapperTest.php
Go to the documentation of this file.
1<?php
8namespace ILIAS\HTTP\Cookies;
9
10use PHPUnit\Framework\TestCase;
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 *****************************************************************************/
35class CookieJarWrapperTest extends TestCase
36{
40 private static $cookieFactory;
44 private static $cookieJarFactory;
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
59 {
60 $cookieName = "YummyCookie";
61 $cookieValue = "MilkAndChocolate";
62 $cookie = self::$cookieFactory->create($cookieName, $cookieValue);
63 $cookieJar = self::$cookieJarFactory->fromCookieStrings([]);
64
65 $newCookieJar = $cookieJar->with($cookie);
66
67 $this->assertFalse($cookieJar->has($cookieName));
68 $this->assertTrue($newCookieJar->has($cookieName));
69
70 $this->assertNotEquals($cookieJar, $newCookieJar);
71 }
72
73
78 {
79 $cookieName = "YummyCookie";
80 $cookieValue = "MilkAndChocolate";
81
82 //create a new jar with one cookie
83 $cookieJar = self::$cookieJarFactory->fromCookieStrings([ $cookieName . '=' . $cookieValue . ';' ]);
84
85 //remove cookie
86 $newCookieJar = $cookieJar->without($cookieName);
87
88 //old jar should hold the cookie
89 $this->assertTrue($cookieJar->has($cookieName));
90
91 //new jar should no longer hold the cookie
92 $this->assertFalse($newCookieJar->has($cookieName));
93
94 //check that both are not equal (checked because the has function could fail due to a change in the future)
95 $this->assertNotEquals($cookieJar, $newCookieJar);
96 }
97}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Cookie.php:19