From 5ff0e57759d260774877b9a4ab9446be7979bd52 Mon Sep 17 00:00:00 2001 From: "John Paul E. Balandan, CPA" Date: Mon, 21 Apr 2025 21:42:27 +0800 Subject: [PATCH] test: add tests showing `Session::markAs(Flash|Temp)data()` invalidates all keys when not all in session --- tests/system/Session/SessionTest.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/system/Session/SessionTest.php b/tests/system/Session/SessionTest.php index 518a2d733a69..7a8de643cc35 100644 --- a/tests/system/Session/SessionTest.php +++ b/tests/system/Session/SessionTest.php @@ -344,6 +344,20 @@ public function testCanFlashData(): void $this->assertFalse($session->has('foo')); } + /** + * @see https://github.com/codeigniter4/CodeIgniter4/pull/9535#discussion_r2052022296 + */ + public function testMarkAsFlashdataFailsWhenAtLeastOneKeyIsNotInSession(): void + { + $session = $this->getInstance(); + $session->start(); + + $session->set(['foo1' => 'bar1', 'foo2' => 'bar2']); + + $this->assertFalse($session->markAsFlashdata(['foo1', 'foo2', 'foo3'])); + $this->assertArrayNotHasKey('__ci_vars', $_SESSION); + } + public function testCanFlashArray(): void { $session = $this->getInstance(); @@ -462,6 +476,20 @@ public function testSetTempDataArraySingleTTL(): void $this->assertLessThanOrEqual($_SESSION['__ci_vars']['baz'], $time + 200); } + /** + * @see https://github.com/codeigniter4/CodeIgniter4/pull/9536#discussion_r2051798869 + */ + public function testMarkAsTempdataFailsWhenAtLeastOneKeyIsNotInSession(): void + { + $session = $this->getInstance(); + $session->start(); + + $session->set(['foo1' => 'bar1', 'foo2' => 'bar2']); + + $this->assertFalse($session->markAsTempdata(['foo1', 'foo2', 'foo3'], 200)); + $this->assertArrayNotHasKey('__ci_vars', $_SESSION); + } + public function testGetTestDataReturnsAll(): void { $session = $this->getInstance();