Skip to content

Commit 3329576

Browse files
authored
test: add tests showing Session::markAs(Flash|Temp)data() invalidates all keys when not all in session (#9537)
1 parent 8c6da93 commit 3329576

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

tests/system/Session/SessionTest.php

+28
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,20 @@ public function testCanFlashData(): void
344344
$this->assertFalse($session->has('foo'));
345345
}
346346

347+
/**
348+
* @see https://github.com/codeigniter4/CodeIgniter4/pull/9535#discussion_r2052022296
349+
*/
350+
public function testMarkAsFlashdataFailsWhenAtLeastOneKeyIsNotInSession(): void
351+
{
352+
$session = $this->getInstance();
353+
$session->start();
354+
355+
$session->set(['foo1' => 'bar1', 'foo2' => 'bar2']);
356+
357+
$this->assertFalse($session->markAsFlashdata(['foo1', 'foo2', 'foo3']));
358+
$this->assertArrayNotHasKey('__ci_vars', $_SESSION);
359+
}
360+
347361
public function testCanFlashArray(): void
348362
{
349363
$session = $this->getInstance();
@@ -462,6 +476,20 @@ public function testSetTempDataArraySingleTTL(): void
462476
$this->assertLessThanOrEqual($_SESSION['__ci_vars']['baz'], $time + 200);
463477
}
464478

479+
/**
480+
* @see https://github.com/codeigniter4/CodeIgniter4/pull/9536#discussion_r2051798869
481+
*/
482+
public function testMarkAsTempdataFailsWhenAtLeastOneKeyIsNotInSession(): void
483+
{
484+
$session = $this->getInstance();
485+
$session->start();
486+
487+
$session->set(['foo1' => 'bar1', 'foo2' => 'bar2']);
488+
489+
$this->assertFalse($session->markAsTempdata(['foo1', 'foo2', 'foo3'], 200));
490+
$this->assertArrayNotHasKey('__ci_vars', $_SESSION);
491+
}
492+
465493
public function testGetTestDataReturnsAll(): void
466494
{
467495
$session = $this->getInstance();

0 commit comments

Comments
 (0)