1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183:
<?php namespace Nethgui\Test\Unit\Nethgui\System;
class SessionDatabaseTest extends \PHPUnit_Framework_TestCase
{
protected $object;
protected function setUp()
{
$this->object = new \Nethgui\System\SessionDatabase;
$this->object->setSession($this->getSession());
}
public function testDelProp()
{
$this->object->delProp('k', array('p1', 'p2'));
$this->assertNull($this->object->getProp('k', 'p1'));
$this->assertNull($this->object->getProp('k', 'p2'));
$this->assertEquals('v3', $this->object->getProp('k', 'p3'));
}
public function testDeleteKey()
{
$this->object->deleteKey('k');
$this->assertNull($this->object->getType('k'));
}
public function testGetAll()
{
$a1 = $this->object->getAll();
$a2 = $this->object->getAll('T');
$this->assertEquals(array('k' => array('p1' => 'v1', 'p2' => 'v2', 'p3' => 'v3', 'type' => 'T')), $a2);
$this->assertEquals($a1, $a2);
}
public function testGetKey1()
{
$this->assertEquals(array('p1' => 'v1', 'p2' => 'v2', 'p3' => 'v3', 'type' => 'T'), $this->object->getKey('k'));
}
public function testGetKey2()
{
$this->assertNull($this->object->getKey('Z'));
}
public function testGetProp1()
{
$this->assertEquals('v1', $this->object->getProp('k', 'p1'));
}
public function testGetProp2()
{
$this->assertNull($this->object->getProp('k', 'Z'));
$this->assertNull($this->object->getProp('z', 'Z'));
}
public function testGetType()
{
$this->assertEquals('T', $this->object->getType('k'));
}
public function testSetKey()
{
$this->object->setKey('w', 'L', array('q1' => 'v1'));
$this->assertEquals('L', $this->object->getType('w'));
$this->assertEquals('v1', $this->object->getProp('w', 'q1'));
}
public function testSetProp1()
{
$this->object->setProp('w', array('a' => 'A'));
$this->assertEquals('A', $this->object->getProp('w', 'a'));
}
public function testSetProp2()
{
$this->object->setProp('k', array('p5' => 'v5', 'p1' => 'xx'));
$this->assertEquals(array('p1' => 'xx', 'p2' => 'v2', 'p3' => 'v3', 'p5' => 'v5', 'type' => 'T'), $this->object->getKey('k'));
}
public function testSetType()
{
$this->object->setType('k', 'X');
$this->assertEquals('X', $this->object->getType('k'));
}
public function testSetSession()
{
$s = $this->getSession();
$this->assertInstanceof('Nethgui\System\SessionDatabase', $this->object->setSession($s));
}
private function getSession($a = array())
{
$a = \array_merge(array('k' => array('p1' => 'v1', 'p2' => 'v2', 'p3' => 'v3', 'type' => 'T')), $a);
$s = new TestSession(array(get_class($this->object) => new \ArrayObject($a)));
return $s;
}
}
class TestSession extends \ArrayObject implements \Nethgui\Utility\SessionInterface
{
public function login()
{
return $this;
}
public function logout()
{
return $this;
}
public function retrieve($key)
{
return $this->offsetGet($key);
}
public function store($key, \Serializable $object = NULL)
{
$this->offsetSet($key, $object);
return $this;
}
}