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:
<?php
namespace Nethgui\Test\Unit\Nethgui\Adapter;
class TabularValueAdapterTest extends \PHPUnit_Framework_TestCase
{
protected $object;
private $serializer;
protected function setUp()
{
$this->serializer = $this->getMockBuilder('\Nethgui\Serializer\KeySerializer')
->disableOriginalConstructor()
->getMock();
$this->serializer->expects($this->any())->method('read')
->will($this->returnValue('1A/1B/1C,2A/2B/2C,3A/3B/3C'));
$innerAdapter = new \Nethgui\Adapter\ArrayAdapter(',', $this->serializer);
$this->object = new \Nethgui\Adapter\TabularValueAdapter($innerAdapter, '/');
}
public function testCount()
{
$this->assertEquals(3, $this->object->count());
}
public function testDelete()
{
$this->object->delete();
$this->assertEquals(0, $this->object->count());
}
public function testGet()
{
$compareMatrix = array(
'1A' => array('1B', '1C'),
'2A' => array('2B', '2C'),
'3A' => array('3B', '3C'),
);
foreach ($this->object->get() as $key => $row) {
$this->assertEquals($row, $compareMatrix[$key]);
}
}
public function testSet()
{
$compareMatrix = array(
array('1A', '1B', '1C'),
array('2A', '2B', '2C'),
);
$this->object->set($compareMatrix);
$i = 0;
foreach ($this->object as $row) {
$this->assertEquals($row, $compareMatrix[$i ++]);
}
}
public function testSaveModified()
{
$this->object['3A'] = array('0', '0');
$this->serializer->expects($this->once())
->method('write')
->with($this->equalTo('1A/1B/1C,2A/2B/2C,3A/0/0'));
$this->object->save();
}
public function testSaveNotModified()
{
$this->serializer->expects($this->never())
->method('write');
$this->object->save();
}
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 testIsModified2()
{
$this->testSaveModified();
$this->assertFalse($this->object->isModified());
}
public function testOffsetExists()
{
$this->assertTrue($this->object->offsetExists('1A'));
$this->assertTrue($this->object->offsetExists('2A'));
$this->assertTrue($this->object->offsetExists('3A'));
$this->assertFalse($this->object->offsetExists('XX'));
$this->assertFalse($this->object->offsetExists(-1));
$this->assertFalse($this->object->offsetExists(''));
}
public function testOffsetGet()
{
$this->assertTrue(is_array($this->object->offsetGet('1A')));
$this->assertTrue(is_array($this->object->offsetGet('2A')));
$this->assertTrue(is_array($this->object->offsetGet('3A')));
}
public function testOffsetSet()
{
$this->object->offsetSet('1A', array('0', '0', '0'));
$this->assertEquals(array('0', '0', '0'), $this->object['1A']);
}
public function testOffsetUnset()
{
$this->object->offsetUnset('1A');
$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');
}
}