2010-04-12 05:32:28 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests to cover the {@link Session} class
|
|
|
|
*
|
2012-04-12 08:02:46 +02:00
|
|
|
* @package framework
|
2010-04-12 05:32:28 +02:00
|
|
|
* @subpackage tests
|
|
|
|
*/
|
|
|
|
|
|
|
|
class SessionTest extends SapphireTest {
|
|
|
|
|
|
|
|
function testGetSetBasics() {
|
|
|
|
Session::set('Test', 'Test');
|
|
|
|
|
|
|
|
$this->assertEquals(Session::get('Test'), 'Test');
|
|
|
|
}
|
|
|
|
|
|
|
|
function testClearElement() {
|
|
|
|
Session::set('Test', 'Test');
|
|
|
|
Session::clear('Test');
|
|
|
|
|
|
|
|
$this->assertEquals(Session::get('Test'), '');
|
|
|
|
}
|
|
|
|
|
|
|
|
function testClearAllElements() {
|
|
|
|
Session::set('Test', 'Test');
|
|
|
|
Session::set('Test-1', 'Test-1');
|
|
|
|
|
2010-10-15 04:50:43 +02:00
|
|
|
Session::clear_all();
|
2010-04-12 05:32:28 +02:00
|
|
|
|
|
|
|
// should session get return null? The array key should probably be
|
|
|
|
// unset from the data array
|
|
|
|
$this->assertEquals(Session::get('Test'), '');
|
|
|
|
$this->assertEquals(Session::get('Test-1'), '');
|
|
|
|
}
|
|
|
|
|
|
|
|
function testGetAllElements() {
|
2010-10-19 05:38:31 +02:00
|
|
|
Session::clear_all(); // Remove all session that might've been set by the test harness
|
|
|
|
|
2010-04-12 05:32:28 +02:00
|
|
|
Session::set('Test', 'Test');
|
|
|
|
Session::set('Test-2', 'Test-2');
|
|
|
|
|
2010-10-15 04:50:43 +02:00
|
|
|
$session = Session::get_all();
|
2010-04-12 05:32:28 +02:00
|
|
|
|
|
|
|
$this->assertEquals($session, array('Test' => 'Test', 'Test-2' => 'Test-2'));
|
|
|
|
}
|
2011-03-22 22:47:22 +01:00
|
|
|
|
2012-04-26 06:43:58 +02:00
|
|
|
/**
|
|
|
|
* Check that changedData isn't populated with junk when clearing non-existent entries.
|
|
|
|
*/
|
|
|
|
function testClearElementThatDoesntExist() {
|
|
|
|
$s = new Session(array('something' => array('does' => 'exist')));
|
|
|
|
|
|
|
|
$s->inst_clear('something.doesnt.exist');
|
|
|
|
$this->assertEquals(array(), $s->inst_changedData());
|
|
|
|
|
|
|
|
$s->inst_set('something-else', 'val');
|
|
|
|
$s->inst_clear('something-new');
|
|
|
|
$this->assertEquals(array('something-else' => 'val'), $s->inst_changedData());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check that changedData is populated with clearing data.
|
|
|
|
*/
|
|
|
|
function testClearElementThatDoesExist() {
|
|
|
|
$s = new Session(array('something' => array('does' => 'exist')));
|
|
|
|
|
|
|
|
$s->inst_clear('something.does');
|
|
|
|
$this->assertEquals(array('something' => array('does' => null)), $s->inst_changedData());
|
|
|
|
}
|
|
|
|
|
2011-03-22 22:47:22 +01:00
|
|
|
function testNonStandardPath(){
|
|
|
|
Session::set_session_store_path(realpath(dirname($_SERVER['DOCUMENT_ROOT']) . '/../session'));
|
|
|
|
Session::start();
|
|
|
|
|
|
|
|
$this->assertEquals(Session::get_session_store_path(), '');
|
|
|
|
}
|
2012-03-24 04:04:52 +01:00
|
|
|
}
|