mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-09-25 18:59:04 +02:00
Add tests for hasChanged, set/getByRef and fix setByRef
This commit is contained in:
parent
6f988cb94c
commit
635b802a2b
@ -111,7 +111,7 @@ class SessionNamespace implements IteratorAggregate
|
|||||||
|
|
||||||
public function setByRef($key, &$value)
|
public function setByRef($key, &$value)
|
||||||
{
|
{
|
||||||
$this->values[$key] = $value;
|
$this->values[$key] = & $value;
|
||||||
|
|
||||||
if (in_array($key, $this->removed)) {
|
if (in_array($key, $this->removed)) {
|
||||||
unset($this->removed[array_search($key, $this->removed)]);
|
unset($this->removed[array_search($key, $this->removed)]);
|
||||||
|
@ -84,4 +84,40 @@ class SessionNamespaceTest extends BaseTestCase
|
|||||||
$this->assertEquals($value, $values[$key]);
|
$this->assertEquals($value, $values[$key]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testRetrievingValuesByReferenceWorks()
|
||||||
|
{
|
||||||
|
$ns = new SessionNamespace();
|
||||||
|
$ns->array = array(1, 2);
|
||||||
|
$array = & $ns->getByRef('array');
|
||||||
|
$array[0] = 11;
|
||||||
|
|
||||||
|
$this->assertEquals(
|
||||||
|
array(11, 2),
|
||||||
|
$ns->array,
|
||||||
|
'Values retrieved with getByRef() seem not be affected by external changes'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSettingValuesByReferenceWorks()
|
||||||
|
{
|
||||||
|
$ns = new SessionNamespace();
|
||||||
|
$array = array(1, 2);
|
||||||
|
$ns->setByRef('array', $array);
|
||||||
|
$array[0] = 11;
|
||||||
|
|
||||||
|
$this->assertEquals(
|
||||||
|
array(11, 2),
|
||||||
|
$ns->array,
|
||||||
|
'Values set with setByRef() seem not to receive external changes'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testTrackingChangesWorks()
|
||||||
|
{
|
||||||
|
$ns = new SessionNamespace();
|
||||||
|
$this->assertFalse($ns->hasChanged(), 'A new empty session namespace seems to have changes');
|
||||||
|
$ns->test = 1;
|
||||||
|
$this->assertTrue($ns->hasChanged(), 'A new session namespace with values seems not to have changes');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user