function testProcessUseNodeId() { $record = new DataSpace(); $record->import(array('_node_id' => $node_id = 100)); $this->translator->expectOnce('getPathToNode', array($node_id)); $this->translator->setReturnValue('getPathToNode', $path = '/whatever/'); $processor = new PathRecordProcessor(); $processor->process($record); $this->assertEqual($record->get('_node_path'), $path); }
function testLoginFailedPasswordNotMatched() { $users_dao = new MockAbstractUsersDAO($this); $this->authenticator->setUsersDAO($users_dao); $users_dao->expectOnce('findByLogin', array($login = '******')); $user_data = new DataSpace(); $user_data->import(array('password' => md5('wrong_password'))); $users_dao->setReturnReference('findByLogin', $user_data); $this->authenticator->login($login, $password = '******'); $toolkit =& Limb::toolkit(); $user =& $toolkit->getUser(); $this->assertFalse($user->isLoggedIn()); $users_dao->tally(); }
function testFetchById() { $id = "10"; $criteria1 = new MockCriteria($this); $criteria2 = new MockCriteria($this); $this->dao->addCriteria($criteria1); $this->dao->addCriteria($criteria2); $criteria1->expectOnce('process', array(new IsAExpectation('MockComplexSelectSQL'))); $criteria2->expectOnce('process', array(new IsAExpectation('MockComplexSelectSQL'))); $this->sql->expectOnce('addCondition', array('oid=10')); $this->sql->expectOnce('toString'); $this->sql->setReturnValue('toString', $str = 'SELECT *...'); $this->conn->expectOnce('newStatement', array($str)); $this->conn->setReturnReference('newStatement', $this->stmt, array($str)); $record = new DataSpace(); $record->import($row = array('whatever')); $this->stmt->expectOnce('getRecordSet'); $this->stmt->setReturnValue('getRecordSet', $rs = new ArrayDataSet(array($row))); $this->assertEqual($this->dao->fetchById($id), $record); $criteria1->tally(); $criteria2->tally(); }
function testAdd() { $dao = new MockDAO($this); $mapper = new ProxyTestMapper($this); $proxy = new ProxyObjectCollection($dao, $mapper, new LimbHandle('Object')); $raw_array = array(array('id' => 1)); $dao->expectOnce('fetch'); $dao->setReturnValue('fetch', $dataset = new ArrayDataSet($raw_array)); $ds1 = new DataSpace(); $ds1->import($raw_array[0]); $mapper->expectOnce('load', array($ds1, new Object())); $added_object = new Object(); $added_object->set('id', 2); $proxy->add($added_object); $proxy->rewind(); $fetched_object = new Object(); $fetched_object->set('id', 1); $this->assertEqual($proxy->current(), $fetched_object); $proxy->next(); $this->assertEqual($proxy->current(), $added_object); $proxy->next(); $this->assertFalse($proxy->valid()); $dao->tally(); $mapper->tally(); }
function testLoad() { $record = new DataSpace(); $record->import($row = array('whatever')); $object = new UOWTestObject(); $object->set('id', $id = 100);//we do the mapper's job $this->toolkit->setReturnReference('createObject', $object, array('UOWTestObject')); $this->dao->expectOnce('fetchById', array($id)); $this->dao->setReturnValue('fetchById', $record, array($id)); $this->mapper->expectOnce('load', array($record, $object)); $loaded_object =& $this->uow->load('UOWTestObject', $id); $this->assertTrue($this->uow->isExisting($loaded_object)); $this->assertFalse($this->uow->isNew($loaded_object)); $this->assertEqual($object, $loaded_object); //cache hit test $object =& $this->uow->load('UOWTestObject', $id); $this->assertEqual($object, $loaded_object); }
function _coachMockUsingArray($array) { $mock =& new MockPagedArrayDataSet($this); $mock->expectCallCount('rewind', 1); $mock->expectCallCount('next', sizeof($array)); $mock->expectCallCount('valid', sizeof($array) + 1); for($i=0; $i<sizeof($array); $i++) { $mock->setReturnValueAt($i, 'valid', true); $dataspace = new DataSpace(); $dataspace->import($array[$i]); $mock->setReturnValueAt($i, 'current', $dataspace); } $mock->setReturnValueAt($i, 'valid', false); return $mock; }
function &_createUserDataSpaceFromArray($user_data) { $result = new DataSpace(); $result->import(array('login' => $user_data[0], 'password' => $user_data[1], 'name' => $user_data[2], 'email' => $user_data[3], 'groups' => explode(',', $user_data[4]))); return $result; }