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: 184:
<?php
namespace Nethgui\Test\Unit\Nethgui\Adapter;
use \Nethgui\Test\Tool\DB;
use \Nethgui\Test\Tool\MockFactory;
class TableAdapter1Test extends \PHPUnit_Framework_TestCase
{
protected $object;
protected function setUp()
{
$this->object = new \Nethgui\Adapter\TableAdapter(MockFactory::getMockDatabase($this, $this->getDB()), 'T');
}
protected function getDB()
{
$db = new \Nethgui\Test\Tool\DB;
$type = 'T';
$initialTable = array();
foreach (array(1, 2, 3) as $i) {
$initialTable[$i . 'K'] = array(
'type' => $type,
$i . 'P' => $i . 'V',
$i . 'Q' => $i . 'W',
);
}
return $db->set(DB::getAll('T'), $initialTable);
}
public function testCount()
{
$this->assertEquals(3, $this->object->count());
}
public function testDelete()
{
$this->object->delete();
$this->assertEquals(0, $this->object->count());
}
public function testGet()
{
$e = new \ArrayObject(array(
'1K' => new \ArrayObject(array('1P' => '1V', '1Q' => '1W')),
'2K' => new \ArrayObject(array('2P' => '2V', '2Q' => '2W')),
'3K' => new \ArrayObject(array('3P' => '3V', '3Q' => '3W')),
));
$v = $this->object->get();
$this->assertInstanceOf("ArrayObject", $v);
$this->assertEquals($e, $v);
}
public function testSet()
{
$e = array(
'1K' => array('1P' => '1V', '1Q' => '1W'),
'2K' => array('2P' => '2V', '2Q' => '2W'),
'3K' => array('3P' => '3V', '3Q' => '3W'),
);
$o = new \ArrayObject();
foreach ($e as $k => $r) {
$o[$k] = new \ArrayObject($r);
}
$this->object->set($e);
$this->assertEquals($o, $this->object->get());
}
public function testGetIterator()
{
$it = $this->object->getIterator();
$this->assertEquals(3, $it->count());
}
public function testIsModified1()
{
$this->assertFalse($this->object->isModified());
$this->object[2] = array('0', '0', '0');
$this->assertTrue($this->object->isModified());
}
public function testOffsetExists()
{
$this->assertTrue($this->object->offsetExists('1K'));
$this->assertFalse($this->object->offsetExists(-1));
}
public function testOffsetGet()
{
$this->assertInstanceOf("ArrayObject", $this->object->offsetGet('1K'));
}
public function testOffsetSet()
{
$this->object->offsetSet('1A', array('0', '0', '0'));
$this->assertEquals(new \ArrayObject(array('0', '0', '0')), $this->object['1A']);
}
public function testOffsetUnset()
{
$this->object->offsetUnset('1K');
$this->assertEquals(2, $this->object->count());
$this->assertFalse($this->object->offsetExists('1A'));
}
public function testGet2()
{
$value = $this->object->get();
$this->assertInstanceOf('ArrayAccess', $value);
}
public function testSetError1()
{
$this->object->set('hi');
}
public function testSetError2()
{
$this->object->set(array(array(1, 2, 3), 'hi'));
}
public function testOffsetSetError1()
{
$this->object->offsetSet('4', 'hi');
}
public function testSave0()
{
$this->assertFalse($this->object->isModified());
$c = $this->object->save();
$this->assertEquals(0, $c);
$this->assertFalse($this->object->isModified());
}
public function testSave1()
{
$e = new \ArrayObject(array(
'2K' => new \ArrayObject(array('2P' => '2V', '2Q' => '2W')),
'3K' => new \ArrayObject(array('3P' => '3V', '3Q' => '3W')),
));
$this->object = new \Nethgui\Adapter\TableAdapter(MockFactory::getMockDatabase($this, $this->getDB()->set(DB::deleteKey("1K"), $e)), 'T', FALSE);
$this->assertFalse($this->object->isModified());
unset($this->object['1K']);
$this->assertTrue($this->object->isModified());
$c = $this->object->save();
$this->assertEquals(1, $c);
$this->assertFalse($this->object->isModified());
$this->assertFalse(isset($this->object['1K']));
}
}