ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
CookieJarWrapperTest.php
Go to the documentation of this file.
1<?php
2
25namespace ILIAS\HTTP\Cookies;
26
27use PHPUnit\Framework\Attributes\BackupGlobals;
28use PHPUnit\Framework\Attributes\BackupStaticProperties;
29use PHPUnit\Framework\Attributes\PreserveGlobalState;
30use PHPUnit\Framework\Attributes\RunInSeparateProcess;
31use PHPUnit\Framework\Attributes\Test;
32use PHPUnit\Framework\TestCase;
33
39#[BackupGlobals(false)]
40#[BackupStaticProperties(false)]
41#[PreserveGlobalState(false)]
42class CookieJarWrapperTest extends TestCase
43{
46
47
48 public static function setUpBeforeClass(): void
49 {
50 parent::setUpBeforeClass(); // TODO: Change the autogenerated stub
51 self::$cookieFactory = new CookieFactoryImpl();
52 self::$cookieJarFactory = new CookieJarFactoryImpl();
53 }
54
55
56 #[Test]
58 {
59 $cookieName = "YummyCookie";
60 $cookieValue = "MilkAndChocolate";
61 $cookie = self::$cookieFactory->create($cookieName, $cookieValue);
62 $cookieJar = self::$cookieJarFactory->fromCookieStrings([]);
63
64 $newCookieJar = $cookieJar->with($cookie);
65
66 $this->assertFalse($cookieJar->has($cookieName));
67 $this->assertTrue($newCookieJar->has($cookieName));
68
69 $this->assertNotEquals($cookieJar, $newCookieJar);
70 }
71
72
73 #[Test]
75 {
76 $cookieName = "YummyCookie";
77 $cookieValue = "MilkAndChocolate";
78
79 //create a new jar with one cookie
80 $cookieJar = self::$cookieJarFactory->fromCookieStrings([ $cookieName . '=' . $cookieValue . ';' ]);
81
82 //remove cookie
83 $newCookieJar = $cookieJar->without($cookieName);
84
85 //old jar should hold the cookie
86 $this->assertTrue($cookieJar->has($cookieName));
87
88 //new jar should no longer hold the cookie
89 $this->assertFalse($newCookieJar->has($cookieName));
90
91 //check that both are not equal (checked because the has function could fail due to a change in the future)
92 $this->assertNotEquals($cookieJar, $newCookieJar);
93 }
94}
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