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:
<?php
namespace Nethgui\Test\Unit\Nethgui\Adapter;
class TabularValueAdapterDegradedTest 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,2A,3A'));
$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(),
'2A' => array(),
'3A' => array(),
);
foreach ($this->object->get() as $key => $row) {
$this->assertEquals($row, $compareMatrix[$key]);
}
}
public function testSet()
{
$compareMatrix = array(
array('1A'),
array('2A'),
);
$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,2A,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('4A', array());
$this->assertEquals(array(), $this->object['4A']);
}
}