X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=tests%2Fsecurity%2FSessionManagerTest.php;h=d9db775efc59fd2a4b9b8e4accbba69788f6534e;hb=af290059d10319e76d1e7d78b592cab99c26d91a;hp=9bd868f809687273bf680f8a551ac41d876d8684;hpb=17e45b2e9c33c736751e059276fadb480f98e621;p=github%2Fshaarli%2FShaarli.git diff --git a/tests/security/SessionManagerTest.php b/tests/security/SessionManagerTest.php index 9bd868f8..d9db775e 100644 --- a/tests/security/SessionManagerTest.php +++ b/tests/security/SessionManagerTest.php @@ -5,9 +5,8 @@ require_once 'tests/utils/FakeConfigManager.php'; require_once 'tests/utils/ReferenceSessionIdHashes.php'; ReferenceSessionIdHashes::genAllHashes(); -use \Shaarli\Security\SessionManager; -use \PHPUnit\Framework\TestCase; - +use PHPUnit\Framework\TestCase; +use Shaarli\Security\SessionManager; /** * Test coverage for SessionManager @@ -270,4 +269,61 @@ class SessionManagerTest extends TestCase $this->session['ip'] = 'ip_id_one'; $this->assertTrue($this->sessionManager->hasClientIpChanged('ip_id_two')); } + + /** + * Test creating an entry in the session array + */ + public function testSetSessionParameterCreate(): void + { + $this->sessionManager->setSessionParameter('abc', 'def'); + + static::assertSame('def', $this->session['abc']); + } + + /** + * Test updating an entry in the session array + */ + public function testSetSessionParameterUpdate(): void + { + $this->session['abc'] = 'ghi'; + + $this->sessionManager->setSessionParameter('abc', 'def'); + + static::assertSame('def', $this->session['abc']); + } + + /** + * Test updating an entry in the session array with null value + */ + public function testSetSessionParameterUpdateNull(): void + { + $this->session['abc'] = 'ghi'; + + $this->sessionManager->setSessionParameter('abc', null); + + static::assertArrayHasKey('abc', $this->session); + static::assertNull($this->session['abc']); + } + + /** + * Test deleting an existing entry in the session array + */ + public function testDeleteSessionParameter(): void + { + $this->session['abc'] = 'def'; + + $this->sessionManager->deleteSessionParameter('abc'); + + static::assertArrayNotHasKey('abc', $this->session); + } + + /** + * Test deleting a non existent entry in the session array + */ + public function testDeleteSessionParameterNotExisting(): void + { + $this->sessionManager->deleteSessionParameter('abc'); + + static::assertArrayNotHasKey('abc', $this->session); + } }