2013-06-10 14:21:17 +02:00
|
|
|
<?php
|
2015-02-04 10:46:36 +01:00
|
|
|
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
2013-06-10 14:21:17 +02:00
|
|
|
|
2014-04-17 13:08:46 +02:00
|
|
|
namespace Tests\Icinga\Web\Session;
|
2013-06-10 14:21:17 +02:00
|
|
|
|
2013-08-28 15:56:33 +02:00
|
|
|
use Icinga\Test\BaseTestCase;
|
2014-03-25 11:12:55 +01:00
|
|
|
use Icinga\Web\Session\PhpSession;
|
2013-08-02 15:35:05 +02:00
|
|
|
|
2013-08-28 15:56:33 +02:00
|
|
|
class PhpSessionTest extends BaseTestCase
|
|
|
|
{
|
2013-08-02 15:35:05 +02:00
|
|
|
private function getSession()
|
|
|
|
{
|
|
|
|
if (!is_writable('/tmp')) {
|
|
|
|
$this->markTestSkipped('Could not write to session directory');
|
|
|
|
}
|
2013-08-28 15:56:33 +02:00
|
|
|
return new PhpSession(
|
|
|
|
array(
|
|
|
|
'use_cookies' => false,
|
2013-11-20 12:01:40 +01:00
|
|
|
'save_path' => '/tmp',
|
|
|
|
'test_session_name' => 'IcingawebUnittest'
|
2013-08-28 15:56:33 +02:00
|
|
|
)
|
|
|
|
);
|
2013-08-02 15:35:05 +02:00
|
|
|
}
|
2013-06-10 14:21:17 +02:00
|
|
|
/**
|
2013-11-20 12:01:40 +01:00
|
|
|
* Test the creation of a PhpSession object
|
|
|
|
*
|
|
|
|
* @runInSeparateProcess
|
|
|
|
*/
|
2013-06-10 14:21:17 +02:00
|
|
|
public function testSessionCreation()
|
|
|
|
{
|
2013-08-02 15:35:05 +02:00
|
|
|
$this->getSession();
|
2013-06-10 14:21:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-11-20 12:01:40 +01:00
|
|
|
* Test PhpSession::open()
|
2013-08-02 15:35:05 +02:00
|
|
|
*
|
2013-11-20 12:01:40 +01:00
|
|
|
* @runInSeparateProcess
|
2013-08-02 15:35:05 +02:00
|
|
|
*/
|
2013-11-20 12:01:40 +01:00
|
|
|
public function testSessionReadWrite()
|
2013-06-10 14:21:17 +02:00
|
|
|
{
|
2013-08-02 15:35:05 +02:00
|
|
|
$session = $this->getSession();
|
2013-11-20 12:01:40 +01:00
|
|
|
$session->purge();
|
|
|
|
$this->assertEquals(null, $session->get('key'));
|
|
|
|
$session->set('key', 'value');
|
|
|
|
$session->write();
|
|
|
|
$session->read();
|
|
|
|
$this->assertEquals('value', $session->get('key'));
|
2013-06-10 14:21:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-11-20 12:01:40 +01:00
|
|
|
* Test a session being closed by PhpSession::close()
|
2013-08-02 15:35:05 +02:00
|
|
|
*
|
2013-11-20 12:01:40 +01:00
|
|
|
* @runInSeparateProcess
|
2013-08-02 15:35:05 +02:00
|
|
|
*/
|
2013-06-10 14:21:17 +02:00
|
|
|
public function testPurgeSession()
|
|
|
|
{
|
2013-08-02 15:35:05 +02:00
|
|
|
$session = $this->getSession();
|
2013-11-20 12:01:40 +01:00
|
|
|
$session->set('key2', 'value2');
|
2013-06-10 14:21:17 +02:00
|
|
|
$session->purge();
|
2013-11-20 12:01:40 +01:00
|
|
|
$session->read();
|
|
|
|
$this->assertEquals(null, $session->get('key2'));
|
2013-06-10 14:21:17 +02:00
|
|
|
}
|
2014-01-23 14:40:59 +01:00
|
|
|
|
|
|
|
/**
|
2014-04-09 16:18:51 +02:00
|
|
|
* Test whether session namespaces are properly written, cleared and loaded
|
2014-01-23 14:40:59 +01:00
|
|
|
*
|
|
|
|
* @runInSeparateProcess
|
|
|
|
*/
|
|
|
|
public function testNamespaceReadWrite()
|
|
|
|
{
|
|
|
|
$session = $this->getSession();
|
|
|
|
$namespace = $session->getNamespace('test');
|
|
|
|
$namespace->set('some_key', 'some_val');
|
|
|
|
$namespace->set('an_array', array(1, 2, 3));
|
|
|
|
$session->write();
|
|
|
|
$session->clear();
|
2014-04-09 16:18:51 +02:00
|
|
|
$this->assertFalse($session->hasNamespace('test'));
|
2014-01-23 14:40:59 +01:00
|
|
|
$session->read();
|
|
|
|
$namespace = $session->getNamespace('test');
|
|
|
|
$this->assertEquals($namespace->get('some_key'), 'some_val');
|
|
|
|
$this->assertEquals($namespace->get('an_array'), array(1, 2, 3));
|
|
|
|
}
|
2014-04-09 16:18:51 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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'));
|
|
|
|
}
|
2013-06-10 14:21:17 +02:00
|
|
|
}
|