mirror of
https://github.com/Icinga/icingaweb2.git
synced 2026-07-08 17:21:02 -04:00
Replace the outdated `array()` spelling with the more modern `[]`. This is applied throughout the whole project, also including phpdocs, tests, view scripts and core modules.
119 lines
3.1 KiB
PHP
119 lines
3.1 KiB
PHP
<?php
|
|
|
|
// SPDX-FileCopyrightText: 2018 Icinga GmbH <https://icinga.com>
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
namespace Tests\Icinga\Web\Session;
|
|
|
|
use Icinga\Test\BaseTestCase;
|
|
use Icinga\Web\Session\PhpSession;
|
|
|
|
class PhpSessionTest extends BaseTestCase
|
|
{
|
|
private function getSession()
|
|
{
|
|
if (!is_writable('/tmp')) {
|
|
$this->markTestSkipped('Could not write to session directory');
|
|
}
|
|
return PhpSession::create(
|
|
[
|
|
'save_path' => '/tmp',
|
|
'test_session_name' => 'IcingawebUnittest'
|
|
]
|
|
);
|
|
}
|
|
/**
|
|
* Test the creation of a PhpSession object
|
|
*
|
|
* @runInSeparateProcess
|
|
*/
|
|
public function testSessionCreation()
|
|
{
|
|
$this->getSession();
|
|
}
|
|
|
|
/**
|
|
* Test PhpSession::open()
|
|
*
|
|
* @runInSeparateProcess
|
|
*/
|
|
public function testSessionReadWrite()
|
|
{
|
|
$session = $this->getSession();
|
|
$session->purge();
|
|
$this->assertEquals(null, $session->get('key'));
|
|
$session->set('key', 'value');
|
|
$session->write();
|
|
$session->read();
|
|
$this->assertEquals('value', $session->get('key'));
|
|
}
|
|
|
|
/**
|
|
* Test a session being closed by PhpSession::close()
|
|
*
|
|
* @runInSeparateProcess
|
|
*/
|
|
public function testPurgeSession()
|
|
{
|
|
$session = $this->getSession();
|
|
$session->set('key2', 'value2');
|
|
$session->purge();
|
|
$session->read();
|
|
$this->assertEquals(null, $session->get('key2'));
|
|
}
|
|
|
|
/**
|
|
* Test whether session namespaces are properly written, cleared and loaded
|
|
*
|
|
* @runInSeparateProcess
|
|
*/
|
|
public function testNamespaceReadWrite()
|
|
{
|
|
$session = $this->getSession();
|
|
$namespace = $session->getNamespace('test');
|
|
$namespace->set('some_key', 'some_val');
|
|
$namespace->set('an_array', [1, 2, 3]);
|
|
$session->write();
|
|
$session->clear();
|
|
$this->assertFalse($session->hasNamespace('test'));
|
|
$session->read();
|
|
$namespace = $session->getNamespace('test');
|
|
$this->assertEquals($namespace->get('some_key'), 'some_val');
|
|
$this->assertEquals($namespace->get('an_array'), [1, 2, 3]);
|
|
}
|
|
|
|
/**
|
|
* Test whether session values are properly removed
|
|
*
|
|
* @runInSeparateProcess
|
|
*/
|
|
public function testValueRemoval()
|
|
{
|
|
$session = $this->getSession();
|
|
$session->set('key', 'value');
|
|
$session->write();
|
|
$session->delete('key');
|
|
$session->write();
|
|
$session->clear();
|
|
$session->read();
|
|
$this->assertNull($session->get('key'));
|
|
}
|
|
|
|
/**
|
|
* Test whether session namespaces are properly removed
|
|
*
|
|
* @runInSeparateProcess
|
|
*/
|
|
public function testNamespaceRemoval()
|
|
{
|
|
$session = $this->getSession();
|
|
$namespace = $session->getNamespace('test');
|
|
$namespace->key = 'value';
|
|
$session->write();
|
|
$session->removeNamespace('test');
|
|
$session->write();
|
|
$session->clear();
|
|
$session->read();
|
|
$this->assertFalse($session->hasNamespace('test'));
|
|
}
|
|
}
|